Don't mount over / if pivot_root_only is enabled
authorStephen Röttger <stephen.roettger@gmail.com>
Sun, 25 Sep 2016 13:48:58 +0000 (15:48 +0200)
committerStephen Röttger <sroettger@google.com>
Fri, 30 Sep 2016 14:30:59 +0000 (16:30 +0200)
The intention behind pivot_root_only is to support nested user
namespaces. However, if we bind mount over /, which happens by default,
the kernel will deny CLONE_NEWUSER.

mount.c

diff --git a/mount.c b/mount.c
index d719e6675b57e589b63948bdf56c32b5453c2ba6..2915332896f5082e43b6ae6d0441885b75f21a40 100644 (file)
--- a/mount.c
+++ b/mount.c
@@ -203,6 +203,12 @@ static bool mountInitNsInternal(struct nsjconf_t *nsjconf)
 
        struct mounts_t *p;
        TAILQ_FOREACH(p, &nsjconf->mountpts, pointers) {
+               // The intention behind pivot_root_only is to allow creating
+               // nested usernamespaces. If we bind mount over /, the kernel
+               // will see the process as chrooted and deny CLONE_NEWUSER.
+               if (nsjconf->pivot_root_only && strcmp(p->dst, "/") == 0) {
+                       continue;
+               }
                char dst[PATH_MAX];
                snprintf(dst, sizeof(dst), "%s/%s", newrootdir, p->dst);
                if (mountMount(nsjconf, p, "/old_root", dst) == false) {