aboutsummaryrefslogtreecommitdiff
path: root/tools/virtiofsd/passthrough_ll.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/virtiofsd/passthrough_ll.c')
-rw-r--r--tools/virtiofsd/passthrough_ll.c34
1 files changed, 11 insertions, 23 deletions
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index 477e6ee0b5..ff53df4451 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -2393,8 +2393,6 @@ static void setup_wait_parent_capabilities(void)
static void setup_namespaces(struct lo_data *lo, struct fuse_session *se)
{
pid_t child;
- char template[] = "virtiofsd-XXXXXX";
- char *tmpdir;
/*
* Create a new pid namespace for *child* processes. We'll have to
@@ -2458,33 +2456,23 @@ static void setup_namespaces(struct lo_data *lo, struct fuse_session *se)
exit(1);
}
- tmpdir = mkdtemp(template);
- if (!tmpdir) {
- fuse_log(FUSE_LOG_ERR, "tmpdir(%s): %m\n", template);
- exit(1);
- }
-
- if (mount("/proc/self/fd", tmpdir, NULL, MS_BIND, NULL) < 0) {
- fuse_log(FUSE_LOG_ERR, "mount(/proc/self/fd, %s, MS_BIND): %m\n",
- tmpdir);
+ /*
+ * We only need /proc/self/fd. Prevent ".." from accessing parent
+ * directories of /proc/self/fd by bind-mounting it over /proc. Since / was
+ * previously remounted with MS_REC | MS_SLAVE this mount change only
+ * affects our process.
+ */
+ if (mount("/proc/self/fd", "/proc", NULL, MS_BIND, NULL) < 0) {
+ fuse_log(FUSE_LOG_ERR, "mount(/proc/self/fd, MS_BIND): %m\n");
exit(1);
}
- /* Now we can get our /proc/self/fd directory file descriptor */
- lo->proc_self_fd = open(tmpdir, O_PATH);
+ /* Get the /proc (actually /proc/self/fd, see above) file descriptor */
+ lo->proc_self_fd = open("/proc", O_PATH);
if (lo->proc_self_fd == -1) {
- fuse_log(FUSE_LOG_ERR, "open(%s, O_PATH): %m\n", tmpdir);
+ fuse_log(FUSE_LOG_ERR, "open(/proc, O_PATH): %m\n");
exit(1);
}
-
- if (umount2(tmpdir, MNT_DETACH) < 0) {
- fuse_log(FUSE_LOG_ERR, "umount2(%s, MNT_DETACH): %m\n", tmpdir);
- exit(1);
- }
-
- if (rmdir(tmpdir) < 0) {
- fuse_log(FUSE_LOG_ERR, "rmdir(%s): %m\n", tmpdir);
- }
}
/*