From d516ee3312411c60630305cfaac6c5a0e21537e8 Mon Sep 17 00:00:00 2001 From: Nicolas Lacasse Date: Wed, 27 Feb 2019 09:44:45 -0800 Subject: Allow overlay to merge Directories and SepcialDirectories. Needed to mount inside /proc or /sys. PiperOrigin-RevId: 235936529 Change-Id: Iee6f2671721b1b9b58a3989705ea901322ec9206 --- pkg/sentry/fs/inode_overlay.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'pkg/sentry') diff --git a/pkg/sentry/fs/inode_overlay.go b/pkg/sentry/fs/inode_overlay.go index 77a2623ef..b11e2bd13 100644 --- a/pkg/sentry/fs/inode_overlay.go +++ b/pkg/sentry/fs/inode_overlay.go @@ -131,11 +131,20 @@ func overlayLookup(ctx context.Context, parent *overlayEntry, inode *Inode, name } if child != nil { if !child.IsNegative() { - // Did we find something in the upper filesystem? We can - // only use it if the types match. - if upperInode == nil || upperInode.StableAttr.Type == child.Inode.StableAttr.Type { + if upperInode == nil { + // If nothing was in the upper, use what we found in the lower. lowerInode = child.Inode lowerInode.IncRef() + } else { + // If we have something from the upper, we can only use it if the types + // match. + // NOTE: Allow SpecialDirectories and Directories to merge. + // This is needed to allow submounts in /proc and /sys. + if upperInode.StableAttr.Type == child.Inode.StableAttr.Type || + (IsDir(upperInode.StableAttr) && IsDir(child.Inode.StableAttr)) { + lowerInode = child.Inode + lowerInode.IncRef() + } } } child.DecRef() -- cgit v1.2.3