Skip to content

Commit 6c9e098

Browse files
authored
[compiler-rt][rtsan] symlink/symlinkat interception. (#134168)
1 parent 75bbf76 commit 6c9e098

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,17 @@ INTERCEPTOR(int, ftruncate64, int fd, off64_t length) {
322322
#define RTSAN_MAYBE_INTERCEPT_FTRUNCATE64
323323
#endif
324324

325+
INTERCEPTOR(int, symlink, const char *target, const char *linkpath) {
326+
__rtsan_notify_intercepted_call("symlink");
327+
return REAL(symlink)(target, linkpath);
328+
}
329+
330+
INTERCEPTOR(int, symlinkat, const char *target, int newdirfd,
331+
const char *linkpath) {
332+
__rtsan_notify_intercepted_call("symlinkat");
333+
return REAL(symlinkat)(target, newdirfd, linkpath);
334+
}
335+
325336
// Streams
326337

327338
INTERCEPTOR(FILE *, fopen, const char *path, const char *mode) {
@@ -1523,6 +1534,8 @@ void __rtsan::InitializeInterceptors() {
15231534
RTSAN_MAYBE_INTERCEPT_READLINKAT;
15241535
INTERCEPT_FUNCTION(unlink);
15251536
INTERCEPT_FUNCTION(unlinkat);
1537+
INTERCEPT_FUNCTION(symlink);
1538+
INTERCEPT_FUNCTION(symlinkat);
15261539
INTERCEPT_FUNCTION(truncate);
15271540
INTERCEPT_FUNCTION(ftruncate);
15281541
RTSAN_MAYBE_INTERCEPT_TRUNCATE64;

compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,22 @@ TEST_F(RtsanOpenedFileTest, FtruncateDiesWhenRealtime) {
897897
ExpectNonRealtimeSurvival(Func);
898898
}
899899

900+
TEST_F(RtsanOpenedFileTest, SymlinkDiesWhenRealtime) {
901+
auto Func = [&]() {
902+
symlink("/tmp/rtsan_symlink_test", GetTemporaryFilePath());
903+
};
904+
ExpectRealtimeDeath(Func, "symlink");
905+
ExpectNonRealtimeSurvival(Func);
906+
}
907+
908+
TEST_F(RtsanOpenedFileTest, SymlinkatDiesWhenRealtime) {
909+
auto Func = [&]() {
910+
symlinkat("/tmp/rtsan_symlinkat_test", AT_FDCWD, GetTemporaryFilePath());
911+
};
912+
ExpectRealtimeDeath(Func, "symlinkat");
913+
ExpectNonRealtimeSurvival(Func);
914+
}
915+
900916
TEST_F(RtsanFileTest, FcloseDiesWhenRealtime) {
901917
FILE *f = fopen(GetTemporaryFilePath(), "w");
902918
EXPECT_THAT(f, Ne(nullptr));

0 commit comments

Comments
 (0)