[compiler-rt] [compiler-rt][rtsan] getsockname interception. (PR #123409)
David CARLIER via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 17 14:18:38 PST 2025
https://github.com/devnexen updated https://github.com/llvm/llvm-project/pull/123409
>From 3859b0e9d30d15505a76394b430f5d59bcfc680e Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen at gmail.com>
Date: Fri, 17 Jan 2025 21:50:11 +0000
Subject: [PATCH] [compiler-rt][rtsan] getsockname interception.
---
compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp | 12 ++++++++++++
.../rtsan/tests/rtsan_test_interceptors_posix.cpp | 10 ++++++++++
2 files changed, 22 insertions(+)
diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
index e3f3d12d7e521b..7ab54c24a002f3 100644
--- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
@@ -829,6 +829,17 @@ INTERCEPTOR(int, getnameinfo, const struct sockaddr *sa, socklen_t salen,
return REAL(getnameinfo)(sa, salen, host, hostlen, serv, servlen, flags);
}
+#if SANITIZER_INTERCEPT_GETSOCKNAME
+INTERCEPTOR(int, getsockname, int socket, struct sockaddr *sa,
+ socklen_t *salen) {
+ __rtsan_notify_intercepted_call("getsockname");
+ return REAL(getsockname)(socket, sa, salen);
+}
+#define RTSAN_MAYBE_INTERCEPT_GETSOCKNAME INTERCEPT_FUNCTION(getsockname)
+#else
+#define RTSAN_MAYBE_INTERCEPT_GETSOCKNAME
+#endif
+
INTERCEPTOR(int, bind, int socket, const struct sockaddr *address,
socklen_t address_len) {
__rtsan_notify_intercepted_call("bind");
@@ -1189,6 +1200,7 @@ void __rtsan::InitializeInterceptors() {
INTERCEPT_FUNCTION(shutdown);
INTERCEPT_FUNCTION(socket);
RTSAN_MAYBE_INTERCEPT_ACCEPT4;
+ RTSAN_MAYBE_INTERCEPT_GETSOCKNAME;
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 c26643c6a2d630..0e03b19e80b6c5 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
@@ -1153,6 +1153,16 @@ TEST(TestRtsanInterceptors, ShutdownOnASocketDiesWhenRealtime) {
ExpectNonRealtimeSurvival(Func);
}
+#if SANITIZER_INTERCEPT_GETSOCKNAME
+TEST(TestRtsanInterceptors, GetsocknameOnASocketDiesWhenRealtime) {
+ sockaddr addr{};
+ socklen_t len{};
+ auto Func = [&]() { getsockname(0, &addr, &len); };
+ ExpectRealtimeDeath(Func, "getsockname");
+ ExpectNonRealtimeSurvival(Func);
+}
+#endif
+
/*
I/O Multiplexing
*/
More information about the llvm-commits
mailing list