Skip to content

Commit

Permalink
[lsan] Move allocator base to avoid conflict with high-entropy ASLR f…
Browse files Browse the repository at this point in the history
…or x86-64 Linux

This ports D148280 for ASan.

On x86-64 Linux, when mmap_rnd_bits is set to 32 (the maximum `ARCH_MMAP_RND_BITS_MAX`),
the allocator space `[kAllocatorSpace,kAllocatorSpace+kAllocatorSize)`
collides with the PIE load base range (0x555555554000 upto `2**mmap_rnd_bits * pagesize` away),
which can cause the allocation to fail.
Using 0x500000000000ULL as the base address avoids this problem and works with
AArch64 Linux and FreeBSD as well.

While here, change s390x to use 0x500000000000ULL as well. See D78644
discussions that the address works.

Reviewed By: thurston, vitalybuka

Differential Revision: https://reviews.llvm.org/D148193
  • Loading branch information
MaskRay committed Apr 14, 2023
1 parent 5b386b8 commit 5ffe955
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions compiler-rt/lib/lsan/lsan_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ using PrimaryAllocator = PrimaryAllocatorASVT<LocalAddressSpaceView>;
# if SANITIZER_FUCHSIA || defined(__powerpc64__)
const uptr kAllocatorSpace = ~(uptr)0;
const uptr kAllocatorSize = 0x40000000000ULL; // 4T.
#elif defined(__s390x__)
const uptr kAllocatorSpace = 0x40000000000ULL;
const uptr kAllocatorSize = 0x40000000000ULL; // 4T.
# else
# elif SANITIZER_APPLE
const uptr kAllocatorSpace = 0x600000000000ULL;
const uptr kAllocatorSize = 0x40000000000ULL; // 4T.
# endif
# else
const uptr kAllocatorSpace = 0x500000000000ULL;
const uptr kAllocatorSize = 0x40000000000ULL; // 4T.
# endif
template <typename AddressSpaceViewTy>
struct AP64 { // Allocator64 parameters. Deliberately using a short name.
static const uptr kSpaceBeg = kAllocatorSpace;
Expand Down

0 comments on commit 5ffe955

Please sign in to comment.