Skip to content

Commit

Permalink
add support for arbitrary whitelist directories
Browse files Browse the repository at this point in the history
  • Loading branch information
smitsohu committed May 2, 2021
1 parent 923d7ad commit 7c63d76
Show file tree
Hide file tree
Showing 4 changed files with 429 additions and 927 deletions.
26 changes: 26 additions & 0 deletions src/firejail/checkcfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ char *xvfb_extra_params = "";
char *netfilter_default = NULL;
unsigned long join_timeout = 5000000; // microseconds
char *config_seccomp_error_action_str = "EPERM";
char **whitelist_reject_topdirs = NULL;

int checkcfg(int val) {
assert(val < CFG_MAX);
Expand Down Expand Up @@ -238,6 +239,31 @@ int checkcfg(int val) {
errExit("strdup");
}

else if (strncmp(ptr, "whitelist-disable-topdir ", 25) == 0) {
char *str = strdup(ptr + 25);
if (!str)
errExit("strdup");

size_t cnt = 0;
size_t sz = 4;
whitelist_reject_topdirs = malloc(sz * sizeof(char *));
if (!whitelist_reject_topdirs)
errExit("malloc");

char *tok = strtok(str, ",");
while (tok) {
whitelist_reject_topdirs[cnt++] = tok;
if (cnt >= sz) {
sz *= 2;
whitelist_reject_topdirs = realloc(whitelist_reject_topdirs, sz * sizeof(char *));
if (!whitelist_reject_topdirs)
errExit("realloc");
}
tok = strtok(NULL, ",");
}
whitelist_reject_topdirs[cnt] = NULL;
}

else
goto errout;

Expand Down
27 changes: 12 additions & 15 deletions src/firejail/firejail.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,26 +122,22 @@ typedef struct interface_t {
uint8_t configured;
} Interface;

typedef struct topdir_t {
char *path;
int fd;
} TopDir;

typedef struct profile_entry_t {
struct profile_entry_t *next;
char *data; // command

// whitelist command parameters
char *link; // link name - set if the file is a link
enum {
WLDIR_HOME = 1, // whitelist in home directory
WLDIR_TMP, // whitelist in /tmp directory
WLDIR_MEDIA, // whitelist in /media directory
WLDIR_MNT, // whitelist in /mnt directory
WLDIR_VAR, // whitelist in /var directory
WLDIR_DEV, // whitelist in /dev directory
WLDIR_OPT, // whitelist in /opt directory
WLDIR_SRV, // whitelist in /srv directory
WLDIR_ETC, // whitelist in /etc directory
WLDIR_SHARE, // whitelist in /usr/share directory
WLDIR_MODULE, // whitelist in /sys/module directory
WLDIR_RUN // whitelist in /run/user/$uid directory
} wldir;
struct wparam_t {
char *file; // resolved file path
char *link; // link path
TopDir *top; // top level directory
} *wparam;

} ProfileEntry;

typedef struct config_t {
Expand Down Expand Up @@ -792,6 +788,7 @@ extern char *xvfb_extra_params;
extern char *netfilter_default;
extern unsigned long join_timeout;
extern char *config_seccomp_error_action_str;
extern char **whitelist_reject_topdirs;

int checkcfg(int val);
void print_compiletime_support(void);
Expand Down
Loading

0 comments on commit 7c63d76

Please sign in to comment.