[compiler-rt] [compiler-rt][rtsan] socketpair interception. (PR #124107)
David CARLIER via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 23 04:23:35 PST 2025
https://github.com/devnexen created https://github.com/llvm/llvm-project/pull/124107
None
>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] [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
*/
More information about the llvm-commits
mailing list