[compiler-rt] [rtsan] Add pipe, mkfifo interceptors (PR #116915)
Chris Apple via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 19 20:57:15 PST 2024
https://github.com/cjappl created https://github.com/llvm/llvm-project/pull/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.
>From 66b8eb05f8725aa1e508d4502382ce837b1be306 Mon Sep 17 00:00:00 2001
From: Chris Apple <cja-private at pm.me>
Date: Tue, 19 Nov 2024 10:27:20 -0800
Subject: [PATCH] [rtsan] Add pipe, mkfifo interceptors
---
.../lib/rtsan/rtsan_interceptors_posix.cpp | 24 ++++++++++++++++
.../tests/rtsan_test_interceptors_posix.cpp | 28 +++++++++++++++++++
2 files changed, 52 insertions(+)
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