Skip to content

Commit d46c26b

Browse files
authored
Fix prctl to handle PR_GET_PDEATHSIG. (#101749)
1 parent 967185e commit d46c26b

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,7 @@ INTERCEPTOR(int, prctl, int option, unsigned long arg2, unsigned long arg3,
12551255
static const int PR_SET_VMA = 0x53564d41;
12561256
static const int PR_SCHED_CORE = 62;
12571257
static const int PR_SCHED_CORE_GET = 0;
1258+
static const int PR_GET_PDEATHSIG = 2;
12581259
if (option == PR_SET_VMA && arg2 == 0UL) {
12591260
char *name = (char *)arg5;
12601261
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,
12701271
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, name, internal_strlen(name) + 1);
12711272
} else if (res != -1 && option == PR_SCHED_CORE &&
12721273
arg2 == PR_SCHED_CORE_GET) {
1273-
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, (u64*)(arg5), sizeof(u64));
1274+
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, (u64 *)(arg5), sizeof(u64));
1275+
} else if (res != -1 && option == PR_GET_PDEATHSIG) {
1276+
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, (u64 *)(arg2), sizeof(u64));
12741277
}
12751278
return res;
12761279
}
@@ -9980,7 +9983,7 @@ INTERCEPTOR(SSIZE_T, getrandom, void *buf, SIZE_T buflen, unsigned int flags) {
99809983
void *ctx;
99819984
COMMON_INTERCEPTOR_ENTER(ctx, getrandom, buf, buflen, flags);
99829985
// If GRND_NONBLOCK is set in the flags, it is non blocking.
9983-
static const int grnd_nonblock = 1;
9986+
static const int grnd_nonblock = 1;
99849987
SSIZE_T n;
99859988
if ((flags & grnd_nonblock))
99869989
n = REAL(getrandom)(buf, buflen, flags);

compiler-rt/test/sanitizer_common/TestCases/Linux/prctl.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ int main() {
4141
assert(cookie != 0);
4242
}
4343

44+
int signum;
45+
res = prctl(PR_GET_PDEATHSIG, reinterpret_cast<unsigned long>(&signum));
46+
if (res < 0) {
47+
assert(errno == EINVAL);
48+
} else {
49+
assert(signum == 0);
50+
}
51+
4452
char invname[81], vlname[] = "prctl";
4553
for (auto i = 0; i < sizeof(invname); i++) {
4654
invname[i] = 0x1e;

0 commit comments

Comments
 (0)