Skip to content

Commit

Permalink
[Sanitizers] prctl interception update for the PR_SET_VMA option case.
Browse files Browse the repository at this point in the history
Supports on Android but also from Linux 5.17

Reviewers: vitalybuka, eugenis

Reviewed-By: vitalybuka

Differential Revision: https://reviews.llvm.org/D127326
  • Loading branch information
devnexen committed Jun 9, 2022
1 parent 11136a6 commit a4c97e1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Expand Up @@ -1367,8 +1367,13 @@ INTERCEPTOR(int, prctl, int option, unsigned long arg2, unsigned long arg3,
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, prctl, option, arg2, arg3, arg4, arg5);
static const int PR_SET_NAME = 15;
static const int PR_SET_VMA = 0x53564d41;
static const int PR_SCHED_CORE = 62;
static const int PR_SCHED_CORE_GET = 0;
if (option == PR_SET_VMA && arg2 == 0UL) {
char *name = (char *)arg5;
COMMON_INTERCEPTOR_READ_RANGE(ctx, name, internal_strlen(name) + 1);
}
int res = REAL(prctl(option, arg2, arg3, arg4, arg5));
if (option == PR_SET_NAME) {
char buff[16];
Expand Down
26 changes: 26 additions & 0 deletions compiler-rt/test/sanitizer_common/TestCases/Linux/prctl.cpp
Expand Up @@ -3,6 +3,7 @@
#include <assert.h>
#include <errno.h>
#include <stdint.h>
#include <sys/mman.h>
#include <sys/prctl.h>

#ifndef PR_SCHED_CORE
Expand All @@ -17,6 +18,11 @@
# define PR_SCHED_CORE_GET 0
#endif

#ifndef PR_SET_VMA
# define PR_SET_VMA 0x53564d41
# define PR_SET_VMA_ANON_NAME 0
#endif

int main() {

int res;
Expand All @@ -34,5 +40,25 @@ int main() {
assert(cookie != 0);
}

char invname[81], vlname[] = "prctl";
for (auto i = 0; i < sizeof(invname); i++) {
invname[i] = 0x1e;
}
invname[80] = 0;
auto p =
mmap(nullptr, 128, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
assert(p != MAP_FAILED);
// regardless of kernel support, the name is invalid
res = prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (uintptr_t)p, 128,
(uintptr_t)invname);
assert(res == -1);
assert(errno == EINVAL);
res = prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (uintptr_t)p, 128,
(uintptr_t)vlname);
if (res < 0) {
assert(errno == EINVAL);
}
munmap(p, 128);

return 0;
}

0 comments on commit a4c97e1

Please sign in to comment.