[compiler-rt] b0fdbad - [ubsan] warn inside the sigaction interceptor if static linking is suspected, and continue instead of crashing on null deref
Kostya Serebryany via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 1 12:37:23 PDT 2021
Author: Kostya Serebryany
Date: 2021-09-01T12:36:48-07:00
New Revision: b0fdbadf9f099e42bd2185ed32211b2d73cb2f58
URL: https://github.com/llvm/llvm-project/commit/b0fdbadf9f099e42bd2185ed32211b2d73cb2f58
DIFF: https://github.com/llvm/llvm-project/commit/b0fdbadf9f099e42bd2185ed32211b2d73cb2f58.diff
LOG: [ubsan] warn inside the sigaction interceptor if static linking is suspected, and continue instead of crashing on null deref
[ubsan] warn inside the sigaction interceptor if static linking is suspected, and continue instead of crashing on null deref
Reviewed By: kostik
Differential Revision: https://reviews.llvm.org/D109081
Added:
compiler-rt/test/ubsan/TestCases/Misc/Linux/static-link.cpp
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_signal_interceptors.inc
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_signal_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_signal_interceptors.inc
index cefb870f7e258..475e577d9982e 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_signal_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_signal_interceptors.inc
@@ -29,8 +29,16 @@ using namespace __sanitizer;
#endif
#ifndef SIGNAL_INTERCEPTOR_SIGACTION_IMPL
-#define SIGNAL_INTERCEPTOR_SIGACTION_IMPL(signum, act, oldact) \
- { return REAL(sigaction_symname)(signum, act, oldact); }
+# define SIGNAL_INTERCEPTOR_SIGACTION_IMPL(signum, act, oldact) \
+ { \
+ if (!REAL(sigaction_symname)) { \
+ Printf( \
+ "Warning: REAL(sigaction_symname) == nullptr. This may happen " \
+ "if you link with ubsan statically. Sigaction will not work.\n"); \
+ return -1; \
+ } \
+ return REAL(sigaction_symname)(signum, act, oldact); \
+ }
#endif
#if SANITIZER_INTERCEPT_BSD_SIGNAL
diff --git a/compiler-rt/test/ubsan/TestCases/Misc/Linux/static-link.cpp b/compiler-rt/test/ubsan/TestCases/Misc/Linux/static-link.cpp
new file mode 100644
index 0000000000000..6c6b421e40c6a
--- /dev/null
+++ b/compiler-rt/test/ubsan/TestCases/Misc/Linux/static-link.cpp
@@ -0,0 +1,13 @@
+// REQUIRES: ubsan-standalone
+// REQUIRES: arch=x86_64
+// RUN: %clangxx -fsanitize=bool -static %s -o %t && UBSAN_OPTIONS=handle_segv=0:handle_sigbus=0:handle_sigfpe=0 %run %t 2>&1 | FileCheck %s
+#include <signal.h>
+#include <stdio.h>
+
+int main() {
+ struct sigaction old_action;
+ sigaction(SIGINT, nullptr, &old_action);
+ // CHECK: Warning: REAL(sigaction_symname) == nullptr.
+ printf("PASS\n");
+ // CHECK: PASS
+}
More information about the llvm-commits
mailing list