From b14573194572e6916e51c8e05f49b800883e9aea Mon Sep 17 00:00:00 2001 From: guzhihao4 Date: Thu, 27 Apr 2023 19:23:11 +0800 Subject: [PATCH] [Sanitizer] Fix sanitizer prctl implemention User can set name to NULL to clear vma through prctl, sanitizer should skip the check of name when it is empty. Issue: #I6ZGF6 Signed-off-by: guzhihao4 Change-Id: I629b24057b2e1d3b2c60e52302d9115d07b7b361 --- .../lib/sanitizer_common/sanitizer_common_interceptors.inc | 4 +++- compiler-rt/test/sanitizer_common/TestCases/Linux/prctl.cpp | 6 ++++++ 2 files changed, 9 insertions(+), 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 507c181f0526..4ecd2ab000b0 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -1370,7 +1370,9 @@ 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; - if (option == PR_SET_VMA && arg2 == 0UL) { + // OHOS_LOCAL + // The arg5 can be nullptr here, skip this check if so. + if (option == PR_SET_VMA && arg2 == 0UL && arg5) { char *name = (char *)arg5; COMMON_INTERCEPTOR_READ_RANGE(ctx, name, internal_strlen(name) + 1); } diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/prctl.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/prctl.cpp index 581739500e7a..c02acdb380e2 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Linux/prctl.cpp +++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/prctl.cpp @@ -58,6 +58,12 @@ int main() { if (res < 0) { assert(errno == EINVAL); } + + res = prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (uintptr_t)p, 128, NULL); + if (res < 0) { + assert(errno == EINVAL); + } + munmap(p, 128); return 0; -- Gitee