diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/firejail/fs.c | 57 | ||||
-rw-r--r-- | src/firejail/pulseaudio.c | 8 | ||||
-rw-r--r-- | src/firejail/x11.c | 9 | ||||
-rw-r--r-- | src/firemon/procevent.c | 44 |
4 files changed, 83 insertions, 35 deletions
diff --git a/src/firejail/fs.c b/src/firejail/fs.c index 88f92ad74..f3ed67928 100644 --- a/src/firejail/fs.c +++ b/src/firejail/fs.c | |||
@@ -484,29 +484,44 @@ void fs_rdonly(const char *dir) { | |||
484 | 484 | ||
485 | static void fs_rdwr(const char *dir) { | 485 | static void fs_rdwr(const char *dir) { |
486 | assert(dir); | 486 | assert(dir); |
487 | // check directory exists | 487 | // check directory exists and ensure we have a resolved path |
488 | // the resolved path allows to run a sanity check after the mount | ||
489 | char *path = realpath(dir, NULL); | ||
490 | if (path == NULL) | ||
491 | return; | ||
492 | // allow only user owned directories, except the user is root | ||
493 | uid_t u = getuid(); | ||
488 | struct stat s; | 494 | struct stat s; |
489 | int rv = stat(dir, &s); | 495 | int rv = stat(path, &s); |
490 | if (rv == 0) { | 496 | if (rv) { |
491 | // if the file is outside /home directory, allow only root user | 497 | free(path); |
492 | uid_t u = getuid(); | 498 | return; |
493 | if (u != 0 && s.st_uid != u) { | 499 | } |
494 | fwarning("you are not allowed to change %s to read-write\n", dir); | 500 | if (u != 0 && s.st_uid != u) { |
495 | return; | 501 | fwarning("you are not allowed to change %s to read-write\n", path); |
496 | } | 502 | free(path); |
497 | 503 | return; | |
498 | // mount --bind /bin /bin | 504 | } |
499 | // mount --bind -o remount,rw /bin | 505 | // mount --bind /bin /bin |
500 | unsigned long flags = 0; | 506 | // mount --bind -o remount,rw /bin |
501 | get_mount_flags(dir, &flags); | 507 | unsigned long flags = 0; |
502 | if ((flags & MS_RDONLY) == 0) | 508 | get_mount_flags(path, &flags); |
503 | return; | 509 | if ((flags & MS_RDONLY) == 0) { |
504 | flags &= ~MS_RDONLY; | 510 | free(path); |
505 | if (mount(dir, dir, NULL, MS_BIND|MS_REC, NULL) < 0 || | 511 | return; |
506 | mount(NULL, dir, NULL, flags|MS_BIND|MS_REMOUNT|MS_REC, NULL) < 0) | ||
507 | errExit("mount read-write"); | ||
508 | fs_logger2("read-write", dir); | ||
509 | } | 512 | } |
513 | flags &= ~MS_RDONLY; | ||
514 | if (mount(path, path, NULL, MS_BIND|MS_REC, NULL) < 0 || | ||
515 | mount(NULL, path, NULL, flags|MS_BIND|MS_REMOUNT|MS_REC, NULL) < 0) | ||
516 | errExit("mount read-write"); | ||
517 | fs_logger2("read-write", path); | ||
518 | |||
519 | // run a check on /proc/self/mountinfo to validate the mount | ||
520 | MountData *mptr = get_last_mount(); | ||
521 | if (strncmp(mptr->dir, path, strlen(path)) != 0) | ||
522 | errLogExit("invalid read-write mount"); | ||
523 | |||
524 | free(path); | ||
510 | } | 525 | } |
511 | 526 | ||
512 | void fs_noexec(const char *dir) { | 527 | void fs_noexec(const char *dir) { |
diff --git a/src/firejail/pulseaudio.c b/src/firejail/pulseaudio.c index eaaba86c0..15d44e4cc 100644 --- a/src/firejail/pulseaudio.c +++ b/src/firejail/pulseaudio.c | |||
@@ -178,10 +178,10 @@ void pulseaudio_init(void) { | |||
178 | 178 | ||
179 | // check /proc/self/mountinfo to confirm the mount is ok | 179 | // check /proc/self/mountinfo to confirm the mount is ok |
180 | MountData *mptr = get_last_mount(); | 180 | MountData *mptr = get_last_mount(); |
181 | if (strncmp(mptr->dir, homeusercfg, strlen(homeusercfg)) != 0) | 181 | if (strcmp(mptr->dir, homeusercfg) != 0) |
182 | errLogExit("invalid mount on top of %s (should be %s)\n", mptr->dir, homeusercfg); | 182 | errLogExit("invalid pulseaudio mount"); |
183 | if (strncmp(mptr->fstype, "tmpfs", 5) != 0) | 183 | if (strcmp(mptr->fstype, "tmpfs") != 0) |
184 | errLogExit("invalid mount on top of %s (filesystem type is %s)\n", mptr->dir, mptr->fstype); | 184 | errLogExit("invalid pulseaudio mount"); |
185 | 185 | ||
186 | char *p; | 186 | char *p; |
187 | if (asprintf(&p, "%s/client.conf", homeusercfg) == -1) | 187 | if (asprintf(&p, "%s/client.conf", homeusercfg) == -1) |
diff --git a/src/firejail/x11.c b/src/firejail/x11.c index 0eace3215..ec8775370 100644 --- a/src/firejail/x11.c +++ b/src/firejail/x11.c | |||
@@ -1196,10 +1196,11 @@ void x11_xorg(void) { | |||
1196 | 1196 | ||
1197 | // check /proc/self/mountinfo to confirm the mount is ok | 1197 | // check /proc/self/mountinfo to confirm the mount is ok |
1198 | MountData *mptr = get_last_mount(); | 1198 | MountData *mptr = get_last_mount(); |
1199 | if (strncmp(mptr->dir, dest, strlen(dest)) != 0) | 1199 | if (strcmp(mptr->dir, dest) != 0) |
1200 | errLogExit("invalid mount on top of %s (should be %s)\n", mptr->dir, dest); | 1200 | errLogExit("invalid .Xauthority mount"); |
1201 | if (strncmp(mptr->fstype, "tmpfs", 5) != 0) | 1201 | if (strcmp(mptr->fstype, "tmpfs") != 0) |
1202 | errLogExit("invalid mount on top of %s (filesystem type is %s)\n", mptr->dir, mptr->fstype); | 1202 | errLogExit("invalid .Xauthority mount"); |
1203 | |||
1203 | free(dest); | 1204 | free(dest); |
1204 | #endif | 1205 | #endif |
1205 | } | 1206 | } |
diff --git a/src/firemon/procevent.c b/src/firemon/procevent.c index 301e5397b..5b16191be 100644 --- a/src/firemon/procevent.c +++ b/src/firemon/procevent.c | |||
@@ -94,10 +94,21 @@ static int pid_is_firejail(pid_t pid) { | |||
94 | // list of firejail arguments that don't trigger sandbox creation | 94 | // list of firejail arguments that don't trigger sandbox creation |
95 | // the initial -- is not included | 95 | // the initial -- is not included |
96 | char *exclude_args[] = { | 96 | char *exclude_args[] = { |
97 | "ls", "list", "tree", "x11", "help", "version", "top", "netstats", "debug-syscalls", | 97 | // all print options |
98 | "debug-errnos", "debug-protocols", "protocol.print", "debug.caps", | 98 | "apparmor.print", "caps.print", "cpu.print", "dns.print", "fs.print", "netfilter.print", |
99 | "shutdown", "bandwidth", "caps.print", "cpu.print", "debug-caps", | 99 | "netfilter6.print", "profile.print", "protocol.print", "seccomp.print", |
100 | "fs.print", "get", "overlay-clean", NULL | 100 | // debug |
101 | "debug-caps", "debug-errnos", "debug-protocols", "debug-syscalls", | ||
102 | // file transfer | ||
103 | "ls", "get", "put", | ||
104 | // stats | ||
105 | "tree", "list", "top", | ||
106 | // network | ||
107 | "netstats", "bandwidth", | ||
108 | // etc | ||
109 | "help", "version", "overlay-clean", | ||
110 | |||
111 | NULL // end of list marker | ||
101 | }; | 112 | }; |
102 | 113 | ||
103 | int i; | 114 | int i; |
@@ -291,6 +302,7 @@ static int procevent_monitor(const int sock, pid_t mypid) { | |||
291 | child %= max_pids; | 302 | child %= max_pids; |
292 | pids[child].level = pids[pid].level + 1; | 303 | pids[child].level = pids[pid].level + 1; |
293 | pids[child].uid = pid_get_uid(child); | 304 | pids[child].uid = pid_get_uid(child); |
305 | pids[child].parent = pid; | ||
294 | } | 306 | } |
295 | sprintf(lineptr, " fork"); | 307 | sprintf(lineptr, " fork"); |
296 | break; | 308 | break; |
@@ -318,12 +330,22 @@ static int procevent_monitor(const int sock, pid_t mypid) { | |||
318 | sprintf(lineptr, " exit"); | 330 | sprintf(lineptr, " exit"); |
319 | break; | 331 | break; |
320 | 332 | ||
333 | |||
334 | |||
321 | case PROC_EVENT_UID: | 335 | case PROC_EVENT_UID: |
322 | pid = proc_ev->event_data.id.process_tgid; | 336 | pid = proc_ev->event_data.id.process_tgid; |
323 | #ifdef DEBUG_PRCTL | 337 | #ifdef DEBUG_PRCTL |
324 | printf("%s: %d, event uid, pid %d\n", __FUNCTION__, __LINE__, pid); | 338 | printf("%s: %d, event uid, pid %d\n", __FUNCTION__, __LINE__, pid); |
325 | #endif | 339 | #endif |
326 | sprintf(lineptr, " uid "); | 340 | if (pids[pid].level == 1 || |
341 | pids[pids[pid].parent].level == 1) { | ||
342 | sprintf(lineptr, "\n"); | ||
343 | continue; | ||
344 | } | ||
345 | else | ||
346 | sprintf(lineptr, " uid (%d:%d)", | ||
347 | proc_ev->event_data.id.r.ruid, | ||
348 | proc_ev->event_data.id.e.euid); | ||
327 | break; | 349 | break; |
328 | 350 | ||
329 | case PROC_EVENT_GID: | 351 | case PROC_EVENT_GID: |
@@ -331,9 +353,19 @@ static int procevent_monitor(const int sock, pid_t mypid) { | |||
331 | #ifdef DEBUG_PRCTL | 353 | #ifdef DEBUG_PRCTL |
332 | printf("%s: %d, event gid, pid %d\n", __FUNCTION__, __LINE__, pid); | 354 | printf("%s: %d, event gid, pid %d\n", __FUNCTION__, __LINE__, pid); |
333 | #endif | 355 | #endif |
334 | sprintf(lineptr, " gid "); | 356 | if (pids[pid].level == 1 || |
357 | pids[pids[pid].parent].level == 1) { | ||
358 | sprintf(lineptr, "\n"); | ||
359 | continue; | ||
360 | } | ||
361 | else | ||
362 | sprintf(lineptr, " gid (%d:%d)", | ||
363 | proc_ev->event_data.id.r.rgid, | ||
364 | proc_ev->event_data.id.e.egid); | ||
335 | break; | 365 | break; |
336 | 366 | ||
367 | |||
368 | |||
337 | case PROC_EVENT_SID: | 369 | case PROC_EVENT_SID: |
338 | pid = proc_ev->event_data.sid.process_tgid; | 370 | pid = proc_ev->event_data.sid.process_tgid; |
339 | #ifdef DEBUG_PRCTL | 371 | #ifdef DEBUG_PRCTL |