diff options
author | Cristian Toader <cristian.matei.toader@gmail.com> | 2013-07-29 16:30:39 +0300 |
---|---|---|
committer | Cristian Toader <cristian.matei.toader@gmail.com> | 2013-07-29 16:30:39 +0300 |
commit | 8022def6f05bf40e1c6e0fd15d77ed0ecf5c3406 (patch) | |
tree | f080ff487369b0a17d6c0e1a9b4c88560e7c379c /src | |
parent | 6d5b0367f6e0035f99570b5bb76a75322ae9a85e (diff) | |
download | tor-8022def6f05bf40e1c6e0fd15d77ed0ecf5c3406.tar tor-8022def6f05bf40e1c6e0fd15d77ed0ecf5c3406.tar.gz |
added openat parameter filter
Diffstat (limited to 'src')
-rw-r--r-- | src/common/sandbox.c | 19 | ||||
-rw-r--r-- | src/common/sandbox.h | 4 | ||||
-rw-r--r-- | src/common/util.c | 4 | ||||
-rw-r--r-- | src/or/main.c | 2 |
4 files changed, 22 insertions, 7 deletions
diff --git a/src/common/sandbox.c b/src/common/sandbox.c index 2e8467d7c..efadeca84 100644 --- a/src/common/sandbox.c +++ b/src/common/sandbox.c @@ -117,7 +117,6 @@ static int filter_nopar_gen[] = { SCMP_SYS(mprotect), SCMP_SYS(mremap), SCMP_SYS(munmap), - SCMP_SYS(openat), SCMP_SYS(poll), SCMP_SYS(prctl), SCMP_SYS(read), @@ -158,7 +157,7 @@ static int filter_nopar_gen[] = { }; const char* -sandbox_intern_string(char *param) +sandbox_intern_string(const char *param) { int i, filter_size; sandbox_cfg_t *elem; @@ -228,15 +227,25 @@ prot_strdup(char* str) int sandbox_cfg_allow_open_filename(sandbox_cfg_t **cfg, char *file) { - sandbox_cfg_t *elem = (sandbox_cfg_t*) malloc(sizeof(sandbox_cfg_t)); + sandbox_cfg_t *elem = NULL; + intptr_t prot_str = (intptr_t) prot_strdup((char*) file); + elem = (sandbox_cfg_t*) malloc(sizeof(sandbox_cfg_t)); elem->syscall = SCMP_SYS(open); elem->pindex = 0; elem->ptype = PARAM_PTR; - elem->param = (intptr_t) prot_strdup((char*) file); + elem->param = prot_str; elem->prot = 1; + elem->next = filter_dynamic; + filter_dynamic = elem; - // fifo + // also allow openat + elem = (sandbox_cfg_t*) malloc(sizeof(sandbox_cfg_t)); + elem->syscall = SCMP_SYS(openat); + elem->pindex = 1; + elem->ptype = PARAM_PTR; + elem->param = prot_str; + elem->prot = 1; elem->next = filter_dynamic; filter_dynamic = elem; diff --git a/src/common/sandbox.h b/src/common/sandbox.h index 9acf8c4a9..104d832bc 100644 --- a/src/common/sandbox.h +++ b/src/common/sandbox.h @@ -29,7 +29,9 @@ */ #ifdef __linux__ +#ifndef __USE_GNU #define __USE_GNU +#endif #include <sys/ucontext.h> #define MAX_PARAM_LEN 64 @@ -80,7 +82,7 @@ typedef struct pfd_elem sandbox_cfg_t; void sandbox_set_debugging_fd(int fd); int tor_global_sandbox(void); -const char* sandbox_intern_string(char *param); +const char* sandbox_intern_string(const char *param); sandbox_cfg_t * sandbox_cfg_new(); int sandbox_cfg_allow_open_filename(sandbox_cfg_t **cfg, char *file); diff --git a/src/common/util.c b/src/common/util.c index 651554ed2..75462b68a 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -24,6 +24,7 @@ #include "torint.h" #include "container.h" #include "address.h" +#include "../common/sandbox.h" #ifdef _WIN32 #include <io.h> @@ -3042,6 +3043,7 @@ smartlist_t * tor_listdir(const char *dirname) { smartlist_t *result; + const char *prot_dname = sandbox_intern_string(dirname); #ifdef _WIN32 char *pattern=NULL; TCHAR tpattern[MAX_PATH] = {0}; @@ -3085,7 +3087,7 @@ tor_listdir(const char *dirname) #else DIR *d; struct dirent *de; - if (!(d = opendir(dirname))) + if (!(d = opendir(prot_dname))) return NULL; result = smartlist_new(); diff --git a/src/or/main.c b/src/or/main.c index 269d3fd9b..d50f239e6 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -2645,6 +2645,8 @@ sandbox_init_filter() sandbox_cfg_t *cfg = sandbox_cfg_new(); sandbox_cfg_allow_open_filename(&cfg, + get_datadir_fname("cached-status")); + sandbox_cfg_allow_open_filename(&cfg, get_datadir_fname("cached-certs")); sandbox_cfg_allow_open_filename(&cfg, get_datadir_fname("cached-consensus")); |