From c84f26184384ec543d91aabf8b01e95b2c518b74 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Wed, 5 Feb 2025 21:01:14 +0000 Subject: [PATCH] [compiler-rt][rtsan] chroot interception. --- compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp | 6 ++++++ .../lib/rtsan/tests/rtsan_test_interceptors_posix.cpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp index 83e6cdd4a0094..6d961d0d84e64 100644 --- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp +++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp @@ -254,6 +254,11 @@ INTERCEPTOR(int, fchdir, int fd) { 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) { @@ -1402,6 +1407,7 @@ void __rtsan::InitializeInterceptors() { 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 075f5974b7562..dba5e18e436a4 100644 --- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp +++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp @@ -457,6 +457,12 @@ TEST(TestRtsanInterceptors, FchdirDiesWhenRealtime) { 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");