From bec32e9ac4f6b2a78b1ac5327467d27fbaddd7bb Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Fri, 10 Nov 2017 02:06:59 +0000 Subject: [PATCH] [msan] Deadly signal handler for msan Summary: Part of https://github.com/google/sanitizers/issues/637 Reviewers: eugenis, alekseyshl Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D39826 llvm-svn: 317864 --- compiler-rt/lib/msan/msan.cc | 11 ++++++++ compiler-rt/lib/msan/msan_interceptors.cc | 29 +++++++++++----------- .../sanitizer_common/TestCases/Linux/assert.cc | 1 - .../test/sanitizer_common/TestCases/Linux/ill.cc | 1 - .../TestCases/Posix/dedup_token_length_test.cc | 1 - .../TestCases/Posix/dump_instruction_bytes.cc | 1 - .../test/sanitizer_common/TestCases/Posix/fpe.cc | 1 - .../Posix/sanitizer_set_report_fd_test.cc | 1 - 8 files changed, 26 insertions(+), 20 deletions(-) diff --git a/compiler-rt/lib/msan/msan.cc b/compiler-rt/lib/msan/msan.cc index 3f85a9a..e6226ba 100644 --- a/compiler-rt/lib/msan/msan.cc +++ b/compiler-rt/lib/msan/msan.cc @@ -369,6 +369,16 @@ void __msan_warning_noreturn() { Die(); } +static void OnStackUnwind(const SignalContext &sig, const void *, + BufferedStackTrace *stack) { + GetStackTrace(stack, kStackTraceMax, sig.pc, sig.bp, sig.context, + common_flags()->fast_unwind_on_fatal); +} + +static void MsanOnDeadlySignal(int signo, void *siginfo, void *context) { + HandleDeadlySignal(siginfo, context, GetTid(), &OnStackUnwind, nullptr); +} + void __msan_init() { CHECK(!msan_init_is_running); if (msan_inited) return; @@ -384,6 +394,7 @@ void __msan_init() { __sanitizer_set_report_path(common_flags()->log_path); InitializeInterceptors(); + InstallDeadlySignalHandlers(MsanOnDeadlySignal); InstallAtExitHandler(); // Needs __cxa_atexit interceptor. DisableCoreDumperIfNecessary(); diff --git a/compiler-rt/lib/msan/msan_interceptors.cc b/compiler-rt/lib/msan/msan_interceptors.cc index feae876..f5822db 100644 --- a/compiler-rt/lib/msan/msan_interceptors.cc +++ b/compiler-rt/lib/msan/msan_interceptors.cc @@ -1006,20 +1006,6 @@ static void read_sigaction(const __sanitizer_sigaction *act) { CHECK_UNPOISONED(&act->sa_mask, sizeof(act->sa_mask)); } -static int sigaction_impl(int signo, const __sanitizer_sigaction *act, - __sanitizer_sigaction *oldact); -static uptr signal_impl(int signo, uptr cb); - -INTERCEPTOR(int, sigaction, int signo, const __sanitizer_sigaction *act, - __sanitizer_sigaction *oldact) { - return sigaction_impl(signo, act, oldact); -} - -INTERCEPTOR(int, signal, int signo, uptr cb) { - cb = signal_impl(signo, cb); - return REAL(signal)(signo, cb); -} - extern "C" int pthread_attr_init(void *attr); extern "C" int pthread_attr_destroy(void *attr); @@ -1275,6 +1261,20 @@ int OnExit() { #include "sanitizer_common/sanitizer_platform_interceptors.h" #include "sanitizer_common/sanitizer_common_interceptors.inc" +static uptr signal_impl(int signo, uptr cb); +static int sigaction_impl(int signo, const __sanitizer_sigaction *act, + __sanitizer_sigaction *oldact); + +#define SIGNAL_INTERCEPTOR_SIGACTION_IMPL(signo, act, oldact) \ + { return sigaction_impl(signo, act, oldact); } + +#define SIGNAL_INTERCEPTOR_SIGNAL_IMPL(func, signo, handler) \ + { \ + handler = signal_impl(signo, handler); \ + return REAL(func)(signo, handler); \ + } + +#include "sanitizer_common/sanitizer_signal_interceptors.inc" static int sigaction_impl(int signo, const __sanitizer_sigaction *act, __sanitizer_sigaction *oldact) { @@ -1490,6 +1490,7 @@ void InitializeInterceptors() { static int inited = 0; CHECK_EQ(inited, 0); InitializeCommonInterceptors(); + InitializeSignalInterceptors(); INTERCEPT_FUNCTION(mmap); MSAN_MAYBE_INTERCEPT_MMAP64; diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/assert.cc b/compiler-rt/test/sanitizer_common/TestCases/Linux/assert.cc index f10ddf3..76069f9 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Linux/assert.cc +++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/assert.cc @@ -8,7 +8,6 @@ // clang-format on // FIXME: implement in other sanitizers. -// XFAIL: msan // XFAIL: tsan #include diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/ill.cc b/compiler-rt/test/sanitizer_common/TestCases/Linux/ill.cc index 7d39abe..47a2783 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Linux/ill.cc +++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/ill.cc @@ -8,7 +8,6 @@ // clang-format on // FIXME: implement in other sanitizers. -// XFAIL: msan // XFAIL: tsan // XFAIL: ubsan // diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc b/compiler-rt/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc index 7e93af4..e1192c7 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc +++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc @@ -8,7 +8,6 @@ // REQUIRES: stable-runtime // FIXME: implement SEGV handler in other sanitizers. -// XFAIL: msan // XFAIL: tsan volatile int *null = 0; diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/dump_instruction_bytes.cc b/compiler-rt/test/sanitizer_common/TestCases/Posix/dump_instruction_bytes.cc index 25e801a..4e5dc6d 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Posix/dump_instruction_bytes.cc +++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/dump_instruction_bytes.cc @@ -9,7 +9,6 @@ // REQUIRES: x86-target-arch // FIXME: implement in other sanitizers. -// XFAIL: msan // XFAIL: tsan int main() { diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/fpe.cc b/compiler-rt/test/sanitizer_common/TestCases/Posix/fpe.cc index 46fe4f4..4f887b5 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Posix/fpe.cc +++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/fpe.cc @@ -4,7 +4,6 @@ // RUN: %env_tool_opts=handle_sigfpe=0 not --crash %run %t 2>&1 | FileCheck --check-prefix=CHECK0 %s // RUN: %env_tool_opts=handle_sigfpe=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK1 %s // FIXME: implement in other sanitizers, not just asan. -// XFAIL: msan // XFAIL: tsan // XFAIL: ubsan // diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc b/compiler-rt/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc index baa1d9a..9119010 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc +++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc @@ -7,7 +7,6 @@ // REQUIRES: stable-runtime // XFAIL: android && asan // FIXME: implement SEGV handler in other sanitizers, not just asan. -// XFAIL: msan // XFAIL: tsan #include -- 2.7.4