-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[compiler-rt][rtsan] intercept getpeername/recvmmsg/sendmmsg #123484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-compiler-rt-sanitizer Author: David CARLIER (devnexen) ChangesFull diff: https://github.com/llvm/llvm-project/pull/123484.diff 2 Files Affected:
diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
index 7ab54c24a002f3..76e29a591c9934 100644
--- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
@@ -840,6 +840,17 @@ INTERCEPTOR(int, getsockname, int socket, struct sockaddr *sa,
#define RTSAN_MAYBE_INTERCEPT_GETSOCKNAME
#endif
+#if SANITIZER_INTERCEPT_GETPEERNAME
+INTERCEPTOR(int, getpeername, int socket, struct sockaddr *sa,
+ socklen_t *salen) {
+ __rtsan_notify_intercepted_call("getpeername");
+ return REAL(getpeername)(socket, sa, salen);
+}
+#define RTSAN_MAYBE_INTERCEPT_GETPEERNAME INTERCEPT_FUNCTION(getpeername)
+#else
+#define RTSAN_MAYBE_INTERCEPT_GETPEERNAME
+#endif
+
INTERCEPTOR(int, bind, int socket, const struct sockaddr *address,
socklen_t address_len) {
__rtsan_notify_intercepted_call("bind");
@@ -879,6 +890,17 @@ INTERCEPTOR(ssize_t, sendmsg, int socket, const struct msghdr *message,
return REAL(sendmsg)(socket, message, flags);
}
+#if SANITIZER_INTERCEPT_SENDMMSG
+INTERCEPTOR(int, sendmmsg, int socket, struct mmsghdr *message,
+ unsigned int len, int flags) {
+ __rtsan_notify_intercepted_call("sendmmsg");
+ return REAL(sendmmsg)(socket, message, len, flags);
+}
+#define RTSAN_MAYBE_INTERCEPT_SENDMMSG INTERCEPT_FUNCTION(sendmmsg)
+#else
+#define RTSAN_MAYBE_INTERCEPT_SENDMMSG
+#endif
+
INTERCEPTOR(ssize_t, sendto, int socket, const void *buffer, size_t length,
int flags, const struct sockaddr *dest_addr, socklen_t dest_len) {
__rtsan_notify_intercepted_call("sendto");
@@ -901,6 +923,17 @@ INTERCEPTOR(ssize_t, recvmsg, int socket, struct msghdr *message, int flags) {
return REAL(recvmsg)(socket, message, flags);
}
+#if SANITIZER_INTERCEPT_RECVMMSG
+INTERCEPTOR(int, recvmmsg, int socket, struct mmsghdr *message,
+ unsigned int len, int flags, struct timespec *timeout) {
+ __rtsan_notify_intercepted_call("recvmmsg");
+ return REAL(recvmmsg)(socket, message, len, flags, timeout);
+}
+#define RTSAN_MAYBE_INTERCEPT_RECVMMSG INTERCEPT_FUNCTION(recvmmsg)
+#else
+#define RTSAN_MAYBE_INTERCEPT_RECVMMSG
+#endif
+
INTERCEPTOR(int, shutdown, int socket, int how) {
__rtsan_notify_intercepted_call("shutdown");
return REAL(shutdown)(socket, how);
@@ -1194,13 +1227,16 @@ void __rtsan::InitializeInterceptors() {
INTERCEPT_FUNCTION(recv);
INTERCEPT_FUNCTION(recvfrom);
INTERCEPT_FUNCTION(recvmsg);
+ RTSAN_MAYBE_INTERCEPT_RECVMMSG;
INTERCEPT_FUNCTION(send);
INTERCEPT_FUNCTION(sendmsg);
+ RTSAN_MAYBE_INTERCEPT_SENDMMSG;
INTERCEPT_FUNCTION(sendto);
INTERCEPT_FUNCTION(shutdown);
INTERCEPT_FUNCTION(socket);
RTSAN_MAYBE_INTERCEPT_ACCEPT4;
RTSAN_MAYBE_INTERCEPT_GETSOCKNAME;
+ RTSAN_MAYBE_INTERCEPT_GETPEERNAME;
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 0e03b19e80b6c5..0ce1844f05eab0 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
@@ -1118,6 +1118,15 @@ TEST(TestRtsanInterceptors, SendmsgToASocketDiesWhenRealtime) {
ExpectNonRealtimeSurvival(Func);
}
+#if SANITIZER_INTERCEPT_SENDMMSG
+TEST(TestRtsanInterceptors, SendmmsgOnASocketDiesWhenRealtime) {
+ mmsghdr msg{};
+ auto Func = [&]() { sendmmsg(0, &msg, 0, 0); };
+ ExpectRealtimeDeath(Func, "sendmmsg");
+ ExpectNonRealtimeSurvival(Func);
+}
+#endif
+
TEST(TestRtsanInterceptors, SendtoToASocketDiesWhenRealtime) {
sockaddr addr{};
socklen_t len{};
@@ -1147,6 +1156,15 @@ TEST(TestRtsanInterceptors, RecvmsgOnASocketDiesWhenRealtime) {
ExpectNonRealtimeSurvival(Func);
}
+#if SANITIZER_INTERCEPT_RECVMMSG
+TEST(TestRtsanInterceptors, RecvmmsgOnASocketDiesWhenRealtime) {
+ mmsghdr msg{};
+ auto Func = [&]() { recvmmsg(0, &msg, 0, 0, nullptr); };
+ ExpectRealtimeDeath(Func, "recvmmsg");
+ ExpectNonRealtimeSurvival(Func);
+}
+#endif
+
TEST(TestRtsanInterceptors, ShutdownOnASocketDiesWhenRealtime) {
auto Func = [&]() { shutdown(0, 0); };
ExpectRealtimeDeath(Func, "shutdown");
@@ -1163,6 +1181,16 @@ TEST(TestRtsanInterceptors, GetsocknameOnASocketDiesWhenRealtime) {
}
#endif
+#if SANITIZER_INTERCEPT_GETPEERNAME
+TEST(TestRtsanInterceptors, GetpeernameOnASocketDiesWhenRealtime) {
+ sockaddr addr{};
+ socklen_t len{};
+ auto Func = [&]() { getpeername(0, &addr, &len); };
+ ExpectRealtimeDeath(Func, "getpeername");
+ ExpectNonRealtimeSurvival(Func);
+}
+#endif
+
/*
I/O Multiplexing
*/
|
It seems prior to glibc 2.21 (specifically bminor/glibc@20e5a5f),
|
Lovely ! Looking into it. |
linux/glibc prior to 2.21 had a different signature for recvmmsg.
This is still breaking our builders at https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8725110728072470801/+/u/clang/build/stdout?format=raw:
It looks like it's also due to a different signature. Could you send out a fix or revert? Thanks. |
|
linux/glibc prior to 2.21 had a different signature for recvmmsg. Fix llvm#123484
No description provided.