Skip to content

Commit a9b1e33

Browse files
committed
[compiler-rt][rtsan] prctl for Linux interception.
1 parent 9052b37 commit a9b1e33

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,32 @@ INTERCEPTOR(ssize_t, process_vm_writev, pid_t pid,
13191319
#define RTSAN_MAYBE_INTERCEPT_PROCESS_VM_WRITEV
13201320
#endif
13211321

1322+
#if SANITIZER_INTERCEPT_PRCTL
1323+
INTERCEPTOR(int, prctl, int operation, ...) {
1324+
__rtsan_notify_intercepted_call("prctl");
1325+
1326+
va_list args;
1327+
va_start(args, operation);
1328+
1329+
// in practice, prctl syscall accepts up to 4 additional arguments.
1330+
// With an operation like PR_SET_NAME however
1331+
// call does not have to set beyond the 2nd but
1332+
// it is good practice to set to NULL the rest.
1333+
using arg_type = unsigned long;
1334+
arg_type arg1 = va_arg(args, arg_type);
1335+
arg_type arg2 = va_arg(args, arg_type);
1336+
arg_type arg3 = va_arg(args, arg_type);
1337+
arg_type arg4 = va_arg(args, arg_type);
1338+
1339+
va_end(args);
1340+
1341+
return REAL(prctl)(operation, arg1, arg2, arg3, arg4);
1342+
}
1343+
#define RTSAN_MAYBE_INTERCEPT_PRCTL INTERCEPT_FUNCTION(prctl)
1344+
#else
1345+
#define RTSAN_MAYBE_INTERCEPT_PRCTL
1346+
#endif
1347+
13221348
// TODO: the `wait` family of functions is an oddity. In testing, if you
13231349
// intercept them, Darwin seemingly ignores them, and linux never returns from
13241350
// the test. Revisit this in the future, but hopefully intercepting fork/exec is
@@ -1520,6 +1546,7 @@ void __rtsan::InitializeInterceptors() {
15201546

15211547
RTSAN_MAYBE_INTERCEPT_PROCESS_VM_READV;
15221548
RTSAN_MAYBE_INTERCEPT_PROCESS_VM_WRITEV;
1549+
RTSAN_MAYBE_INTERCEPT_PRCTL;
15231550

15241551
INTERCEPT_FUNCTION(syscall);
15251552
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
#include <sys/time.h>
3737
#endif
3838

39+
#if SANITIZER_INTERCEPT_PRCTL
40+
#include <sys/prctl.h>
41+
#endif
42+
3943
#include <fcntl.h>
4044
#include <ifaddrs.h>
4145
#include <net/if.h>
@@ -781,6 +785,14 @@ TEST(TestRtsanInterceptors, ProcessVmWritevDiesWhenRealtime) {
781785
}
782786
#endif
783787

788+
#if SANITIZER_INTERCEPT_PRCTL
789+
TEST(TestRtsanInterceptors, PrctlDiesWhenRealtime) {
790+
auto Func = []() { prctl(PR_GET_DUMPABLE, 0, 0, 0, 0); };
791+
ExpectRealtimeDeath(Func, "prctl");
792+
ExpectNonRealtimeSurvival(Func);
793+
}
794+
#endif
795+
784796
class RtsanDirectoryTest : public ::testing::Test {
785797
protected:
786798
void SetUp() override {

0 commit comments

Comments
 (0)