diff options
author | Nick Mathewson <nickm@torproject.org> | 2013-07-19 22:47:49 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2013-11-18 10:43:15 -0500 |
commit | bd8ad674b913582b6f8e5b85ac722e14598d681b (patch) | |
tree | 6833bbd938ce99a8d8c91bd8f6e53befdd149711 /src/common/sandbox.c | |
parent | b0023083c413c6447ef34cf3c6cfaf54a1cc8793 (diff) | |
download | tor-bd8ad674b913582b6f8e5b85ac722e14598d681b.tar.gz tor-bd8ad674b913582b6f8e5b85ac722e14598d681b.zip |
Add a sighandler-safe logging mechanism
We had accidentially grown two fake ones: one for backtrace.c, and one
for sandbox.c. Let's do this properly instead.
Now, when we configure logs, we keep track of fds that should get told
about bad stuff happening from signal handlers. There's another entry
point for these that avoids using non-signal-handler-safe functions.
Diffstat (limited to 'src/common/sandbox.c')
-rw-r--r-- | src/common/sandbox.c | 47 |
1 files changed, 7 insertions, 40 deletions
diff --git a/src/common/sandbox.c b/src/common/sandbox.c index dbb1657cdb..a37c74e4a3 100644 --- a/src/common/sandbox.c +++ b/src/common/sandbox.c @@ -184,16 +184,6 @@ install_glob_syscall_filter(void) return (rc < 0 ? -rc : rc); } -/** Additional file descriptor to use when logging seccomp2 failures */ -static int sigsys_debugging_fd = -1; - -/** Use the file descriptor <b>fd</b> to log seccomp2 failures. */ -static void -sigsys_set_debugging_fd(int fd) -{ - sigsys_debugging_fd = fd; -} - /** * 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 @@ -203,8 +193,8 @@ static void sigsys_debugging(int nr, siginfo_t *info, void *void_context) { ucontext_t *ctx = (ucontext_t *) (void_context); - char message[256]; - int rv = 0, syscall, length, err; + char number[32]; + int syscall; (void) nr; if (info->si_code != SYS_SECCOMP) @@ -215,24 +205,11 @@ sigsys_debugging(int nr, siginfo_t *info, void *void_context) syscall = ctx->uc_mcontext.gregs[REG_SYSCALL]; - strlcpy(message, "\n\n(Sandbox) Caught a bad syscall attempt (syscall 0x", - sizeof(message)); - (void) format_hex_number_sigsafe(syscall, message+strlen(message), - sizeof(message)-strlen(message)); - strlcat(message, ")\n", sizeof(message)); - length = strlen(message); - - err = 0; - if (sigsys_debugging_fd >= 0) { - rv = write(sigsys_debugging_fd, message, length); - err += rv != length; - } - - rv = write(STDOUT_FILENO, message, length); - err += rv != length; - - if (err) - _exit(2); + 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); @@ -318,14 +295,4 @@ tor_global_sandbox(void) #endif } -/** Use <b>fd</b> to log non-survivable sandbox violations. */ -void -sandbox_set_debugging_fd(int fd) -{ -#ifdef USE_LIBSECCOMP - sigsys_set_debugging_fd(fd); -#else - (void)fd; -#endif -} |