[compiler-rt] Reapply "Fix prctl to handle PR_GET_PDEATHSIG. (#101749)" (PR #104469)
Kirill Stoimenov via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 15 09:39:07 PDT 2024
https://github.com/kstoimenov updated https://github.com/llvm/llvm-project/pull/104469
>From 557ccfd2c924a167c3c6f55fe4e8453770cf1f29 Mon Sep 17 00:00:00 2001
From: Kirill Stoimenov <kstoimenov at google.com>
Date: Thu, 15 Aug 2024 16:35:50 +0000
Subject: [PATCH 1/2] Reapply "Fix prctl to handle PR_GET_PDEATHSIG. (#101749)"
Reapply with a fix.
This reverts commit 046524e8fe425cbc86c3371f2bf29fbb39d98435.
---
.../sanitizer_common/sanitizer_common_interceptors.inc | 7 +++++--
.../test/sanitizer_common/TestCases/Linux/prctl.cpp | 8 ++++++++
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 49c9dcbef358ff..0fa491a9641a6c 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -1255,6 +1255,7 @@ INTERCEPTOR(int, prctl, int option, unsigned long arg2, unsigned long arg3,
static const int PR_SET_VMA = 0x53564d41;
static const int PR_SCHED_CORE = 62;
static const int PR_SCHED_CORE_GET = 0;
+ static const int PR_GET_PDEATHSIG = 2;
if (option == PR_SET_VMA && arg2 == 0UL) {
char *name = (char *)arg5;
COMMON_INTERCEPTOR_READ_RANGE(ctx, name, internal_strlen(name) + 1);
@@ -1270,7 +1271,9 @@ INTERCEPTOR(int, prctl, int option, unsigned long arg2, unsigned long arg3,
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, name, internal_strlen(name) + 1);
} else if (res != -1 && option == PR_SCHED_CORE &&
arg2 == PR_SCHED_CORE_GET) {
- COMMON_INTERCEPTOR_WRITE_RANGE(ctx, (u64*)(arg5), sizeof(u64));
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, (u64 *)(arg5), sizeof(u64));
+ } else if (res != -1 && option == PR_GET_PDEATHSIG) {
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, (u64 *)(arg2), sizeof(u64));
}
return res;
}
@@ -9980,7 +9983,7 @@ INTERCEPTOR(SSIZE_T, getrandom, void *buf, SIZE_T buflen, unsigned int flags) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, getrandom, buf, buflen, flags);
// If GRND_NONBLOCK is set in the flags, it is non blocking.
- static const int grnd_nonblock = 1;
+ static const int grnd_nonblock = 1;
SSIZE_T n;
if ((flags & grnd_nonblock))
n = REAL(getrandom)(buf, buflen, flags);
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/prctl.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/prctl.cpp
index d0be7f4fa87899..cbff02d66efa78 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Linux/prctl.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/prctl.cpp
@@ -41,6 +41,14 @@ int main() {
}
}
+ int signum;
+ res = prctl(PR_GET_PDEATHSIG, reinterpret_cast<unsigned long>(&signum));
+ if (res < 0) {
+ assert(errno == EINVAL);
+ } else {
+ assert(signum == 0);
+ }
+
char invname[81], vlname[] = "prctl";
for (auto i = 0; i < sizeof(invname); i++) {
invname[i] = 0x1e;
>From 3868ea10e46f25d2eff2b57c04f3842d5836f5ae Mon Sep 17 00:00:00 2001
From: Kirill Stoimenov <kstoimenov at google.com>
Date: Thu, 15 Aug 2024 16:38:39 +0000
Subject: [PATCH 2/2] Fix the type.
---
.../lib/sanitizer_common/sanitizer_common_interceptors.inc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 0fa491a9641a6c..e09a4a8ae25fd8 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -1273,7 +1273,7 @@ INTERCEPTOR(int, prctl, int option, unsigned long arg2, unsigned long arg3,
arg2 == PR_SCHED_CORE_GET) {
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, (u64 *)(arg5), sizeof(u64));
} else if (res != -1 && option == PR_GET_PDEATHSIG) {
- COMMON_INTERCEPTOR_WRITE_RANGE(ctx, (u64 *)(arg2), sizeof(u64));
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, (u64 *)(arg2), sizeof(int));
}
return res;
}
More information about the llvm-commits
mailing list