llvm-project/compiler-rt/lib/scudo
Kostya Kortchinsky 040c211bc4 [scudo] Fix improper TSD init after TLS destructors are called
Summary:
Some of glibc's own thread local data is destroyed after a user's thread local
destructors are called, via __libc_thread_freeres. This might involve calling
free, as is the case for strerror_thread_freeres.
If there is no prior heap operation in the thread, this free would end up
initializing some thread specific data that would never be destroyed properly
(as user's pthread destructors have already been called), while still being
deallocated when the TLS goes away. As a result, a program could SEGV, usually
in __sanitizer::AllocatorGlobalStats::Unregister, where one of the doubly linked
list links would refer to a now unmapped memory area.

To prevent this from happening, we will not do a full initialization from the
deallocation path. This means that the fallback cache & quarantine will be used
if no other heap operation has been called, and we effectively prevent the TSD
being initialized and never destroyed. The TSD will be fully initialized for all
other paths.

In the event of a thread doing only frees and nothing else, a TSD would never
be initialized for that thread, but this situation is unlikely and we can live
with that.

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 312939
2017-09-11 19:59:40 +00:00
..
CMakeLists.txt [scudo] Add Android support 2017-05-05 21:38:22 +00:00
scudo_allocator.cpp [scudo] Fix improper TSD init after TLS destructors are called 2017-09-11 19:59:40 +00:00
scudo_allocator.h [sanitizer] Re-introduce kUseSeparateSizeClassForBatch for the 32-bit Primary 2017-08-28 15:20:02 +00:00
scudo_allocator_combined.h [scudo] Do not grab a cache for secondary allocation & per related changes 2017-07-13 21:01:19 +00:00
scudo_allocator_secondary.h [Sanitizers] Move cached allocator_may_return_null flag to sanitizer_allocator 2017-06-20 21:23:02 +00:00
scudo_crc32.cpp [scudo] CRC32 optimizations 2017-05-09 15:12:38 +00:00
scudo_crc32.h [scudo] CRC32 optimizations 2017-05-09 15:12:38 +00:00
scudo_flags.cpp [scudo] Quarantine overhaul 2017-07-24 15:29:38 +00:00
scudo_flags.h [scudo] 32-bit and hardware agnostic support 2016-11-30 17:32:20 +00:00
scudo_flags.inc [scudo] Quarantine overhaul 2017-07-24 15:29:38 +00:00
scudo_interceptors.cpp [scudo] 32-bit and hardware agnostic support 2016-11-30 17:32:20 +00:00
scudo_new_delete.cpp [scudo] Application & platform compatibility changes 2017-08-16 16:40:48 +00:00
scudo_termination.cpp [scudo] 32-bit and hardware agnostic support 2016-11-30 17:32:20 +00:00
scudo_tls.h [scudo] Fix improper TSD init after TLS destructors are called 2017-09-11 19:59:40 +00:00
scudo_tls_android.cpp [scudo] Fix improper TSD init after TLS destructors are called 2017-09-11 19:59:40 +00:00
scudo_tls_android.inc [scudo] Fix improper TSD init after TLS destructors are called 2017-09-11 19:59:40 +00:00
scudo_tls_context_android.inc [scudo] Add Android support 2017-05-05 21:38:22 +00:00
scudo_tls_context_linux.inc [scudo] Add Android support 2017-05-05 21:38:22 +00:00
scudo_tls_linux.cpp [scudo] Fix improper TSD init after TLS destructors are called 2017-09-11 19:59:40 +00:00
scudo_tls_linux.inc [scudo] Fix improper TSD init after TLS destructors are called 2017-09-11 19:59:40 +00:00
scudo_utils.cpp [scudo] getauxval alternative for Android 2017-09-06 17:51:32 +00:00
scudo_utils.h [sanitizers] Add a blocking boolean to GetRandom prototype 2017-08-14 14:53:47 +00:00