-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[compiler-rt][rtsan] chdir/fchdir interception. #125895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-compiler-rt-sanitizer Author: David CARLIER (devnexen) ChangesFull diff: https://github.com/llvm/llvm-project/pull/125895.diff 2 Files Affected:
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");
|
INTERCEPTOR(int, chroot, const char *path) { | ||
__rtsan_notify_intercepted_call("chroot"); | ||
return REAL(chroot)(path); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we separate out chroot? I think we should consider it separately considering it is a sudo only call.
The other two interceptors look great, and I will happily approve those. Just want to consider chroot separately considering it's system-wide effects
46c89e6
to
6c806ff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks!
No description provided.