Skip to content
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
41 changes: 41 additions & 0 deletions compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ void OSSpinLockLock(volatile OSSpinLock *__lock);
#include <pthread.h>
#include <stdarg.h>
#include <stdio.h>
#if SANITIZER_LINUX
#include <sys/inotify.h>
#endif
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -1130,6 +1133,39 @@ INTERCEPTOR(int, kevent64, int kq, const struct kevent64_s *changelist,
#define RTSAN_MAYBE_INTERCEPT_KEVENT64
#endif // SANITIZER_INTERCEPT_KQUEUE

#if SANITIZER_LINUX
INTERCEPTOR(int, inotify_init) {
__rtsan_notify_intercepted_call("inotify_init");
return REAL(inotify_init)();
}

INTERCEPTOR(int, inotify_init1, int flags) {
__rtsan_notify_intercepted_call("inotify_init1");
return REAL(inotify_init1)(flags);
}

INTERCEPTOR(int, inotify_add_watch, int fd, const char *path, uint32_t mask) {
__rtsan_notify_intercepted_call("inotify_add_watch");
return REAL(inotify_add_watch)(fd, path, mask);
}

INTERCEPTOR(int, inotify_rm_watch, int fd, int wd) {
__rtsan_notify_intercepted_call("inotify_rm_watch");
return REAL(inotify_rm_watch)(fd, wd);
}
#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 \
INTERCEPT_FUNCTION(inotify_add_watch)
#define RTSAN_MAYBE_INTERCEPT_INOTIFY_RM_WATCH \
INTERCEPT_FUNCTION(inotify_rm_watch)
#else
#define RTSAN_MAYBE_INTERCEPT_INOTIFY_INIT
#define RTSAN_MAYBE_INTERCEPT_INOTIFY_INIT1
#define RTSAN_MAYBE_INTERCEPT_INOTIFY_ADD_WATCH
#define RTSAN_MAYBE_INTERCEPT_INOTIFY_RM_WATCH
#endif

INTERCEPTOR(int, pipe, int pipefd[2]) {
__rtsan_notify_intercepted_call("pipe");
return REAL(pipe)(pipefd);
Expand Down Expand Up @@ -1367,6 +1403,11 @@ void __rtsan::InitializeInterceptors() {
RTSAN_MAYBE_INTERCEPT_KEVENT;
RTSAN_MAYBE_INTERCEPT_KEVENT64;

RTSAN_MAYBE_INTERCEPT_INOTIFY_INIT;
RTSAN_MAYBE_INTERCEPT_INOTIFY_INIT1;
RTSAN_MAYBE_INTERCEPT_INOTIFY_ADD_WATCH;
RTSAN_MAYBE_INTERCEPT_INOTIFY_RM_WATCH;

INTERCEPT_FUNCTION(pipe);
INTERCEPT_FUNCTION(mkfifo);

Expand Down
35 changes: 35 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 @@ -43,6 +43,9 @@
#include <poll.h>
#include <pthread.h>
#include <stdio.h>
#if SANITIZER_LINUX
#include <sys/inotify.h>
#endif
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/socket.h>
Expand Down Expand Up @@ -1481,6 +1484,38 @@ TEST_F(KqueueTest, Kevent64DiesWhenRealtime) {
}
#endif // SANITIZER_INTERCEPT_KQUEUE

#if SANITIZER_LINUX
TEST(TestRtsanInterceptors, InotifyInitDiesWhenRealtime) {
auto Func = []() { inotify_init(); };
ExpectRealtimeDeath(Func, "inotify_init");
ExpectNonRealtimeSurvival(Func);
}

TEST(TestRtsanInterceptors, InotifyInit1DiesWhenRealtime) {
auto Func = []() { inotify_init1(0); };
ExpectRealtimeDeath(Func, "inotify_init1");
ExpectNonRealtimeSurvival(Func);
}

TEST(TestRtsanInterceptors, InotifyAddWatchDiesWhenRealtime) {
int fd = inotify_init();
EXPECT_THAT(fd, Ne(-1));
auto Func = [fd]() {
inotify_add_watch(fd, "/tmp/rtsan_inotify", IN_CREATE);
};
ExpectRealtimeDeath(Func, "inotify_add_watch");
ExpectNonRealtimeSurvival(Func);
}

TEST(TestRtsanInterceptors, InotifyRmWatchDiesWhenRealtime) {
int fd = inotify_init();
EXPECT_THAT(fd, Ne(-1));
auto Func = [fd]() { inotify_rm_watch(fd, -1); };
ExpectRealtimeDeath(Func, "inotify_rm_watch");
ExpectNonRealtimeSurvival(Func);
}
#endif

TEST(TestRtsanInterceptors, MkfifoDiesWhenRealtime) {
auto Func = []() { mkfifo("/tmp/rtsan_test_fifo", 0); };
ExpectRealtimeDeath(Func, "mkfifo");
Expand Down
Loading