public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [patch v3] Allow for unpriviledged nested containers
@ 2021-11-15 23:08 DJ Delorie
  2021-11-17 11:06 ` Florian Weimer
  0 siblings, 1 reply; 11+ messages in thread
From: DJ Delorie @ 2021-11-15 23:08 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-alpha


Subject: Allow for unpriviledged nested containers

When running a "make check" in an untrusted podman container, we do
not have priviledges to mount a new /proc.  Previously, we just failed
to initialize the container and thus all test-container tests were
"unsupported".  With this change, we bind mount the parent's /proc,
which we have priviledges to do.  Note that MS_REC is needed as /proc
typically has things mounted within it, and not mounting those would
be a security hole[*].

[*] https://stackoverflow.com/questions/23417521/mounting-proc-in-non-privileged-namespace-sandbox

diff --git a/support/test-container.c b/support/test-container.c
index 94498d39019..8f47f136e75 100644
--- a/support/test-container.c
+++ b/support/test-container.c
@@ -231,7 +231,7 @@ concat (const char *str, ...)
 static void
 trymount (const char *src, const char *dest)
 {
-  if (mount (src, dest, "", MS_BIND, NULL) < 0)
+  if (mount (src, dest, "", MS_BIND|MS_REC, NULL) < 0)
     FAIL_EXIT1 ("can't mount %s onto %s\n", src, dest);
 }
 
@@ -1094,6 +1094,13 @@ main (int argc, char **argv)
   trymount (support_srcdir_root, new_srcdir_path);
   trymount (support_objdir_root, new_objdir_path);
 
+  /* It may not be possible to mount /proc directly.  */
+  {
+    char *new_proc = concat (new_root_path, "/proc", NULL);
+    xmkdirp (new_proc, 0755);
+    trymount ("/proc", new_proc);
+  }
+
   xmkdirp (concat (new_root_path, "/dev", NULL), 0755);
   devmount (new_root_path, "null");
   devmount (new_root_path, "zero");
@@ -1163,11 +1170,6 @@ main (int argc, char **argv)
 
   maybe_xmkdir ("/tmp", 0755);
 
-  /* Now that we're pid 1 (effectively "root") we can mount /proc  */
-  maybe_xmkdir ("/proc", 0777);
-  if (mount ("proc", "/proc", "proc", 0, NULL) < 0)
-    FAIL_EXIT1 ("Unable to mount /proc: ");
-
   /* We map our original UID to the same UID in the container so we
      can own our own files normally.  */
   UMAP = open ("/proc/self/uid_map", O_WRONLY);


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-11-18 20:25 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-15 23:08 [patch v3] Allow for unpriviledged nested containers DJ Delorie
2021-11-17 11:06 ` Florian Weimer
2021-11-17 22:44   ` DJ Delorie
2021-11-18 11:35     ` Florian Weimer
2021-11-18 18:37       ` DJ Delorie
2021-11-18 19:47         ` Florian Weimer
2021-11-18 19:52           ` DJ Delorie
2021-11-18 19:55             ` Florian Weimer
2021-11-18 20:18               ` DJ Delorie
2021-11-18 20:20                 ` Florian Weimer
2021-11-18 20:25                   ` DJ Delorie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).