ASan requires that the min alignment be at least the shadow
granularity, so add an init function to do that.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc | ||
---|---|---|
185 ↗ | (On Diff #121052) | Why can't this be just a shadow granularity? |
compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc | ||
---|---|---|
185 ↗ | (On Diff #121052) | It can, but I was not clear on how to get that value -- |
maybe we need to set this to low level allocator during initialization?
@alekseyshl WDYT?
Why do we need this at all for internal allocator? It's internal to sanitizer and sanitizer code is not instrumented, that means no shadow.
Here is a typical backtrace. It seems that asan installs a callback to the internal allocator that poisons those memory.
#0 0xf7fd7c89 in kernel_vsyscall ()
#1 0xf7e3c627 in syscall () from /lib/i386-linux-gnu/libc.so.6
#2 0x0811c3cc in sanitizer::internal_sched_yield() () at /usr/local/google/home/waltl/Work/llvm-scale5/scale5/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc:401
#3 0x08062c75 in LockSlow () at /usr/local/google/home/waltl/Work/llvm-scale5/scale5/compiler-rt/lib/asan/../sanitizer_common/sanitizer_mutex.h:55
#4 0x08129696 in Lock () at /usr/local/google/home/waltl/Work/llvm-scale5/scale5/compiler-rt/lib/sanitizer_common/sanitizer_mutex.h:32
#5 GenericScopedLock () at /usr/local/google/home/waltl/Work/llvm-scale5/scale5/compiler-rt/lib/sanitizer_common/sanitizer_mutex.h:187
#6 GetOrInit () at /usr/local/google/home/waltl/Work/llvm-scale5/scale5/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc:21
#7 0x08128147 in Print () at /usr/local/google/home/waltl/Work/llvm-scale5/scale5/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc:35
#8 0x0810f31f in AsanCheckFailed () at /usr/local/google/home/waltl/Work/llvm-scale5/scale5/compiler-rt/lib/asan/asan_rtl.cc:69
#9 0x08124884 in CheckFailed () at /usr/local/google/home/waltl/Work/llvm-scale5/scale5/compiler-rt/lib/sanitizer_common/sanitizer_termination.cc:79
#10 0x08108b26 in PoisonShadow () at /usr/local/google/home/waltl/Work/llvm-scale5/scale5/compiler-rt/lib/asan/asan_poisoning.cc:38
#11 0x0810f355 in __asan::OnLowLevelAllocate(unsigned long, unsigned long) () at /usr/local/google/home/waltl/Work/llvm-scale5/scale5/compiler-rt/lib/asan/asan_rtl.cc:89
#12 0x0811328b in Allocate () at /usr/local/google/home/waltl/Work/llvm-scale5/scale5/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc:193
#13 0x0812b49a in operator new () at /usr/local/google/home/waltl/Work/llvm-scale5/scale5/compiler-rt/lib/sanitizer_common/sanitizer_common.h:937
#14 ChooseExternalSymbolizer () at /usr/local/google/home/waltl/Work/llvm-scale5/scale5/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc:486
#15 ChooseSymbolizerTools () at /usr/local/google/home/waltl/Work/llvm-scale5/scale5/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc:516
#16 PlatformInit () at /usr/local/google/home/waltl/Work/llvm-scale5/scale5/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc:529
#17 0x081296aa in GetOrInit () at /usr/local/google/home/waltl/Work/llvm-scale5/scale5/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc:24
#18 0x0812b635 in LateInitialize () at /usr/local/google/home/waltl/Work/llvm-scale5/scale5/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc:534
#19 0x0810ee62 in AsanInitInternal () at /usr/local/google/home/waltl/Work/llvm-scale5/scale5/compiler-rt/lib/asan/asan_rtl.cc:479
#20 0xf7fe8de4 in ?? () from /lib/ld-linux.so.2
#21 0xf7fd9a5f in ?? () from /lib/ld-linux.so.2
Ah, right, thanks!
Ok then, we need SetLowLevelAllocatorMinAlignment to complement SetLowLevelAllocateCallback, default it to 8 and call it from ASan to set it to shadow granularity.
compiler-rt/lib/asan/asan_rtl.cc | ||
---|---|---|
411 ↗ | (On Diff #123586) | Swap the Set.. calls, set the min alignment first. |
compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc | ||
210 ↗ | (On Diff #123586) | Did you really mean that alignment can only go up? How about this: constexpr uptr kLowLevelAllocatorDefaultAlignment = 8; |
compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc | ||
---|---|---|
210 ↗ | (On Diff #123586) | Done. Not sure if the final kLowLevelAllocatorDefaultAlignment is a typo, but I changed it to low_level_alloc_min_alignment so that if SetLowLevelAllocateMinAlignment is called multiple times, we get a max of all the input alignments. |