[compiler-rt] [compiler-rt][rtsan] rename/renameat interception (PR #135884)

via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 15 16:54:02 PDT 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/135884.diff


2 Files Affected:

- (modified) compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp (+13) 
- (modified) compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp (+14) 


``````````diff
diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
index e8cea21ddf9aa..61fb7585e4bed 100644
--- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
@@ -295,6 +295,17 @@ INTERCEPTOR(int, unlinkat, int fd, const char *pathname, int flag) {
   return REAL(unlinkat)(fd, pathname, flag);
 }
 
+INTERCEPTOR(int, rename, const char *oldpath, const char *newpath) {
+  __rtsan_notify_intercepted_call("rename");
+  return REAL(rename)(oldpath, newpath);
+}
+
+INTERCEPTOR(int, renameat, int oldfd, const char *oldpath, int newfd,
+            const char *newpath) {
+  __rtsan_notify_intercepted_call("renameat");
+  return REAL(renameat)(oldfd, oldpath, newfd, newpath);
+}
+
 INTERCEPTOR(int, truncate, const char *pathname, off_t length) {
   __rtsan_notify_intercepted_call("truncate");
   return REAL(truncate)(pathname, length);
@@ -1534,6 +1545,8 @@ void __rtsan::InitializeInterceptors() {
   RTSAN_MAYBE_INTERCEPT_READLINKAT;
   INTERCEPT_FUNCTION(unlink);
   INTERCEPT_FUNCTION(unlinkat);
+  INTERCEPT_FUNCTION(rename);
+  INTERCEPT_FUNCTION(renameat);
   INTERCEPT_FUNCTION(symlink);
   INTERCEPT_FUNCTION(symlinkat);
   INTERCEPT_FUNCTION(truncate);
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 048da5858d665..885264a3a7c2e 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
@@ -885,6 +885,20 @@ TEST_F(RtsanOpenedFileTest, UnlinkatDiesWhenRealtime) {
   ExpectNonRealtimeSurvival(Func);
 }
 
+TEST_F(RtsanOpenedFileTest, RenameDiesWhenRealtime) {
+  auto Func = [&]() { rename(GetTemporaryFilePath(), "/tmp/rename_rtsan"); };
+  ExpectRealtimeDeath(Func, "rename");
+  ExpectNonRealtimeSurvival(Func);
+}
+
+TEST_F(RtsanOpenedFileTest, RenameatDiesWhenRealtime) {
+  auto Func = [&]() {
+    renameat(-1, GetTemporaryFilePath(), -1, "/tmp/renameat_rtsan");
+  };
+  ExpectRealtimeDeath(Func, "renameat");
+  ExpectNonRealtimeSurvival(Func);
+}
+
 TEST_F(RtsanOpenedFileTest, TruncateDiesWhenRealtime) {
   auto Func = [&]() { truncate(GetTemporaryFilePath(), 16); };
   ExpectRealtimeDeath(Func, MAYBE_APPEND_64("truncate"));

``````````

</details>


https://github.com/llvm/llvm-project/pull/135884


More information about the llvm-commits mailing list