Browse code

Use rslave instead of rprivate in chrootarchive

With `rprivate` there exists a race where a reference to a mount has
propagated to the new namespace, when `rprivate` is set the parent
namespace is not able to remove the mount due to that reference.
With `rslave` unmounts will propagate correctly into the namespace and
prevent the sort of transient errors that are possible with `rprivate`.

This is a similar fix to https://github.com/opencontainers/runc/pull/1500/commits/117c92745bd098bf05a69489b7b78cac6364e1d0

Signed-off-by: Brian Goff <cpuguy83@gmail.com>

Brian Goff authored on 2017/10/17 02:49:31
Showing 1 changed files
... ...
@@ -26,8 +26,13 @@ func chroot(path string) (err error) {
26 26
 		return fmt.Errorf("Error creating mount namespace before pivot: %v", err)
27 27
 	}
28 28
 
29
-	// make everything in new ns private
30
-	if err := mount.MakeRPrivate("/"); err != nil {
29
+	// Make everything in new ns slave.
30
+	// Don't use `private` here as this could race where the mountns gets a
31
+	//   reference to a mount and an unmount from the host does not propagate,
32
+	//   which could potentially cause transient errors for other operations,
33
+	//   even though this should be relatively small window here `slave` should
34
+	//   not cause any problems.
35
+	if err := mount.MakeRSlave("/"); err != nil {
31 36
 		return err
32 37
 	}
33 38