Skip to content

Commit

Permalink
cmd/snap-update-ns: allow detaches to propagate
Browse files Browse the repository at this point in the history
When snap-update-ns chooses not to reuse a mount entry it attempts to unmount
it by detaching the mount entry. Before that is done the mount entry used to be
switch to private propagation, so that the unmount operation was isolated.

Disable this logic so that unmounts (and detaches) propagate normally. The
mount namespace of the snap is mostly switched to slaved propagation, with the
sole exception of /media or /run/media, which uses bidirectional propagation by
design.

This patch is experimental and is not ready for being merged yet.

Jira: https://warthogs.atlassian.net/browse/SNAPDENG-31645

Signed-off-by: Zygmunt Krynicki <[email protected]>
  • Loading branch information
zyga committed Sep 27, 2024
1 parent 633df5b commit 096a8f9
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 16 deletions.
9 changes: 0 additions & 9 deletions cmd/snap-update-ns/change.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,15 +405,6 @@ func (c *Change) lowLevelPerform(as *Assumptions) error {
flags := umountNoFollow
if c.Entry.XSnapdDetach() {
flags |= syscall.MNT_DETACH
// If we are detaching something then before performing the actual detach
// switch the entire hierarchy to private event propagation (that is,
// none). This works around a bit of peculiar kernel behavior when the
// kernel reports EBUSY during a detach operation, because the changes
// propagate in a way that conflicts with itself. This is also documented
// in umount(2).
err = sysMount("none", c.Entry.Dir, "", syscall.MS_REC|syscall.MS_PRIVATE, "")
logger.Debugf("mount --make-rprivate %q (error: %v)", c.Entry.Dir, err)
err = clearMissingMountError(err)
}

// Perform the raw unmount operation.
Expand Down
7 changes: 0 additions & 7 deletions cmd/snap-update-ns/change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,6 @@ func (s *changeSuite) TestPerformFilesystemMountWithoutMountPointAndReadOnlyBase

{C: `lstat "/rofs"`, R: testutil.FileInfoDir},
{C: `mount "tmpfs" "/rofs" "tmpfs" 0 "mode=0755,uid=0,gid=0"`},
{C: `mount "none" "/tmp/.snap/rofs" "" MS_REC|MS_PRIVATE ""`},
{C: `unmount "/tmp/.snap/rofs" UMOUNT_NOFOLLOW|MNT_DETACH`},

// Perform clean up after the unmount operation.
Expand Down Expand Up @@ -976,7 +975,6 @@ func (s *changeSuite) TestPerformFilesystemDetch(c *C) {
synth, err := chg.Perform(s.as)
c.Assert(err, IsNil)
c.Assert(s.sys.RCalls(), testutil.SyscallsEqual, []testutil.CallResultError{
{C: `mount "none" "/target" "" MS_REC|MS_PRIVATE ""`},
{C: `unmount "/target" UMOUNT_NOFOLLOW|MNT_DETACH`},

// Perform clean up after the unmount operation.
Expand Down Expand Up @@ -1323,7 +1321,6 @@ func (s *changeSuite) TestPerformDirectoryBindMountWithoutMountPointAndReadOnlyB

{C: `lstat "/rofs"`, R: testutil.FileInfoDir},
{C: `mount "tmpfs" "/rofs" "tmpfs" 0 "mode=0755,uid=0,gid=0"`},
{C: `mount "none" "/tmp/.snap/rofs" "" MS_REC|MS_PRIVATE ""`},
{C: `unmount "/tmp/.snap/rofs" UMOUNT_NOFOLLOW|MNT_DETACH`},

// Perform clean up after the unmount operation.
Expand Down Expand Up @@ -1471,7 +1468,6 @@ func (s *changeSuite) TestPerformDirectoryBindMountWithoutMountSourceAndReadOnly
{C: `close 4`},
{C: `lstat "/rofs"`, R: testutil.FileInfoDir},
{C: `mount "tmpfs" "/rofs" "tmpfs" 0 "mode=0755,uid=0,gid=0"`},
{C: `mount "none" "/tmp/.snap/rofs" "" MS_REC|MS_PRIVATE ""`},
{C: `unmount "/tmp/.snap/rofs" UMOUNT_NOFOLLOW|MNT_DETACH`},

// Perform clean up after the unmount operation.
Expand Down Expand Up @@ -1864,7 +1860,6 @@ func (s *changeSuite) TestPerformFileBindMountWithoutMountPointAndReadOnlyBase(c

{C: `lstat "/rofs"`, R: testutil.FileInfoDir},
{C: `mount "tmpfs" "/rofs" "tmpfs" 0 "mode=0755,uid=0,gid=0"`},
{C: `mount "none" "/tmp/.snap/rofs" "" MS_REC|MS_PRIVATE ""`},
{C: `unmount "/tmp/.snap/rofs" UMOUNT_NOFOLLOW|MNT_DETACH`},

// Perform clean up after the unmount operation.
Expand Down Expand Up @@ -2259,7 +2254,6 @@ func (s *changeSuite) TestPerformCreateSymlinkWithoutBaseDirAndReadOnlyBase(c *C

{C: `lstat "/rofs"`, R: testutil.FileInfoDir},
{C: `mount "tmpfs" "/rofs" "tmpfs" 0 "mode=0755,uid=0,gid=0"`},
{C: `mount "none" "/tmp/.snap/rofs" "" MS_REC|MS_PRIVATE ""`},
{C: `unmount "/tmp/.snap/rofs" UMOUNT_NOFOLLOW|MNT_DETACH`},

// Perform clean up after the unmount operation.
Expand Down Expand Up @@ -2520,7 +2514,6 @@ func (s *changeSuite) TestPerformCreateSymlinkWithAvoidedTrespassing(c *C) {
{C: `close 7`},

// We're done restoring now.
{C: `mount "none" "/tmp/.snap/etc" "" MS_REC|MS_PRIVATE ""`},
{C: `unmount "/tmp/.snap/etc" UMOUNT_NOFOLLOW|MNT_DETACH`},

// Perform clean up after the unmount operation.
Expand Down

0 comments on commit 096a8f9

Please sign in to comment.