[compiler-rt] 023f8b0 - [hwasan] Increase allocator space for non-android Linux

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 8 14:12:50 PST 2023


Author: Vitaly Buka
Date: 2023-03-08T14:12:39-08:00
New Revision: 023f8b08dbf8ca9cbe8842266106e8470d65af34

URL: https://github.com/llvm/llvm-project/commit/023f8b08dbf8ca9cbe8842266106e8470d65af34
DIFF: https://github.com/llvm/llvm-project/commit/023f8b08dbf8ca9cbe8842266106e8470d65af34.diff

LOG: [hwasan] Increase allocator space for non-android Linux

This is max acceptable value with pow of 2 for DefaultSizeClassMap, the
same as for ASAN.

Reviewed By: kstoimenov

Differential Revision: https://reviews.llvm.org/D145536

Added: 
    

Modified: 
    compiler-rt/lib/hwasan/hwasan_allocator.h
    compiler-rt/test/hwasan/TestCases/Linux/decorate-proc-maps.c
    compiler-rt/test/hwasan/TestCases/use-after-free.c

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/hwasan/hwasan_allocator.h b/compiler-rt/lib/hwasan/hwasan_allocator.h
index 67982cad25438..2093079413014 100644
--- a/compiler-rt/lib/hwasan/hwasan_allocator.h
+++ b/compiler-rt/lib/hwasan/hwasan_allocator.h
@@ -68,15 +68,21 @@ struct AP64 {
 
 #if defined(HWASAN_ALIASING_MODE)
   static const uptr kSpaceSize = 1ULL << kAddressTagShift;
+  typedef __sanitizer::DefaultSizeClassMap SizeClassMap;
+#elif SANITIZER_LINUX && !SANITIZER_ANDROID
+  static const uptr kSpaceSize = 0x40000000000ULL;  // 4T.
+  typedef __sanitizer::DefaultSizeClassMap SizeClassMap;
 #else
-  static const uptr kSpaceSize = 0x2000000000ULL;
+  static const uptr kSpaceSize = 0x2000000000ULL;  // 128G.
+  typedef __sanitizer::VeryDenseSizeClassMap SizeClassMap;
 #endif
+
   static const uptr kMetadataSize = sizeof(Metadata);
-  typedef __sanitizer::VeryDenseSizeClassMap SizeClassMap;
   using AddressSpaceView = LocalAddressSpaceView;
   typedef HwasanMapUnmapCallback MapUnmapCallback;
   static const uptr kFlags = 0;
 };
+
 typedef SizeClassAllocator64<AP64> PrimaryAllocator;
 typedef CombinedAllocator<PrimaryAllocator> Allocator;
 typedef Allocator::AllocatorCache AllocatorCache;

diff  --git a/compiler-rt/test/hwasan/TestCases/Linux/decorate-proc-maps.c b/compiler-rt/test/hwasan/TestCases/Linux/decorate-proc-maps.c
index 40e8c0ed8bb75..1c4e2e7c76d3b 100644
--- a/compiler-rt/test/hwasan/TestCases/Linux/decorate-proc-maps.c
+++ b/compiler-rt/test/hwasan/TestCases/Linux/decorate-proc-maps.c
@@ -48,7 +48,7 @@ void *ThreadFn(void *arg) {
 int main(void) {
   pthread_t t;
   void * volatile res = malloc(100);
-  void * volatile res2 = malloc(100000);
+  void * volatile res2 = malloc(1000000);
   pthread_create(&t, 0, ThreadFn, 0);
   pthread_join(t, 0);
   int ret_val = (int)(size_t)res;

diff  --git a/compiler-rt/test/hwasan/TestCases/use-after-free.c b/compiler-rt/test/hwasan/TestCases/use-after-free.c
index bd09bbf889df1..24546374341e3 100644
--- a/compiler-rt/test/hwasan/TestCases/use-after-free.c
+++ b/compiler-rt/test/hwasan/TestCases/use-after-free.c
@@ -27,7 +27,7 @@ int main() {
   // of the fault.
   // CHECK: in main {{.*}}use-after-free.c:[[@LINE-6]]
   // Offset is 5 or 11 depending on left/right alignment.
-  // CHECK: is a small unallocated heap chunk; size: 32 offset: {{5|11}}
+  // CHECK: is a small unallocated heap chunk; size: {{16|32}} offset: {{5|11}}
   // CHECK: Cause: use-after-free
   // CHECK: is located 5 bytes inside a 10-byte region
   //


        


More information about the llvm-commits mailing list