[compiler-rt] [compiler-rt][rtsan] socketpair interception. (PR #124107)
David CARLIER via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 27 04:26:52 PST 2025
https://github.com/devnexen updated https://github.com/llvm/llvm-project/pull/124107
>From f3db8a83b3e32d4fc045f57e8c4164f74dd71683 Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen at gmail.com>
Date: Thu, 23 Jan 2025 12:22:35 +0000
Subject: [PATCH 1/2] [compiler-rt][rtsan] socketpair interception.
---
compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp | 11 +++++++++++
.../lib/rtsan/tests/rtsan_test_interceptors_posix.cpp | 9 +++++++++
2 files changed, 20 insertions(+)
diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
index a01354781272d5..bed58da73fef97 100644
--- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
@@ -1021,6 +1021,16 @@ INTERCEPTOR(int, setsockopt, int socket, int level, int option,
#define RTSAN_MAYBE_INTERCEPT_SETSOCKOPT
#endif
+#if !SANITIZER_APPLE
+INTERCEPTOR(int, socketpair, int domain, int type, int protocol, int pair[2]) {
+ __rtsan_notify_intercepted_call("socketpair");
+ return REAL(socketpair)(domain, type, protocol, pair);
+}
+#define RTSAN_MAYBE_INTERCEPT_SOCKETPAIR INTERCEPT_FUNCTION(socketpair)
+#else
+#define RTSAN_MAYBE_INTERCEPT_SOCKETPAIR
+#endif
+
// I/O Multiplexing
INTERCEPTOR(int, poll, struct pollfd *fds, nfds_t nfds, int timeout) {
@@ -1353,6 +1363,7 @@ void __rtsan::InitializeInterceptors() {
RTSAN_MAYBE_INTERCEPT_GETPEERNAME;
RTSAN_MAYBE_INTERCEPT_GETSOCKOPT;
RTSAN_MAYBE_INTERCEPT_SETSOCKOPT;
+ RTSAN_MAYBE_INTERCEPT_SOCKETPAIR;
RTSAN_MAYBE_INTERCEPT_SELECT;
INTERCEPT_FUNCTION(pselect);
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 981766c85f965e..c230b5debe5fa6 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
@@ -1308,6 +1308,15 @@ TEST(TestRtsanInterceptors, SetsockoptOnASocketDiesWhenRealtime) {
}
#endif
+#if !SANITIZER_APPLE
+TEST(TestRtsanInterceptors, SocketpairDiesWhenRealtime) {
+ int pair[2]{};
+ auto Func = [&pair]() { socketpair(0, 0, 0, pair); };
+ ExpectRealtimeDeath(Func, "socketpair");
+ ExpectNonRealtimeSurvival(Func);
+}
+#endif
+
/*
I/O Multiplexing
*/
>From c82f98a4c57f0f3cf2cbdffaee9396d6630c6357 Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen at gmail.com>
Date: Mon, 27 Jan 2025 12:26:39 +0000
Subject: [PATCH 2/2] enable for apple too
---
compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp | 7 +------
.../lib/rtsan/tests/rtsan_test_interceptors_posix.cpp | 2 --
2 files changed, 1 insertion(+), 8 deletions(-)
diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
index bed58da73fef97..75541f56148776 100644
--- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
@@ -1021,15 +1021,10 @@ INTERCEPTOR(int, setsockopt, int socket, int level, int option,
#define RTSAN_MAYBE_INTERCEPT_SETSOCKOPT
#endif
-#if !SANITIZER_APPLE
INTERCEPTOR(int, socketpair, int domain, int type, int protocol, int pair[2]) {
__rtsan_notify_intercepted_call("socketpair");
return REAL(socketpair)(domain, type, protocol, pair);
}
-#define RTSAN_MAYBE_INTERCEPT_SOCKETPAIR INTERCEPT_FUNCTION(socketpair)
-#else
-#define RTSAN_MAYBE_INTERCEPT_SOCKETPAIR
-#endif
// I/O Multiplexing
@@ -1363,7 +1358,7 @@ void __rtsan::InitializeInterceptors() {
RTSAN_MAYBE_INTERCEPT_GETPEERNAME;
RTSAN_MAYBE_INTERCEPT_GETSOCKOPT;
RTSAN_MAYBE_INTERCEPT_SETSOCKOPT;
- RTSAN_MAYBE_INTERCEPT_SOCKETPAIR;
+ INTERCEPT_FUNCTION(socketpair);
RTSAN_MAYBE_INTERCEPT_SELECT;
INTERCEPT_FUNCTION(pselect);
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 c230b5debe5fa6..bd54fd5dd2495a 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
@@ -1308,14 +1308,12 @@ TEST(TestRtsanInterceptors, SetsockoptOnASocketDiesWhenRealtime) {
}
#endif
-#if !SANITIZER_APPLE
TEST(TestRtsanInterceptors, SocketpairDiesWhenRealtime) {
int pair[2]{};
auto Func = [&pair]() { socketpair(0, 0, 0, pair); };
ExpectRealtimeDeath(Func, "socketpair");
ExpectNonRealtimeSurvival(Func);
}
-#endif
/*
I/O Multiplexing
More information about the llvm-commits
mailing list