[compiler-rt] fd893bd - Fix sigaction interceptor to always correctly populate oldact

Matt Morehouse via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 12 10:12:35 PDT 2020


Author: Matt Morehouse
Date: 2020-08-12T10:11:56-07:00
New Revision: fd893bda5576d34dd987d7cfe517a05486cd38f4

URL: https://github.com/llvm/llvm-project/commit/fd893bda5576d34dd987d7cfe517a05486cd38f4
DIFF: https://github.com/llvm/llvm-project/commit/fd893bda5576d34dd987d7cfe517a05486cd38f4.diff

LOG: Fix sigaction interceptor to always correctly populate oldact

This fixes https://bugs.llvm.org/show_bug.cgi?id=47118. Before this change, when the sigaction interceptor prevented a signal from being changed, it also prevented the oldact output parameter from being written to. This resulted in a use-of-uninitialized-variable by any program that used sigaction for the purpose of reading signals.

This change fixes this: the regular sigaction implementation is still called, but with the act parameter nullified, preventing any changes.

Patch By: IanPudney

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D85797

Added: 
    compiler-rt/test/msan/interception_sigaction_test.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 68d9eb65968d..cefb870f7e25 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_signal_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_signal_interceptors.inc
@@ -53,7 +53,10 @@ INTERCEPTOR(uptr, signal, int signum, uptr handler) {
 
 INTERCEPTOR(int, sigaction_symname, int signum,
             const __sanitizer_sigaction *act, __sanitizer_sigaction *oldact) {
-  if (GetHandleSignalMode(signum) == kHandleSignalExclusive) return 0;
+  if (GetHandleSignalMode(signum) == kHandleSignalExclusive) {
+    if (!oldact) return 0;
+    act = nullptr;
+  }
   SIGNAL_INTERCEPTOR_SIGACTION_IMPL(signum, act, oldact);
 }
 #define INIT_SIGACTION COMMON_INTERCEPT_FUNCTION(sigaction_symname)

diff  --git a/compiler-rt/test/msan/interception_sigaction_test.cpp b/compiler-rt/test/msan/interception_sigaction_test.cpp
new file mode 100644
index 000000000000..282771923960
--- /dev/null
+++ b/compiler-rt/test/msan/interception_sigaction_test.cpp
@@ -0,0 +1,25 @@
+// RUN: %clangxx_msan -O0 -g %s -o %t
+// RUN: MSAN_OPTIONS=handle_segv=2 %t 2>&1 | FileCheck %s
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <signal.h>
+#include <string.h>
+
+extern "C" int __interceptor_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
+extern "C" int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) {
+  write(2, "sigaction call\n", sizeof("sigaction call\n") - 1);
+  return __interceptor_sigaction(signum, act, oldact);
+}
+
+int main() {
+  struct sigaction oldact;
+  sigaction(SIGSEGV, nullptr, &oldact);
+
+  if (oldact.sa_handler || oldact.sa_sigaction) {
+    fprintf(stderr, "oldact filled\n");
+  }
+  return 0;
+  // CHECK: sigaction call
+  // CHECK: oldact filled
+}


        


More information about the llvm-commits mailing list