[compiler-rt] fce917d - [rtsan] Add pipe, mkfifo interceptors (#116915)

via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 20 07:47:17 PST 2024


Author: Chris Apple
Date: 2024-11-20T07:47:14-08:00
New Revision: fce917d39d97b8697e04fc52b1727307fc341212

URL: https://github.com/llvm/llvm-project/commit/fce917d39d97b8697e04fc52b1727307fc341212
DIFF: https://github.com/llvm/llvm-project/commit/fce917d39d97b8697e04fc52b1727307fc341212.diff

LOG: [rtsan] Add pipe, mkfifo interceptors (#116915)

## Why we think this are unsafe

Again, these correspond directly to system calls on linux and OSX. They
are two ways to do interprocess communication so it would make sense
that they take some synchronization by the OS.

Added: 
    

Modified: 
    compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
    compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
index d18ebb57fc2f75..5ef52d72fceb31 100644
--- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
@@ -736,6 +736,26 @@ INTERCEPTOR(int, kevent64, int kq, const struct kevent64_s *changelist,
 #define RTSAN_MAYBE_INTERCEPT_KEVENT64
 #endif // SANITIZER_INTERCEPT_KQUEUE
 
+INTERCEPTOR(int, pipe, int pipefd[2]) {
+  __rtsan_notify_intercepted_call("pipe");
+  return REAL(pipe)(pipefd);
+}
+
+INTERCEPTOR(int, mkfifo, const char *pathname, mode_t mode) {
+  __rtsan_notify_intercepted_call("mkfifo");
+  return REAL(mkfifo)(pathname, mode);
+}
+
+// see comment above about -Wunguarded-availability-new
+// and why we disable it here
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunguarded-availability-new"
+INTERCEPTOR(int, mkfifoat, int dirfd, const char *pathname, mode_t mode) {
+  __rtsan_notify_intercepted_call("mkfifoat");
+  return REAL(mkfifoat)(dirfd, pathname, mode);
+}
+#pragma clang diagnostic pop
+
 // Preinit
 void __rtsan::InitializeInterceptors() {
   INTERCEPT_FUNCTION(calloc);
@@ -836,6 +856,10 @@ void __rtsan::InitializeInterceptors() {
   RTSAN_MAYBE_INTERCEPT_KQUEUE;
   RTSAN_MAYBE_INTERCEPT_KEVENT;
   RTSAN_MAYBE_INTERCEPT_KEVENT64;
+
+  INTERCEPT_FUNCTION(pipe);
+  INTERCEPT_FUNCTION(mkfifo);
+  INTERCEPT_FUNCTION(mkfifoat);
 }
 
 #endif // SANITIZER_POSIX

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 ab02b44187d89e..72f6d819b216c0 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
@@ -965,4 +965,32 @@ TEST_F(KqueueTest, Kevent64DiesWhenRealtime) {
 }
 #endif // SANITIZER_INTERCEPT_KQUEUE
 
+TEST(TestRtsanInterceptors, MkfifoDiesWhenRealtime) {
+  auto Func = []() { mkfifo("/tmp/rtsan_test_fifo", 0); };
+  ExpectRealtimeDeath(Func, "mkfifo");
+  ExpectNonRealtimeSurvival(Func);
+}
+
+#if __has_builtin(__builtin_available) && SANITIZER_APPLE
+#define MKFIFOAT_AVAILABLE() (__builtin_available(macOS 10.13, *))
+#else
+// We are going to assume this is true until we hit systems where it isn't
+#define MKFIFOAT_AVAILABLE() (true)
+#endif
+
+TEST(TestRtsanInterceptors, MkfifoatDiesWhenRealtime) {
+  if (MKFIFOAT_AVAILABLE()) {
+    auto Func = []() { mkfifoat(0, "/tmp/rtsan_test_fifo", 0); };
+    ExpectRealtimeDeath(Func, "mkfifoat");
+    ExpectNonRealtimeSurvival(Func);
+  }
+}
+
+TEST(TestRtsanInterceptors, PipeDiesWhenRealtime) {
+  int fds[2];
+  auto Func = [&fds]() { pipe(fds); };
+  ExpectRealtimeDeath(Func, "pipe");
+  ExpectNonRealtimeSurvival(Func);
+}
+
 #endif // SANITIZER_POSIX


        


More information about the llvm-commits mailing list