Commit 4de2791f by Serge Hallyn

always remount / rslave before running creation template (if root)

If we're not root, our mounts in private userns won't get pushed back anyway. If we are root, we need to make sure that anything the template does gets cleaned up. Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com> Acked-by: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent 0779c6f9
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/mount.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <sched.h> #include <sched.h>
...@@ -833,11 +834,23 @@ static bool create_run_template(struct lxc_container *c, char *tpath, bool quiet ...@@ -833,11 +834,23 @@ static bool create_run_template(struct lxc_container *c, char *tpath, bool quiet
exit(1); exit(1);
} }
if (strcmp(bdev->type, "dir") != 0) { if (geteuid() == 0) {
if (unshare(CLONE_NEWNS) < 0) { if (unshare(CLONE_NEWNS) < 0) {
ERROR("error unsharing mounts"); ERROR("error unsharing mounts");
exit(1); exit(1);
} }
if (detect_shared_rootfs()) {
if (mount("", "", NULL, MS_SLAVE|MS_REC, 0)) {
SYSERROR("Failed to make / rslave to run template");
ERROR("Continuing...");
}
}
}
if (strcmp(bdev->type, "dir") != 0) {
if (geteuid() != 0) {
ERROR("non-root users can only create directory-backed containers");
exit(1);
}
if (bdev->ops->mount(bdev) < 0) { if (bdev->ops->mount(bdev) < 0) {
ERROR("Error mounting rootfs"); ERROR("Error mounting rootfs");
exit(1); exit(1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment