/** Signal handler: write a crash message with a stack trace, and die. */ static void crash_handler(int sig, siginfo_t *si, void *ctx_) { char buf[40]; int depth; ucontext_t *ctx = (ucontext_t *) ctx_; int n_fds, i; const int *fds = NULL; (void) si; depth = backtrace(cb_buf, MAX_DEPTH); /* Clean up the top stack frame so we get the real function * name for the most recently failing function. */ clean_backtrace(cb_buf, depth, ctx); format_dec_number_sigsafe((unsigned)sig, buf, sizeof(buf)); tor_log_err_sigsafe(bt_version, " died: Caught signal ", buf, "\n", NULL); n_fds = tor_log_get_sigsafe_err_fds(&fds); for (i=0; i < n_fds; ++i) backtrace_symbols_fd(cb_buf, depth, fds[i]); abort(); }
/** * Function called when a SIGSYS is caught by the application. It notifies the * user that an error has occurred and either terminates or allows the * application to continue execution, based on the DEBUGGING_CLOSE symbol. */ static void sigsys_debugging(int nr, siginfo_t *info, void *void_context) { ucontext_t *ctx = (ucontext_t *) (void_context); char number[32]; int syscall; (void) nr; if (info->si_code != SYS_SECCOMP) return; if (!ctx) return; syscall = ctx->uc_mcontext.gregs[REG_SYSCALL]; format_dec_number_sigsafe(syscall, number, sizeof(number)); tor_log_err_sigsafe("(Sandbox) Caught a bad syscall attempt (syscall ", number, ")\n", NULL); #if defined(DEBUGGING_CLOSE) _exit(1); #endif // DEBUGGING_CLOSE }
static const char * get_syscall_name(int syscall_num) { int i; for (i = 0; SYSCALLS_BY_NUMBER[i].syscall_name; ++i) { if (SYSCALLS_BY_NUMBER[i].syscall_num == syscall_num) return SYSCALLS_BY_NUMBER[i].syscall_name; } { static char syscall_name_buf[64]; format_dec_number_sigsafe(syscall_num, syscall_name_buf, sizeof(syscall_name_buf)); return syscall_name_buf; } }
/** * Function called when a SIGSYS is caught by the application. It notifies the * user that an error has occurred and either terminates or allows the * application to continue execution, based on the DEBUGGING_CLOSE symbol. */ static void sigsys_debugging(int nr, siginfo_t *info, void *void_context) { ucontext_t *ctx = (ucontext_t *) (void_context); char number[32]; int syscall; #ifdef USE_BACKTRACE int depth; int n_fds, i; const int *fds = NULL; #endif (void) nr; if (info->si_code != SYS_SECCOMP) return; if (!ctx) return; syscall = (int) ctx->uc_mcontext.gregs[REG_SYSCALL]; #ifdef USE_BACKTRACE depth = backtrace(syscall_cb_buf, MAX_DEPTH); /* Clean up the top stack frame so we get the real function * name for the most recently failing function. */ clean_backtrace(syscall_cb_buf, depth, ctx); #endif format_dec_number_sigsafe(syscall, number, sizeof(number)); tor_log_err_sigsafe("(Sandbox) Caught a bad syscall attempt (syscall ", number, ")\n", NULL); #ifdef USE_BACKTRACE n_fds = tor_log_get_sigsafe_err_fds(&fds); for (i=0; i < n_fds; ++i) backtrace_symbols_fd(syscall_cb_buf, depth, fds[i]); #endif #if defined(DEBUGGING_CLOSE) _exit(1); #endif // DEBUGGING_CLOSE }