Skip to content

[compiler-rt][rtsan] getsockname interception. #123409

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

Merged
merged 1 commit into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Loading