[Asan] Don't crash if metadata is not initialized
authorVitaly Buka <vitalybuka@google.com>
Tue, 1 Sep 2020 11:49:49 +0000 (04:49 -0700)
committerVitaly Buka <vitalybuka@google.com>
Tue, 8 Sep 2020 20:58:34 +0000 (13:58 -0700)
commitc05095cd6865a95ee848cd95d11643969a81a241
tree2b7b98cde8bc50f9b07d9fb3bb4434b834fbda6a
parent5c463d107d3c26fc5573f31b838a8a3a1e4b5065
[Asan] Don't crash if metadata is not initialized

Fixes https://github.com/google/sanitizers/issues/1193.

AsanChunk can be uninitialized yet just after return from the secondary
allocator. If lsan starts scan just before metadata assignment it can
fail to find corresponding AsanChunk.

It should be safe to ignore this and let lsan to assume that
AsanChunk is in the beginning of the block. This block is from the
secondary allocator and created with mmap, so it should not contain
any pointers and will make lsan to miss some leaks.

Similar already happens for primary allocator. If it can't find real
AsanChunk it falls back and assume that block starts with AsanChunk.
Then if the block is already returned to allocator we have  garbage in
AsanChunk and may scan dead memory hiding some leaks.
I'll fix this in D87135.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D86931
compiler-rt/lib/asan/asan_allocator.cpp
compiler-rt/test/asan/TestCases/lsan_crash.cpp [new file with mode: 0644]