roymuste / address-sanitizer

Automatically exported from code.google.com/p/address-sanitizer
0 stars 0 forks source link

Miscalculation of ByteMap kSize1 for small mmap ranges on iOS/AArch64 #265

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
In sanitizer_allocator_internal.h, the computed kSize1 template parameter used 
in the typedef of ByteMap can be zero if SANITIZER_MMAP_RANGE_SIZE is not at 
least 64 GB. This causes the map1_ array to be of length 0.

Note that the same typedef in asan_allocator2.cc requires only a minimum of 4 
GB due to a different value of kRegionSizeLog.

Original issue reported on code.google.com by rgovostes on 20 Feb 2014 at 12:56

GoogleCodeExporter commented 9 years ago
Do I understand correctly that on AArch64/iOS SANITIZER_MMAP_RANGE_SIZE is 2Gb?
So both definitions are incorrect for that platform, right?

Original comment by konstant...@gmail.com on 24 Feb 2014 at 2:10

GoogleCodeExporter commented 9 years ago
Should SANITIZER_MMAP_RANGE_SIZE be defined as the upper bound of allocatable 
memory, or the difference between the upper and lower bound? I don't remember a 
comment in the code defining it.

For the former, it is 6.5 GB, and the latter, it is 2.5 GB.

Original comment by rgovostes on 24 Feb 2014 at 8:54

GoogleCodeExporter commented 9 years ago
So, on iOS/AArch64 a user program can map addresses between 4G and 6.5Gb, right?
Since this is so small, I suggest you to use FlatByteMap:

--- lib/sanitizer_common/sanitizer_allocator_internal.h (revision 202117)
+++ lib/sanitizer_common/sanitizer_allocator_internal.h (working copy)
@@ -25,7 +25,7 @@

 static const uptr kInternalAllocatorSpace = 0;
 static const u64 kInternalAllocatorSize = SANITIZER_MMAP_RANGE_SIZE;
-#if SANITIZER_WORDSIZE == 32
+#if SANITIZER_MMAP_RANGE_SIZE < (1ULL << 36)
 static const uptr kInternalAllocatorRegionSizeLog = 20;
 static const uptr kInternalAllocatorNumRegions =
     kInternalAllocatorSize >> kInternalAllocatorRegionSizeLog;

(You'll need to define SANITIZER_MMAP_RANGE_SIZE to 6.5Gb)

iOS/AArch64 is the first platform for asan where the mmap range does not start 
around zero, 
so SANITIZER_MMAP_RANGE_SIZE is supposed to be the upper bound of that range.
Anyway, this does not matter much if we use FlatByteMap.

If at some point we face a platform which has a small mmap range that starts at 
huge address
(e.g. 2Gb starting at 40Tb), we'll need some refactoring. But not today. 

Original comment by konstant...@gmail.com on 25 Feb 2014 at 10:56

GoogleCodeExporter commented 9 years ago

Original comment by ramosian.glider@gmail.com on 30 Jul 2015 at 9:05

GoogleCodeExporter commented 9 years ago
Adding Project:AddressSanitizer as part of GitHub migration.

Original comment by ramosian.glider@gmail.com on 30 Jul 2015 at 9:06