mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 13:43:47 +01:00
fixed memory leak, added array filter support
This commit is contained in:
parent
89b39db003
commit
44a4464cf6
@ -37,6 +37,7 @@
|
|||||||
#include <linux/futex.h>
|
#include <linux/futex.h>
|
||||||
#include <bits/signum.h>
|
#include <bits/signum.h>
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
#include <seccomp.h>
|
#include <seccomp.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -616,7 +617,7 @@ prot_strdup(char* str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
sandbox_cfg_allow_open_filename(sandbox_cfg_t **cfg, char *file)
|
sandbox_cfg_allow_open_filename(sandbox_cfg_t **cfg, char *file, char fr)
|
||||||
{
|
{
|
||||||
sandbox_cfg_t *elem = NULL;
|
sandbox_cfg_t *elem = NULL;
|
||||||
|
|
||||||
@ -630,11 +631,37 @@ sandbox_cfg_allow_open_filename(sandbox_cfg_t **cfg, char *file)
|
|||||||
elem->next = *cfg;
|
elem->next = *cfg;
|
||||||
*cfg = elem;
|
*cfg = elem;
|
||||||
|
|
||||||
|
if (fr) tor_free_(file);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
sandbox_cfg_allow_openat_filename(sandbox_cfg_t **cfg, char *file)
|
sandbox_cfg_allow_open_filename_array(sandbox_cfg_t **cfg, int num, ...)
|
||||||
|
{
|
||||||
|
int rc = 0, i;
|
||||||
|
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, num);
|
||||||
|
|
||||||
|
for (i = 0; i < num; i++) {
|
||||||
|
char *fn = va_arg(ap, char*);
|
||||||
|
char fr = (char) va_arg(ap, int);
|
||||||
|
|
||||||
|
rc = sandbox_cfg_allow_open_filename(cfg, fn, fr);
|
||||||
|
if(rc) {
|
||||||
|
log_err(LD_BUG,"(Sandbox) failed on par %d", i);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
end:
|
||||||
|
va_end(ap);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
sandbox_cfg_allow_openat_filename(sandbox_cfg_t **cfg, char *file, char fr)
|
||||||
{
|
{
|
||||||
sandbox_cfg_t *elem = NULL;
|
sandbox_cfg_t *elem = NULL;
|
||||||
|
|
||||||
@ -648,6 +675,32 @@ sandbox_cfg_allow_openat_filename(sandbox_cfg_t **cfg, char *file)
|
|||||||
elem->next = *cfg;
|
elem->next = *cfg;
|
||||||
*cfg = elem;
|
*cfg = elem;
|
||||||
|
|
||||||
|
if (fr) tor_free_(file);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
sandbox_cfg_allow_openat_filename_array(sandbox_cfg_t **cfg, int num, ...)
|
||||||
|
{
|
||||||
|
int rc = 0, i;
|
||||||
|
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, num);
|
||||||
|
|
||||||
|
for (i = 0; i < num; i++) {
|
||||||
|
char *fn = va_arg(ap, char*);
|
||||||
|
char fr = (char) va_arg(ap, int);
|
||||||
|
|
||||||
|
rc = sandbox_cfg_allow_openat_filename(cfg, fn, fr);
|
||||||
|
if(rc) {
|
||||||
|
log_err(LD_BUG,"(Sandbox) failed on par %d", i);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
end:
|
||||||
|
va_end(ap);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -669,6 +722,30 @@ sandbox_cfg_allow_execve(sandbox_cfg_t **cfg, char *com)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
sandbox_cfg_allow_execve_array(sandbox_cfg_t **cfg, int num, ...)
|
||||||
|
{
|
||||||
|
int rc = 0, i;
|
||||||
|
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, num);
|
||||||
|
|
||||||
|
for (i = 0; i < num; i++) {
|
||||||
|
char *fn = va_arg(ap, char*);
|
||||||
|
|
||||||
|
rc = sandbox_cfg_allow_execve(cfg, fn);
|
||||||
|
|
||||||
|
if(rc) {
|
||||||
|
log_err(LD_BUG,"(Sandbox) failed on par %d", i);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
end:
|
||||||
|
va_end(ap);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
add_param_filter(scmp_filter_ctx ctx, sandbox_cfg_t* cfg)
|
add_param_filter(scmp_filter_ctx ctx, sandbox_cfg_t* cfg)
|
||||||
{
|
{
|
||||||
|
@ -98,9 +98,18 @@ int tor_global_sandbox(void);
|
|||||||
const char* sandbox_intern_string(const char *param);
|
const char* sandbox_intern_string(const char *param);
|
||||||
|
|
||||||
sandbox_cfg_t * sandbox_cfg_new();
|
sandbox_cfg_t * sandbox_cfg_new();
|
||||||
int sandbox_cfg_allow_open_filename(sandbox_cfg_t **cfg, char *file);
|
|
||||||
int sandbox_cfg_allow_openat_filename(sandbox_cfg_t **cfg, char *file);
|
int sandbox_cfg_allow_open_filename(sandbox_cfg_t **cfg, char *file,
|
||||||
|
char fr);
|
||||||
|
int sandbox_cfg_allow_open_filename_array(sandbox_cfg_t **cfg, int num, ...);
|
||||||
|
|
||||||
|
int sandbox_cfg_allow_openat_filename(sandbox_cfg_t **cfg, char *file,
|
||||||
|
char fr);
|
||||||
|
int sandbox_cfg_allow_openat_filename_array(sandbox_cfg_t **cfg, int num, ...);
|
||||||
|
|
||||||
int sandbox_cfg_allow_execve(sandbox_cfg_t **cfg, char *com);
|
int sandbox_cfg_allow_execve(sandbox_cfg_t **cfg, char *com);
|
||||||
|
int sandbox_cfg_allow_execve_array(sandbox_cfg_t **cfg, int num, ...);
|
||||||
|
|
||||||
int sandbox_init(sandbox_cfg_t* cfg);
|
int sandbox_init(sandbox_cfg_t* cfg);
|
||||||
|
|
||||||
#endif /* SANDBOX_H_ */
|
#endif /* SANDBOX_H_ */
|
||||||
|
104
src/or/main.c
104
src/or/main.c
@ -2644,73 +2644,51 @@ sandbox_init_filter()
|
|||||||
{
|
{
|
||||||
sandbox_cfg_t *cfg = sandbox_cfg_new();
|
sandbox_cfg_t *cfg = sandbox_cfg_new();
|
||||||
|
|
||||||
// TODO: mem leak
|
sandbox_cfg_allow_openat_filename(&cfg,
|
||||||
sandbox_cfg_allow_openat_filename(&cfg, get_datadir_fname("cached-status"));
|
get_datadir_fname("cached-status"), 1);
|
||||||
|
|
||||||
sandbox_cfg_allow_open_filename(&cfg, get_datadir_fname("cached-certs"));
|
sandbox_cfg_allow_open_filename_array(&cfg, 22,
|
||||||
sandbox_cfg_allow_open_filename(&cfg, get_datadir_fname("cached-certs.tmp"));
|
get_datadir_fname("cached-certs"), 1,
|
||||||
sandbox_cfg_allow_open_filename(&cfg, get_datadir_fname("cached-consensus"));
|
get_datadir_fname("cached-certs.tmp"), 1,
|
||||||
sandbox_cfg_allow_open_filename(&cfg,
|
get_datadir_fname("cached-consensus"), 1,
|
||||||
get_datadir_fname("unverified-consensus"));
|
get_datadir_fname("unverified-consensus"), 1,
|
||||||
sandbox_cfg_allow_open_filename(&cfg,
|
get_datadir_fname("cached-microdesc-consensus"), 1,
|
||||||
get_datadir_fname("cached-microdesc-consensus"));
|
get_datadir_fname("cached-microdesc-consensus.tmp"), 1,
|
||||||
sandbox_cfg_allow_open_filename(&cfg,
|
get_datadir_fname("cached-microdescs"), 1,
|
||||||
get_datadir_fname("cached-microdesc-consensus.tmp"));
|
get_datadir_fname("cached-microdescs.tmp"), 1,
|
||||||
sandbox_cfg_allow_open_filename(&cfg, get_datadir_fname("cached-microdescs"));
|
get_datadir_fname("cached-microdescs.new"), 1,
|
||||||
sandbox_cfg_allow_open_filename(&cfg,
|
get_datadir_fname("cached-microdescs.new.tmp"), 1,
|
||||||
get_datadir_fname("cached-microdescs.tmp"));
|
get_datadir_fname("unverified-microdesc-consensus"), 1,
|
||||||
sandbox_cfg_allow_open_filename(&cfg,
|
get_datadir_fname("cached-descriptors"), 1,
|
||||||
get_datadir_fname("cached-microdescs.new"));
|
get_datadir_fname("cached-descriptors.new"), 1,
|
||||||
sandbox_cfg_allow_open_filename(&cfg,
|
get_datadir_fname("cached-descriptors.tmp"), 1,
|
||||||
get_datadir_fname("cached-microdescs.new.tmp"));
|
get_datadir_fname("cached-descriptors.new.tmp"), 1,
|
||||||
sandbox_cfg_allow_open_filename(&cfg,
|
get_datadir_fname("cached-descriptors.tmp.tmp"), 1,
|
||||||
get_datadir_fname("unverified-microdesc-consensus"));
|
get_datadir_fname("cached-extrainfo"), 1,
|
||||||
sandbox_cfg_allow_open_filename(&cfg,
|
get_datadir_fname("state.tmp"), 1,
|
||||||
get_datadir_fname("cached-descriptors"));
|
get_datadir_fname("unparseable-desc.tmp"), 1,
|
||||||
sandbox_cfg_allow_open_filename(&cfg,
|
get_datadir_fname("unparseable-desc"), 1,
|
||||||
get_datadir_fname("cached-descriptors.new"));
|
"/dev/srandom", 0,
|
||||||
sandbox_cfg_allow_open_filename(&cfg,
|
"/dev/urandom", 0
|
||||||
get_datadir_fname("cached-descriptors.tmp"));
|
);
|
||||||
sandbox_cfg_allow_open_filename(&cfg,
|
|
||||||
get_datadir_fname("cached-descriptors.new.tmp"));
|
|
||||||
sandbox_cfg_allow_open_filename(&cfg,
|
|
||||||
get_datadir_fname("cached-descriptors.tmp.tmp"));
|
|
||||||
sandbox_cfg_allow_open_filename(&cfg, get_datadir_fname("cached-extrainfo"));
|
|
||||||
sandbox_cfg_allow_open_filename(&cfg, get_datadir_fname("state.tmp"));
|
|
||||||
sandbox_cfg_allow_open_filename(&cfg,
|
|
||||||
get_datadir_fname("unparseable-desc.tmp"));
|
|
||||||
sandbox_cfg_allow_open_filename(&cfg, get_datadir_fname("unparseable-desc"));
|
|
||||||
|
|
||||||
// orport
|
// orport
|
||||||
if (server_mode(get_options())) {
|
if (server_mode(get_options())) {
|
||||||
sandbox_cfg_allow_open_filename(&cfg,
|
sandbox_cfg_allow_open_filename_array(&cfg, 13,
|
||||||
get_datadir_fname2("keys", "secret_id_key"));
|
get_datadir_fname2("keys", "secret_id_key"), 1,
|
||||||
sandbox_cfg_allow_open_filename(&cfg,
|
get_datadir_fname2("keys", "secret_onion_key"), 1,
|
||||||
get_datadir_fname2("keys", "secret_onion_key"));
|
get_datadir_fname2("keys", "secret_onion_key_ntor"), 1,
|
||||||
sandbox_cfg_allow_open_filename(&cfg,
|
get_datadir_fname2("keys", "secret_onion_key_ntor.tmp"), 1,
|
||||||
get_datadir_fname2("keys", "secret_onion_key_ntor"));
|
get_datadir_fname2("keys", "secret_id_key.old"), 1,
|
||||||
sandbox_cfg_allow_open_filename(&cfg,
|
get_datadir_fname2("keys", "secret_onion_key.old"), 1,
|
||||||
get_datadir_fname2("keys", "secret_onion_key_ntor.tmp"));
|
get_datadir_fname2("keys", "secret_onion_key_ntor.old"), 1,
|
||||||
sandbox_cfg_allow_open_filename(&cfg,
|
get_datadir_fname2("keys", "secret_onion_key.tmp"), 1,
|
||||||
get_datadir_fname2("keys", "secret_id_key.old"));
|
get_datadir_fname("fingerprint"), 1,
|
||||||
sandbox_cfg_allow_open_filename(&cfg,
|
get_datadir_fname("cached-consensus"), 1,
|
||||||
get_datadir_fname2("keys", "secret_onion_key.old"));
|
get_datadir_fname("cached-consensus.tmp"), 1,
|
||||||
sandbox_cfg_allow_open_filename(&cfg,
|
"/etc/resolv.conf", 0,
|
||||||
get_datadir_fname2("keys", "secret_onion_key_ntor.old"));
|
"/dev/random", 0
|
||||||
sandbox_cfg_allow_open_filename(&cfg,
|
);
|
||||||
get_datadir_fname2("keys", "secret_onion_key.tmp"));
|
|
||||||
|
|
||||||
sandbox_cfg_allow_open_filename(&cfg, get_datadir_fname("fingerprint"));
|
|
||||||
sandbox_cfg_allow_open_filename(&cfg,
|
|
||||||
get_datadir_fname("cached-consensus.tmp"));
|
|
||||||
sandbox_cfg_allow_open_filename(&cfg,
|
|
||||||
get_datadir_fname("cached-consensus"));
|
|
||||||
|
|
||||||
sandbox_cfg_allow_open_filename(&cfg, "/etc/resolv.conf");
|
|
||||||
sandbox_cfg_allow_open_filename(&cfg, "/dev/srandom");
|
|
||||||
sandbox_cfg_allow_open_filename(&cfg, "/dev/urandom");
|
|
||||||
sandbox_cfg_allow_open_filename(&cfg, "/dev/random");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sandbox_cfg_allow_execve(&cfg, "/usr/local/bin/tor");
|
sandbox_cfg_allow_execve(&cfg, "/usr/local/bin/tor");
|
||||||
|
Loading…
Reference in New Issue
Block a user