Skip to content

Commit

Permalink
some hardening
Browse files Browse the repository at this point in the history
  • Loading branch information
smitsohu committed Jan 17, 2022
1 parent b8d282c commit 493a0ef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/firejail/fs_etc.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ static int check_dir_or_file(const char *fname) {
static void duplicate(const char *fname, const char *private_dir, const char *private_run_dir) {
assert(fname);

if (*fname == '~' || *fname == '/' || strncmp(fname, "..", 2) == 0) {
if (*fname == '~' || *fname == '/' || strstr(fname, "..")) {
fprintf(stderr, "Error: \"%s\" is an invalid filename\n", fname);
exit(1);
}
Expand Down
8 changes: 7 additions & 1 deletion src/firejail/sbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <unistd.h>
#include <net/if.h>
#include <stdarg.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include "../include/seccomp.h"

Expand Down Expand Up @@ -77,6 +78,11 @@ static int __attribute__((noreturn)) sbox_do_exec_v(unsigned filtermask, char *

umask(027);

// https://seclists.org/oss-sec/2021/q4/43
struct rlimit tozero = { .rlim_cur = 0, .rlim_max = 0 };
if (setrlimit(RLIMIT_CORE, &tozero))
errExit("setrlimit");

// apply filters
if (filtermask & SBOX_CAPS_NONE) {
caps_drop_all();
Expand Down Expand Up @@ -289,7 +295,7 @@ int sbox_run_v(unsigned filtermask, char * const arg[]) {
if (waitpid(child, &status, 0) == -1 ) {
errExit("waitpid");
}
if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
fprintf(stderr, "Error: failed to run %s, exiting...\n", arg[0]);
exit(1);
}
Expand Down

0 comments on commit 493a0ef

Please sign in to comment.