From: "Serge E. Hallyn" <serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
To: Linux Containers <containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org>
Subject: [PATCH 1/1] stop rootless containers from messing with host mounts
Date: Mon, 6 Apr 2009 16:27:24 -0500 [thread overview]
Message-ID: <20090406212724.GA30355@us.ibm.com> (raw)
If a container has no root, lxc still remounts /proc. If the
system had marked / as MS_SHARED, as is the case in Fedora 11,
then even though the container is in a new mounts namespace, the
mount event is propagated back to the host mounts ns, overmounting
the host's /proc. After that, ps -ef will no longer show host
processes for a host admin.
So mark / as MS_SLAVE in a container after spawning a new mounts
namespace, and before actually chrooting. This way the container
will still receive mount events from the host.
Signed-off-by: Serge Hallyn <serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
---
src/lxc/conf.c | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 6c3476a..d807ae3 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -60,6 +60,10 @@
#define MS_REC 16384
#endif
+#ifndef MS_SLAVE
+#define MS_SLAVE 1<<19
+#endif
+
typedef int (*instanciate_cb)(const char *directory,
const char *file, pid_t pid);
@@ -1847,6 +1851,12 @@ int lxc_setup(const char *name, const char *cons,
return -LXC_ERROR_SETUP_TTY;
}
+ /* Make sure we don't end up forwarding mount events back to parent */
+ if (mount("", "/", NULL, MS_SLAVE|MS_REC, NULL) < 0) {
+ lxc_log_error("Failed to set host / as slave for '%s'", name);
+ return -LXC_ERROR_SETUP_ROOTFS;
+ }
+
if (conf_is_set(flags, rootfs) && setup_rootfs(name)) {
lxc_log_error("failed to set rootfs for '%s'", name);
return -LXC_ERROR_SETUP_ROOTFS;
--
1.6.2
reply other threads:[~2009-04-06 21:27 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090406212724.GA30355@us.ibm.com \
--to=serue-r/jw6+rmf7hqt0dzr+alfa@public.gmane.org \
--cc=containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox