[compiler-rt] [compiler-rt][rtsan] signalfd interception for Linux. (PR #135491)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 12 05:17:34 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-compiler-rt-sanitizer
Author: David CARLIER (devnexen)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/135491.diff
2 Files Affected:
- (modified) compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp (+16)
- (modified) compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp (+11)
``````````diff
diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
index e8cea21ddf9aa..fa194c1132502 100644
--- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
@@ -1456,6 +1456,20 @@ INTERCEPTOR(ssize_t, process_vm_writev, pid_t pid,
#define RTSAN_MAYBE_INTERCEPT_PROCESS_VM_WRITEV
#endif
+// Signals
+
+#if SANITIZER_LINUX
+/* same as eventfd, signalfd calls SYS_signalfd4 to support the flags argument
+ */
+INTERCEPTOR(int, signalfd, const sigset_t *mask, int flags) {
+ __rtsan_notify_intercepted_call("signalfd");
+ return REAL(signalfd)(mask, flags);
+}
+#define RTSAN_MAYBE_INTERCEPT_SIGNALFD INTERCEPT_FUNCTION(signalfd)
+#else
+#define RTSAN_MAYBE_INTERCEPT_SIGNALFD
+#endif
+
// TODO: the `wait` family of functions is an oddity. In testing, if you
// intercept them, Darwin seemingly ignores them, and linux never returns from
// the test. Revisit this in the future, but hopefully intercepting fork/exec is
@@ -1676,6 +1690,8 @@ void __rtsan::InitializeInterceptors() {
RTSAN_MAYBE_INTERCEPT_PROCESS_VM_READV;
RTSAN_MAYBE_INTERCEPT_PROCESS_VM_WRITEV;
+ RTSAN_MAYBE_INTERCEPT_SIGNALFD;
+
INTERCEPT_FUNCTION(syscall);
}
diff --git a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
index 048da5858d665..31f0e58de7538 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
@@ -46,6 +46,7 @@
#if SANITIZER_LINUX
#include <sys/eventfd.h>
#include <sys/inotify.h>
+#include <sys/signalfd.h>
#include <sys/timerfd.h>
#endif
#include <sys/ioctl.h>
@@ -821,6 +822,16 @@ TEST(TestRtsanInterceptors, ProcessVmWritevDiesWhenRealtime) {
}
#endif
+#if SANITIZER_LINUX
+TEST(TestRtsanInterceptors, SignalfdDiesWhenRealtime) {
+ sigset_t set;
+ sigemptyset(&set);
+ auto Func = [&set]() { signalfd(-1, &set, 0); };
+ ExpectRealtimeDeath(Func, "signalfd");
+ ExpectNonRealtimeSurvival(Func);
+}
+#endif
+
class RtsanDirectoryTest : public ::testing::Test {
protected:
void SetUp() override {
``````````
</details>
https://github.com/llvm/llvm-project/pull/135491
More information about the llvm-commits
mailing list