Skip to content

Commit fb77ca0

Browse files
committed
Re-land 'ASan: move allocator base to avoid conflict with high-entropy ASLR for x86-64 Linux'
D147984 was reverted because it broke lit tests on Mac. This revision is based on D147984 but maintains the old behavior for Apple. Note that, per the follow-up discussion with MaskRay in D147984, this patch excludes Apple but includes other platforms (e.g., aarch64, MIPS64) and OSes (e.g., FreeBSD, S390X), not just x86-64 Linux. Original commit message from D147984: Users have discovered [*] that when CONFIG_ARCH_MMAP_RND_BITS == 32, it will frequently conflict with ASan's allocator on x86-64 Linux, because the PIE program segment base address of 0x555555555554 plus an ASLR shift of up to ((2**32) * 4K == 0x100000000000) will sometimes exceed ASan's hardcoded base address of 0x600000000000. We fix this by simply moving the allocator base to 0x500000000000, which is below the PIE program segment base address. This is cleaner than trying to move it to another location that is sandwiched between the PIE program and library segments, because if either of those grow too large, it will collide with the allocator region. Note that we will never need to change this base address again (unless we want to increase the size of the allocator), because ASLR cannot be set above 32-bits for x86-64 Linux (the PIE program segment and library segments would collide with each other; see also ARCH_MMAP_RND_BITS_MAX in https://github.com/torvalds/linux/blob/master/arch/x86/Kconfig). [*] see https://b.corp.google.com/issues/276925478 and https://groups.google.com/a/google.com/g/chrome-os-gardeners/c/BbfzCP3dEeo/m/h3C_vVUxCQAJ Differential Revision: https://reviews.llvm.org/D148280
1 parent d43f088 commit fb77ca0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

compiler-rt/lib/asan/asan_allocator.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,15 @@ typedef DefaultSizeClassMap SizeClassMap;
143143
const uptr kAllocatorSpace = ~(uptr)0;
144144
const uptr kAllocatorSize = 0x8000000000ULL; // 500G
145145
typedef DefaultSizeClassMap SizeClassMap;
146-
# else
146+
# elif SANITIZER_APPLE
147147
const uptr kAllocatorSpace = 0x600000000000ULL;
148148
const uptr kAllocatorSize = 0x40000000000ULL; // 4T.
149149
typedef DefaultSizeClassMap SizeClassMap;
150-
# endif
150+
# else
151+
const uptr kAllocatorSpace = 0x500000000000ULL;
152+
const uptr kAllocatorSize = 0x40000000000ULL; // 4T.
153+
typedef DefaultSizeClassMap SizeClassMap;
154+
# endif
151155
template <typename AddressSpaceViewTy>
152156
struct AP64 { // Allocator64 parameters. Deliberately using a short name.
153157
static const uptr kSpaceBeg = kAllocatorSpace;

0 commit comments

Comments
 (0)