Skip to content

[compiler-rt][rtsan] Linux's eventfd interception. #132836

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
Apr 5, 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
9 changes: 9 additions & 0 deletions compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,12 @@ INTERCEPTOR(int, timerfd_gettime, int fd, struct itimerspec *val) {
__rtsan_notify_intercepted_call("timerfd_gettime");
return REAL(timerfd_gettime)(fd, val);
}

/* eventfd wrappers calls SYS_eventfd2 down the line */
INTERCEPTOR(int, eventfd, unsigned int count, int flags) {
__rtsan_notify_intercepted_call("eventfd");
return REAL(eventfd)(count, flags);
}
#define RTSAN_MAYBE_INTERCEPT_INOTIFY_INIT INTERCEPT_FUNCTION(inotify_init)
#define RTSAN_MAYBE_INTERCEPT_INOTIFY_INIT1 INTERCEPT_FUNCTION(inotify_init1)
#define RTSAN_MAYBE_INTERCEPT_INOTIFY_ADD_WATCH \
Expand All @@ -1370,6 +1376,7 @@ INTERCEPTOR(int, timerfd_gettime, int fd, struct itimerspec *val) {
INTERCEPT_FUNCTION(timerfd_settime)
#define RTSAN_MAYBE_INTERCEPT_TIMERFD_GETTIME \
INTERCEPT_FUNCTION(timerfd_gettime)
#define RTSAN_MAYBE_INTERCEPT_EVENTFD INTERCEPT_FUNCTION(eventfd)
#else
#define RTSAN_MAYBE_INTERCEPT_INOTIFY_INIT
#define RTSAN_MAYBE_INTERCEPT_INOTIFY_INIT1
Expand All @@ -1378,6 +1385,7 @@ INTERCEPTOR(int, timerfd_gettime, int fd, struct itimerspec *val) {
#define RTSAN_MAYBE_INTERCEPT_TIMERFD_CREATE
#define RTSAN_MAYBE_INTERCEPT_TIMERFD_SETTIME
#define RTSAN_MAYBE_INTERCEPT_TIMERFD_GETTIME
#define RTSAN_MAYBE_INTERCEPT_EVENTFD
#endif

INTERCEPTOR(int, pipe, int pipefd[2]) {
Expand Down Expand Up @@ -1644,6 +1652,7 @@ void __rtsan::InitializeInterceptors() {
RTSAN_MAYBE_INTERCEPT_TIMERFD_CREATE;
RTSAN_MAYBE_INTERCEPT_TIMERFD_SETTIME;
RTSAN_MAYBE_INTERCEPT_TIMERFD_GETTIME;
RTSAN_MAYBE_INTERCEPT_EVENTFD;

INTERCEPT_FUNCTION(pipe);
INTERCEPT_FUNCTION(mkfifo);
Expand Down
7 changes: 7 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 @@ -44,6 +44,7 @@
#include <pthread.h>
#include <stdio.h>
#if SANITIZER_LINUX
#include <sys/eventfd.h>
#include <sys/inotify.h>
#include <sys/timerfd.h>
#endif
Expand Down Expand Up @@ -1677,6 +1678,12 @@ TEST(TestRtsanInterceptors, TimerfdGettimeDiesWhenRealtime) {
ExpectRealtimeDeath(Func, "timerfd_gettime");
ExpectNonRealtimeSurvival(Func);
}

TEST(TestRtsanInterceptors, EventfdDiesWhenRealtime) {
auto Func = []() { eventfd(EFD_CLOEXEC, 0); };
ExpectRealtimeDeath(Func, "eventfd");
ExpectNonRealtimeSurvival(Func);
}
#endif

TEST(TestRtsanInterceptors, MkfifoDiesWhenRealtime) {
Expand Down