From 66b0f3e15a60df21f67d37dc6e420d1825acacfe Mon Sep 17 00:00:00 2001 From: Nicolas Lacasse Date: Tue, 14 Aug 2018 10:33:53 -0700 Subject: Fix bind() on overlays. InodeOperations.Bind now returns a Dirent which will be cached in the Dirent tree. When an overlay is in-use, Bind cannot return the Dirent created by the upper filesystem because the Dirent does not know about the overlay. Instead, overlayBind must create a new overlay-aware Inode and Dirent and return that. This is analagous to how Lookup and overlayLookup work. PiperOrigin-RevId: 208670710 Change-Id: I6390affbcf94c38656b4b458e248739b4853da29 --- pkg/sentry/fs/inode_overlay.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'pkg') diff --git a/pkg/sentry/fs/inode_overlay.go b/pkg/sentry/fs/inode_overlay.go index 34e62a4a2..e18e095a0 100644 --- a/pkg/sentry/fs/inode_overlay.go +++ b/pkg/sentry/fs/inode_overlay.go @@ -364,7 +364,23 @@ func overlayBind(ctx context.Context, o *overlayEntry, name string, data unix.Bo if o.upper == nil { return nil, syserror.EOPNOTSUPP } - return o.upper.InodeOperations.Bind(ctx, o.upper, name, data, perm) + d, err := o.upper.InodeOperations.Bind(ctx, o.upper, name, data, perm) + if err != nil { + return nil, err + } + + // Grab the inode and drop the dirent, we don't need it. + inode := d.Inode + inode.IncRef() + d.DecRef() + + // Create a new overlay entry and dirent for the socket. + entry, err := newOverlayEntry(ctx, inode, nil, false) + if err != nil { + inode.DecRef() + return nil, err + } + return NewDirent(newOverlayInode(ctx, entry, inode.MountSource), name), nil } func overlayBoundEndpoint(o *overlayEntry, path string) unix.BoundEndpoint { -- cgit v1.2.3