From 253426676c2d00358522fabc942232d4a05172f6 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Thu, 20 Oct 2016 15:29:23 -0700 Subject: [PATCH 1/2] chroot: remount everything as private in new mntns If parent of the destination path is shared, this path will be unmounted from the parent ns even if the path itself is private. Signed-off-by: Tonis Tiigi Upstream-commit: b511d1f0cabd32ca30c87fa1bbc7ecac283dab39 Component: engine --- components/engine/pkg/chrootarchive/chroot_linux.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/components/engine/pkg/chrootarchive/chroot_linux.go b/components/engine/pkg/chrootarchive/chroot_linux.go index 7153b48798..9f1dd527ff 100644 --- a/components/engine/pkg/chrootarchive/chroot_linux.go +++ b/components/engine/pkg/chrootarchive/chroot_linux.go @@ -26,7 +26,12 @@ func chroot(path string) (err error) { return fmt.Errorf("Error creating mount namespace before pivot: %v", err) } - if err := mount.MakeRPrivate(path); err != nil { + // make everything in new ns private + if err := mount.MakeRPrivate("/"); err != nil { + return err + } + // ensure path is a mountpoint + if err := mount.MakePrivate(path); err != nil { return err } From f8d146b07d855806890d78176a4e8a84263db68b Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Thu, 20 Oct 2016 15:34:23 -0700 Subject: [PATCH 2/2] chroot: let root be cleaned up by kernel Signed-off-by: Tonis Tiigi Upstream-commit: 70dfea63ba2a8a6d8b367420039aeb6a1759c240 Component: engine --- components/engine/pkg/chrootarchive/chroot_linux.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/components/engine/pkg/chrootarchive/chroot_linux.go b/components/engine/pkg/chrootarchive/chroot_linux.go index 9f1dd527ff..3325329978 100644 --- a/components/engine/pkg/chrootarchive/chroot_linux.go +++ b/components/engine/pkg/chrootarchive/chroot_linux.go @@ -62,13 +62,6 @@ func chroot(path string) (err error) { err = errCleanup } } - - if errCleanup := syscall.Unmount("/", syscall.MNT_DETACH); errCleanup != nil { - if err == nil { - err = fmt.Errorf("error unmounting root: %v", errCleanup) - } - return - } }() if err := syscall.PivotRoot(path, pivotDir); err != nil {