From 7917222486d0042a1800f25e12a9fa1f162c2eb0 Mon Sep 17 00:00:00 2001 From: Robert Swiecki Date: Wed, 21 Jun 2017 18:29:02 +0200 Subject: [PATCH] mount: Use /tmp/nsjail.[tmp|root]. --- cmdline.c | 1 + common.h | 1 + mount.c | 7 +++++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cmdline.c b/cmdline.c index 5584662..458edf3 100644 --- a/cmdline.c +++ b/cmdline.c @@ -353,6 +353,7 @@ bool cmdlineParse(int argc, char *argv[], struct nsjconf_t * nsjconf) .iface_vs_gw = "0.0.0.0", .kafel_file = NULL, .kafel_string = NULL, + .orig_euid = geteuid(), }; /* *INDENT-ON* */ diff --git a/common.h b/common.h index 62d78eb..f16c12d 100644 --- a/common.h +++ b/common.h @@ -164,6 +164,7 @@ struct nsjconf_t { size_t cgroup_pids_max; FILE *kafel_file; char *kafel_string; + uid_t orig_euid; TAILQ_HEAD(udmaplist, idmap_t) uids; TAILQ_HEAD(gdmaplist, idmap_t) gids; TAILQ_HEAD(envlist, charptr_t) envs; diff --git a/mount.c b/mount.c index ba55951..296b50b 100644 --- a/mount.c +++ b/mount.c @@ -254,7 +254,8 @@ static bool mountInitNsInternal(struct nsjconf_t *nsjconf) return false; } - const char *const destdir = "/tmp/nsjail.root"; + char destdir[PATH_MAX]; + snprintf(destdir, sizeof(destdir), "/tmp/nsjail.root.%d", (int)nsjconf->orig_euid); if (mkdir(destdir, 0755) == -1 && errno != EEXIST) { PLOG_E("Couldn't create '%s' directory. Maybe remove it?", destdir); return false; @@ -263,7 +264,9 @@ static bool mountInitNsInternal(struct nsjconf_t *nsjconf) PLOG_E("mount('%s', 'tmpfs')", destdir); return false; } - const char *const tmpdir = "/tmp/nsjail.tmp"; + + char tmpdir[PATH_MAX]; + snprintf(tmpdir, sizeof(tmpdir), "/tmp/nsjail.tmp.%d", (int)nsjconf->orig_euid); if (mkdir(tmpdir, 0755) == -1 && errno != EEXIST) { PLOG_E("Couldn't create '%s' directory. Maybe remove it?", tmpdir); return false;