Skip to content

Commit 6c147f8

Browse files
committed
Make parent mount private before bind mounting rootfs
This reverts part of the commit eb0a144 That commit introduced two issues. - We need to make parent mount of rootfs private before bind mounting rootfs. Otherwise bind mounting root can propagate in other mount namespaces. (If parent mount is shared). - It broke test TestRootfsPropagationSharedMount() on Fedora. On fedora /tmp is a mount point with "shared" propagation. I think you should be able to reproduce it on other distributions as well as long as you mount tmpfs on /tmp and make it "shared" propagation. Reason for failure is that pivot_root() fails. And it fails because kernel does following check. IS_MNT_SHARED(new_mnt->mnt_parent) Say /tmp/foo is new rootfs, we have bind mounted rootfs, so new_mnt is /tmp/foo, and new_mnt->mnt_parent is /tmp which is "shared" on fedora and above check fails. So this change broke few things, it is a good idea to revert part of it. Signed-off-by: Vivek Goyal <[email protected]>
1 parent d6b68e8 commit 6c147f8

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

libcontainer/rootfs_linux.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -563,10 +563,12 @@ func prepareRoot(config *configs.Config) error {
563563
if err := syscall.Mount("", "/", "", uintptr(flag), ""); err != nil {
564564
return err
565565
}
566-
if config.NoPivotRoot {
567-
if err := rootfsParentMountPrivate(config.Rootfs); err != nil {
568-
return err
569-
}
566+
567+
// Make parent mount private to make sure following bind mount does
568+
// not propagate in other namespaces. Also it will help with kernel
569+
// check pass in pivot_root. (IS_SHARED(new_mnt->mnt_parent))
570+
if err := rootfsParentMountPrivate(config.Rootfs); err != nil {
571+
return err
570572
}
571573

572574
return syscall.Mount(config.Rootfs, config.Rootfs, "bind", syscall.MS_BIND|syscall.MS_REC, "")
@@ -617,15 +619,7 @@ func pivotRoot(rootfs string) error {
617619
}
618620

619621
if err := syscall.PivotRoot(".", "."); err != nil {
620-
// Make the parent mount private
621-
if err := rootfsParentMountPrivate("."); err != nil {
622-
return err
623-
}
624-
625-
// Try again
626-
if err := syscall.PivotRoot(".", "."); err != nil {
627-
return fmt.Errorf("pivot_root %s", err)
628-
}
622+
return fmt.Errorf("pivot_root %s", err)
629623
}
630624

631625
// Currently our "." is oldroot (according to the current kernel code).

0 commit comments

Comments
 (0)