[compiler-rt] [sanitizer_common] Change allocator base in test case for compatibili… (PR #93234)
Thurston Dang via llvm-commits
llvm-commits at lists.llvm.org
Thu May 23 12:51:50 PDT 2024
https://github.com/thurstond created https://github.com/llvm/llvm-project/pull/93234
…ty with high-entropy ASLR
With high-entropy ASLR (e.g., 32-bits == 16TB), the allocator base of 0x700000000000 (112TB) may collide with the placement of the libraries (e.g., on Linux, the mmap base could be 128TB - 16TB). This results in a segfault in the test case.
This patch moves the allocator base below the PIE program segment, inspired by fb77ca05ffb4f8e666878f2f6718a9fb4d686839. As per that patch: 1) we are leaving the old behavior for Apple 2) since ASLR cannot be set above 32-bits for x86-64 Linux, we expect this new layout to be durable.
Note that this is only changing a test case, not the behavior of sanitizers. Sanitizers have their own settings for initializing the allocator base.
Reproducer:
1. ninja check-sanitizer # Just to build the test
2. for f in `seq 1 10000`; do echo $f; GTEST_FILTER=*SizeClassAllocator64Dense ./projects/compiler-rt/lib/sanitizer_common/tests/Sanitizer-x86_64-Test > /tmp/x; if [ $? -ne 0 ]; then cat /tmp/x; fi; done
>From 993cf5755343f228a2f1b4da7f94076e7f762683 Mon Sep 17 00:00:00 2001
From: Thurston Dang <thurston at google.com>
Date: Thu, 23 May 2024 19:46:59 +0000
Subject: [PATCH] [sanitizer_common] Change allocator base in test case for
compatibility with high-entropy ASLR
With high-entropy ASLR (e.g., 32-bits == 16TB), the allocator base of 0x700000000000 (112TB) may collide with the placement of the libraries (e.g., on Linux, the mmap base could be 128TB - 16TB). This results in a segfault in the test case.
This patch moves the allocator base below the PIE program segment, inspired by fb77ca05ffb4f8e666878f2f6718a9fb4d686839. As per that patch: 1) we are leaving the old behavior for Apple 2) since ASLR cannot be set above 32-bits for x86-64 Linux, we expect this new layout to be durable.
Note that this is only changing a test case, not the behavior of sanitizers. Sanitizers have their own settings for initializing the allocator base.
Reproducer:
1. ninja check-sanitizer # Just to build the test
2. for f in `seq 1 10000`; do echo $f; GTEST_FILTER=*SizeClassAllocator64Dense ./projects/compiler-rt/lib/sanitizer_common/tests/Sanitizer-x86_64-Test > /tmp/x; if [ $? -ne 0 ]; then cat /tmp/x; fi; done
---
.../sanitizer_common/tests/sanitizer_allocator_test.cpp | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp
index 58f2c8f7b3334..1a1ccce82d259 100644
--- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp
+++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp
@@ -69,12 +69,17 @@ const uptr kAllocatorSpace = ~(uptr)0;
const uptr kAllocatorSize = 0x2000000000ULL; // 128G.
static const u64 kAddressSpaceSize = 1ULL << 38;
typedef VeryDenseSizeClassMap SizeClassMap;
-#else
+# elif SANITIZER_APPLE
static const uptr kAllocatorSpace = 0x700000000000ULL;
static const uptr kAllocatorSize = 0x010000000000ULL; // 1T.
static const u64 kAddressSpaceSize = 1ULL << 47;
typedef DefaultSizeClassMap SizeClassMap;
-#endif
+# else
+static const uptr kAllocatorSpace = 0x500000000000ULL;
+static const uptr kAllocatorSize = 0x010000000000ULL; // 1T.
+static const u64 kAddressSpaceSize = 1ULL << 47;
+typedef DefaultSizeClassMap SizeClassMap;
+# endif
template <typename AddressSpaceViewTy>
struct AP64 { // Allocator Params. Short name for shorter demangled names..
More information about the llvm-commits
mailing list