[compiler-rt] 939f290 - [compiler-rt][rtsan] getsockopt/setsockopt interception. (#124004)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 22 15:23:38 PST 2025
Author: David CARLIER
Date: 2025-01-22T23:23:32Z
New Revision: 939f2900d03c6ab0a89ba619ff25c8542bd11a5a
URL: https://github.com/llvm/llvm-project/commit/939f2900d03c6ab0a89ba619ff25c8542bd11a5a
DIFF: https://github.com/llvm/llvm-project/commit/939f2900d03c6ab0a89ba619ff25c8542bd11a5a.diff
LOG: [compiler-rt][rtsan] getsockopt/setsockopt interception. (#124004)
Added:
Modified:
compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
index a9812f90dec0799..a01354781272d5b 100644
--- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
@@ -1002,6 +1002,25 @@ INTERCEPTOR(int, accept4, int socket, struct sockaddr *address,
#define RTSAN_MAYBE_INTERCEPT_ACCEPT4
#endif
+#if SANITIZER_INTERCEPT_GETSOCKOPT
+INTERCEPTOR(int, getsockopt, int socket, int level, int option, void *value,
+ socklen_t *len) {
+ __rtsan_notify_intercepted_call("getsockopt");
+ return REAL(getsockopt)(socket, level, option, value, len);
+}
+
+INTERCEPTOR(int, setsockopt, int socket, int level, int option,
+ const void *value, socklen_t len) {
+ __rtsan_notify_intercepted_call("setsockopt");
+ return REAL(setsockopt)(socket, level, option, value, len);
+}
+#define RTSAN_MAYBE_INTERCEPT_GETSOCKOPT INTERCEPT_FUNCTION(getsockopt)
+#define RTSAN_MAYBE_INTERCEPT_SETSOCKOPT INTERCEPT_FUNCTION(setsockopt)
+#else
+#define RTSAN_MAYBE_INTERCEPT_GETSOCKOPT
+#define RTSAN_MAYBE_INTERCEPT_SETSOCKOPT
+#endif
+
// I/O Multiplexing
INTERCEPTOR(int, poll, struct pollfd *fds, nfds_t nfds, int timeout) {
@@ -1332,6 +1351,8 @@ void __rtsan::InitializeInterceptors() {
RTSAN_MAYBE_INTERCEPT_ACCEPT4;
RTSAN_MAYBE_INTERCEPT_GETSOCKNAME;
RTSAN_MAYBE_INTERCEPT_GETPEERNAME;
+ RTSAN_MAYBE_INTERCEPT_GETSOCKOPT;
+ RTSAN_MAYBE_INTERCEPT_SETSOCKOPT;
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 23b1728c7a45940..981766c85f965e4 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
@@ -1286,6 +1286,28 @@ TEST(TestRtsanInterceptors, GetpeernameOnASocketDiesWhenRealtime) {
}
#endif
+#if SANITIZER_INTERCEPT_GETSOCKOPT
+TEST(TestRtsanInterceptors, GetsockoptOnASocketDiesWhenRealtime) {
+ int val = 0;
+ socklen_t len = static_cast<socklen_t>(sizeof(val));
+ auto Func = [&val, &len]() {
+ getsockopt(0, SOL_SOCKET, SO_REUSEADDR, &val, &len);
+ };
+ ExpectRealtimeDeath(Func, "getsockopt");
+ ExpectNonRealtimeSurvival(Func);
+}
+
+TEST(TestRtsanInterceptors, SetsockoptOnASocketDiesWhenRealtime) {
+ int val = 0;
+ socklen_t len = static_cast<socklen_t>(sizeof(val));
+ auto Func = [&val, &len]() {
+ setsockopt(0, SOL_SOCKET, SO_REUSEADDR, &val, len);
+ };
+ ExpectRealtimeDeath(Func, "setsockopt");
+ ExpectNonRealtimeSurvival(Func);
+}
+#endif
+
/*
I/O Multiplexing
*/
More information about the llvm-commits
mailing list