Make PrivateTmp dirs also inaccessible from the outside

Currently, PrivateTmp=yes means that the service cannot see the /tmp
shared by rest of the system and is isolated from other services using
PrivateTmp, but users can access and modify /tmp as seen by the
service.

Move the private /tmp and /var/tmp directories into a 0077-mode
directory. This way unpriviledged users on the system cannot see (or
modify) /tmp as seen by the service.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2013-03-20 14:08:41 -04:00
parent 1f048a6b6b
commit d34cd37490
5 changed files with 54 additions and 47 deletions
+14 -10
View File
@@ -40,6 +40,7 @@
#include <sys/poll.h>
#include <linux/seccomp-bpf.h>
#include <glob.h>
#include <libgen.h>
#ifdef HAVE_PAM
#include <security/pam_appl.h>
@@ -1551,19 +1552,22 @@ void exec_context_init(ExecContext *c) {
}
void exec_context_tmp_dirs_done(ExecContext *c) {
assert(c);
char* dirs[] = {c->tmp_dir ? c->tmp_dir : c->var_tmp_dir,
c->tmp_dir ? c->var_tmp_dir : NULL,
NULL};
char **dirp;
if (c->tmp_dir) {
rm_rf_dangerous(c->tmp_dir, false, true, false);
free(c->tmp_dir);
c->tmp_dir = NULL;
for(dirp = dirs; *dirp; dirp++) {
char *dir;
rm_rf_dangerous(*dirp, false, true, false);
dir = dirname(*dirp);
rmdir(dir);
free(*dirp);
}
if (c->var_tmp_dir) {
rm_rf_dangerous(c->var_tmp_dir, false, true, false);
free(c->var_tmp_dir);
c->var_tmp_dir = NULL;
}
c->tmp_dir = c->var_tmp_dir = NULL;
}
void exec_context_done(ExecContext *c, bool reloading_or_reexecuting) {