Skip to content

Commit

Permalink
Merge pull request #1148 from rhvgoyal/parent-mount-private
Browse files Browse the repository at this point in the history
Make parent mount private before bind mounting rootfs
  • Loading branch information
Mrunal Patel authored Oct 26, 2016
2 parents 6328410 + 6c147f8 commit 4599e70
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions libcontainer/rootfs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,12 @@ func prepareRoot(config *configs.Config) error {
if err := syscall.Mount("", "/", "", uintptr(flag), ""); err != nil {
return err
}
if config.NoPivotRoot {
if err := rootfsParentMountPrivate(config.Rootfs); err != nil {
return err
}

// Make parent mount private to make sure following bind mount does
// not propagate in other namespaces. Also it will help with kernel
// check pass in pivot_root. (IS_SHARED(new_mnt->mnt_parent))
if err := rootfsParentMountPrivate(config.Rootfs); err != nil {
return err
}

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

if err := syscall.PivotRoot(".", "."); err != nil {
// Make the parent mount private
if err := rootfsParentMountPrivate("."); err != nil {
return err
}

// Try again
if err := syscall.PivotRoot(".", "."); err != nil {
return fmt.Errorf("pivot_root %s", err)
}
return fmt.Errorf("pivot_root %s", err)
}

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

0 comments on commit 4599e70

Please sign in to comment.