diff options
author | Nick Mathewson <nickm@torproject.org> | 2019-10-22 12:13:47 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2019-10-22 12:13:47 -0400 |
commit | c1bf4260b69fa4de09471e31994b7fa242dce872 (patch) | |
tree | 2fc8de1b4657c598cf94d03e543349bbd96f7687 /src | |
parent | d4dde249a04c768381767f67a1a82425bc70baaa (diff) | |
parent | 749c2e1761c753992fb2549e7ee912e568f563d6 (diff) | |
download | tor-c1bf4260b69fa4de09471e31994b7fa242dce872.tar.gz tor-c1bf4260b69fa4de09471e31994b7fa242dce872.zip |
Merge remote-tracking branch 'tor-github/pr/1302' into maint-0.4.1
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/err/backtrace.c | 26 | ||||
-rw-r--r-- | src/lib/log/log.c | 5 | ||||
-rw-r--r-- | src/lib/sandbox/sandbox.c | 1 |
3 files changed, 28 insertions, 4 deletions
diff --git a/src/lib/err/backtrace.c b/src/lib/err/backtrace.c index e6cbe3d326..daf2dd7502 100644 --- a/src/lib/err/backtrace.c +++ b/src/lib/err/backtrace.c @@ -57,7 +57,8 @@ #include "lib/err/torerr.h" #if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && \ - defined(HAVE_BACKTRACE_SYMBOLS_FD) && defined(HAVE_SIGACTION) + defined(HAVE_BACKTRACE_SYMBOLS_FD) && defined(HAVE_SIGACTION) && \ + defined(HAVE_PTHREAD_H) #define USE_BACKTRACE #endif @@ -190,13 +191,15 @@ dump_stack_symbols_to_error_fds(void) backtrace_symbols_fd(cb_buf, (int)depth, fds[i]); } +/* The signals that we want our backtrace handler to trap */ +static int trap_signals[] = { SIGSEGV, SIGILL, SIGFPE, SIGBUS, SIGSYS, + SIGIO, -1 }; + /** Install signal handlers as needed so that when we crash, we produce a * useful stack trace. Return 0 on success, -errno on failure. */ static int install_bt_handler(const char *software) { - int trap_signals[] = { SIGSEGV, SIGILL, SIGFPE, SIGBUS, SIGSYS, - SIGIO, -1 }; int i, rv=0; strncpy(bt_version, software, sizeof(bt_version) - 1); @@ -235,6 +238,23 @@ install_bt_handler(const char *software) static void remove_bt_handler(void) { + int i; + + struct sigaction sa; + + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = SIG_DFL; + sigfillset(&sa.sa_mask); + + for (i = 0; trap_signals[i] >= 0; ++i) { + /* remove_bt_handler() is called on shutdown, from low-level code. + * It's not a fatal error, so we just ignore it. */ + (void)sigaction(trap_signals[i], &sa, NULL); + } + + /* cb_buf_mutex is statically initialised, so we can not destroy it. + * If we destroy it, and then re-initialise tor, all our backtraces will + * fail. */ } #endif /* defined(USE_BACKTRACE) */ diff --git a/src/lib/log/log.c b/src/lib/log/log.c index d95bf1ff6e..6667c26864 100644 --- a/src/lib/log/log.c +++ b/src/lib/log/log.c @@ -806,7 +806,10 @@ logs_free_all(void) } /* We _could_ destroy the log mutex here, but that would screw up any logs - * that happened between here and the end of execution. */ + * that happened between here and the end of execution. + * If tor is re-initialized, log_mutex_initialized will still be 1. So we + * won't trigger any undefined behaviour by trying to re-initialize the + * log mutex. */ } /** Remove and free the log entry <b>victim</b> from the linked-list diff --git a/src/lib/sandbox/sandbox.c b/src/lib/sandbox/sandbox.c index b652397f5a..faaf463f29 100644 --- a/src/lib/sandbox/sandbox.c +++ b/src/lib/sandbox/sandbox.c @@ -294,6 +294,7 @@ sb_rt_sigaction(scmp_filter_ctx ctx, sandbox_cfg_t *filter) unsigned i; int rc; int param[] = { SIGINT, SIGTERM, SIGPIPE, SIGUSR1, SIGUSR2, SIGHUP, SIGCHLD, + SIGSEGV, SIGILL, SIGFPE, SIGBUS, SIGSYS, SIGIO, #ifdef SIGXFSZ SIGXFSZ #endif |