[compiler-rt] [compiler-rt][rtsan] chdir/fchdir/chroot interception. (PR #125895)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 5 09:50:03 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-compiler-rt-sanitizer
Author: David CARLIER (devnexen)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/125895.diff
2 Files Affected:
- (modified) compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp (+19-2)
- (modified) compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp (+18)
``````````diff
diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
index 3ea9e54a046cf8..1adf8657bffe28 100644
--- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
@@ -244,6 +244,22 @@ INTERCEPTOR(int, close, int filedes) {
return REAL(close)(filedes);
}
+INTERCEPTOR(int, chdir, const char *path) {
+ __rtsan_notify_intercepted_call("chdir");
+ return REAL(chdir)(path);
+}
+
+INTERCEPTOR(int, fchdir, int fd) {
+ __rtsan_notify_intercepted_call("fchdir");
+ return REAL(fchdir)(fd);
+}
+
+INTERCEPTOR(int, chroot, const char *path) {
+ __rtsan_notify_intercepted_call("chroot");
+ return REAL(chroot)(path);
+}
+// Streams
+
INTERCEPTOR(FILE *, fopen, const char *path, const char *mode) {
__rtsan_notify_intercepted_call("fopen");
return REAL(fopen)(path, mode);
@@ -254,8 +270,6 @@ INTERCEPTOR(FILE *, freopen, const char *path, const char *mode, FILE *stream) {
return REAL(freopen)(path, mode, stream);
}
-// Streams
-
#if SANITIZER_INTERCEPT_FOPEN64
INTERCEPTOR(FILE *, fopen64, const char *path, const char *mode) {
__rtsan_notify_intercepted_call("fopen64");
@@ -1390,6 +1404,9 @@ void __rtsan::InitializeInterceptors() {
INTERCEPT_FUNCTION(openat);
RTSAN_MAYBE_INTERCEPT_OPENAT64;
INTERCEPT_FUNCTION(close);
+ INTERCEPT_FUNCTION(chdir);
+ INTERCEPT_FUNCTION(fchdir);
+ INTERCEPT_FUNCTION(chroot);
INTERCEPT_FUNCTION(fopen);
RTSAN_MAYBE_INTERCEPT_FOPEN64;
RTSAN_MAYBE_INTERCEPT_FREOPEN64;
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 e3688157a842c7..dba5e18e436a41 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
@@ -445,6 +445,24 @@ TEST(TestRtsanInterceptors, CloseDiesWhenRealtime) {
ExpectNonRealtimeSurvival(Func);
}
+TEST(TestRtsanInterceptors, ChdirDiesWhenRealtime) {
+ auto Func = []() { chdir("."); };
+ ExpectRealtimeDeath(Func, "chdir");
+ ExpectNonRealtimeSurvival(Func);
+}
+
+TEST(TestRtsanInterceptors, FchdirDiesWhenRealtime) {
+ auto Func = []() { fchdir(0); };
+ ExpectRealtimeDeath(Func, "fchdir");
+ ExpectNonRealtimeSurvival(Func);
+}
+
+TEST(TestRtsanInterceptors, ChrootDiesWhenRealtime) {
+ auto Func = []() { chroot("."); };
+ ExpectRealtimeDeath(Func, "chroot");
+ ExpectNonRealtimeSurvival(Func);
+}
+
TEST_F(RtsanFileTest, FopenDiesWhenRealtime) {
auto Func = [this]() {
FILE *f = fopen(GetTemporaryFilePath(), "w");
``````````
</details>
https://github.com/llvm/llvm-project/pull/125895
More information about the llvm-commits
mailing list