diff options
author | Nick Mathewson <nickm@torproject.org> | 2020-11-12 11:55:55 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2020-11-12 11:55:55 -0500 |
commit | dbc8d2a4e476c06f59db3ff79b66afc8bc4ea27c (patch) | |
tree | a121f0acd9193829ba57dbc3075495807f46e3ca /src/lib/sandbox | |
parent | e2d3c9c5f82a1369385dd99765c31ba479ba8f23 (diff) | |
download | tor-dbc8d2a4e476c06f59db3ff79b66afc8bc4ea27c.tar.gz tor-dbc8d2a4e476c06f59db3ff79b66afc8bc4ea27c.zip |
When handling includes, detect missing interned strings earlier.
There were three separate places where we were hitting a sandbox Bug
warning before we actually exited.
Fixes #40094; bugfix on 0.3.1.1-alpha when %includes were introduced.
Diffstat (limited to 'src/lib/sandbox')
-rw-r--r-- | src/lib/sandbox/sandbox.c | 37 | ||||
-rw-r--r-- | src/lib/sandbox/sandbox.h | 5 |
2 files changed, 36 insertions, 6 deletions
diff --git a/src/lib/sandbox/sandbox.c b/src/lib/sandbox/sandbox.c index 8d467c516e..d9ad8ec2c6 100644 --- a/src/lib/sandbox/sandbox.c +++ b/src/lib/sandbox/sandbox.c @@ -310,6 +310,8 @@ static int filter_nopar_gen[] = { #define seccomp_rule_add_4(ctx,act,call,f1,f2,f3,f4) \ seccomp_rule_add((ctx),(act),(call),4,(f1),(f2),(f3),(f4)) +static const char *sandbox_get_interned_string(const char *str); + /** * Function responsible for setting up the rt_sigaction syscall for * the seccomp filter sandbox. @@ -1224,9 +1226,40 @@ static sandbox_filter_func_t filter_func[] = { sb_kill }; +/** + * Return the interned (and hopefully sandbox-permitted) string equal + * to @a str. + */ const char * sandbox_intern_string(const char *str) { + const char *interned = sandbox_get_interned_string(str); + + if (sandbox_active && str != NULL && interned == NULL) { + log_warn(LD_BUG, "No interned sandbox parameter found for %s", str); + } + + return interned ? interned : str; +} + +/** + * Return true if the sandbox is running and we are missing an interned string + * equal to @a str. + */ +bool +sandbox_interned_string_is_missing(const char *str) +{ + return sandbox_active && sandbox_get_interned_string(str) == NULL; +} + +/** + * Try to find and return the interned string equal to @a str. + * + * If there is no such string, return NULL. + **/ +static const char * +sandbox_get_interned_string(const char *str) +{ sandbox_cfg_t *elem; if (str == NULL) @@ -1245,9 +1278,7 @@ sandbox_intern_string(const char *str) } } - if (sandbox_active) - log_warn(LD_BUG, "No interned sandbox parameter found for %s", str); - return str; + return NULL; } /* DOCDOC */ diff --git a/src/lib/sandbox/sandbox.h b/src/lib/sandbox/sandbox.h index a2b3227b90..eba99afbde 100644 --- a/src/lib/sandbox/sandbox.h +++ b/src/lib/sandbox/sandbox.h @@ -104,12 +104,11 @@ typedef struct { #endif /* defined(USE_LIBSECCOMP) */ #ifdef USE_LIBSECCOMP -/** Returns a registered protected string used with the sandbox, given that - * it matches the parameter. - */ const char* sandbox_intern_string(const char *param); +bool sandbox_interned_string_is_missing(const char *s); #else /* !defined(USE_LIBSECCOMP) */ #define sandbox_intern_string(s) (s) +#define sandbox_interned_string_is_missing(s) (false) #endif /* defined(USE_LIBSECCOMP) */ /** Creates an empty sandbox configuration file.*/ |