Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,31 @@ INTERCEPTOR(int, execve, const char *filename, char *const argv[],
return REAL(execve)(filename, argv, envp);
}

#if SANITIZER_GLIBC
INTERCEPTOR(int, clone, int (*f)(void *), void *stack, int flags, void *arg,
...) {
__rtsan_notify_intercepted_call("clone");

if ((flags & CLONE_PIDFD) || (flags & CLONE_SETTLS) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch does not appear to be under test - is there any reason why that is difficult?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry just saw your comment now, will add something.

(flags & CLONE_PARENT_SETTID) || (flags & CLONE_CHILD_SETTID) ||
(flags & CLONE_CHILD_CLEARTID)) {
va_list args;
va_start(args, arg);
pid_t *parent = va_arg(args, pid_t *);
void *tls = va_arg(args, void *);
pid_t *child = va_arg(args, pid_t *);
va_end(args);

return REAL(clone)(f, stack, flags, arg, parent, tls, child);
}

return REAL(clone)(f, stack, flags, arg);
}
#define RTSAN_MAYBE_INTERCEPT_CLONE INTERCEPT_FUNCTION(clone)
#else
#define RTSAN_MAYBE_INTERCEPT_CLONE
#endif

#if SANITIZER_INTERCEPT_PROCESS_VM_READV
INTERCEPTOR(ssize_t, process_vm_readv, pid_t pid, const struct iovec *local_iov,
unsigned long liovcnt, const struct iovec *remote_iov,
Expand Down Expand Up @@ -1650,6 +1675,7 @@ void __rtsan::InitializeInterceptors() {

INTERCEPT_FUNCTION(fork);
INTERCEPT_FUNCTION(execve);
RTSAN_MAYBE_INTERCEPT_CLONE;

RTSAN_MAYBE_INTERCEPT_PROCESS_VM_READV;
RTSAN_MAYBE_INTERCEPT_PROCESS_VM_WRITEV;
Expand Down
29 changes: 29 additions & 0 deletions compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,35 @@ TEST_F(PthreadRwlockTest, PthreadRwlockWrlockSurvivesWhenNonRealtime) {
ExpectNonRealtimeSurvival(Func);
}

#if SANITIZER_GLIBC
TEST(TestRtsanInterceptors, CloneDiesWhenRealtime) {
std::vector<char> buf;
buf.resize(1024 * 1024);
auto Call = [](void *a) { return 0; };
auto Func = [&buf, &Call]() {
clone(Call, buf.data() + buf.size(), 0, nullptr);
};

ExpectRealtimeDeath(Func, "clone");
ExpectNonRealtimeSurvival(Func);
}

TEST(TestRtsanInterceptors, CloneWithTldDiesWhenRealtime) {
std::vector<char> buf;
pid_t pidfd;
void *tls = ::operator new(4096, std::align_val_t(16));
buf.resize(1024 * 1024);
auto Call = [](void *a) { return 0; };
auto Func = [&buf, &Call, &pidfd, &tls]() {
clone(Call, buf.data() + buf.size(), CLONE_PIDFD | CLONE_SETTLS, &pidfd,
tls, nullptr);
};

ExpectRealtimeDeath(Func, "clone");
ExpectNonRealtimeSurvival(Func);
}
#endif

/*
Sockets
*/
Expand Down