[compiler-rt] 5ffe955 - [lsan] Move allocator base to avoid conflict with high-entropy ASLR for x86-64 Linux

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 14 10:18:59 PDT 2023


Author: Fangrui Song
Date: 2023-04-14T10:18:54-07:00
New Revision: 5ffe955570a5d743bbbae204ce1b132e89fa86dc

URL: https://github.com/llvm/llvm-project/commit/5ffe955570a5d743bbbae204ce1b132e89fa86dc
DIFF: https://github.com/llvm/llvm-project/commit/5ffe955570a5d743bbbae204ce1b132e89fa86dc.diff

LOG: [lsan] Move allocator base to avoid conflict with high-entropy ASLR for 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

Added: 
    

Modified: 
    compiler-rt/lib/lsan/lsan_allocator.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/lsan/lsan_allocator.h b/compiler-rt/lib/lsan/lsan_allocator.h
index b67d9d7750efc..10c1672ec5e33 100644
--- a/compiler-rt/lib/lsan/lsan_allocator.h
+++ b/compiler-rt/lib/lsan/lsan_allocator.h
@@ -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;


        


More information about the llvm-commits mailing list