summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNicolas Lacasse <nlacasse@google.com>2019-02-27 09:44:45 -0800
committerShentubot <shentubot@google.com>2019-02-27 09:45:45 -0800
commitd516ee3312411c60630305cfaac6c5a0e21537e8 (patch)
tree9b61b3f5895b99428a329ab6f2b790bdf029be40
parentcff2c57192ccd5ccf4cec6280afcd724dc1135d1 (diff)
Allow overlay to merge Directories and SepcialDirectories.
Needed to mount inside /proc or /sys. PiperOrigin-RevId: 235936529 Change-Id: Iee6f2671721b1b9b58a3989705ea901322ec9206
-rw-r--r--pkg/sentry/fs/inode_overlay.go15
1 files changed, 12 insertions, 3 deletions
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()