[compiler-rt] [compiler-rt][rtsan] socketpair interception. (PR #124107)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 23 04:24:05 PST 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/124107.diff
2 Files Affected:
- (modified) compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp (+11)
- (modified) compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp (+9)
``````````diff
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
*/
``````````
</details>
https://github.com/llvm/llvm-project/pull/124107
More information about the llvm-commits
mailing list