Commit Graph

589 Commits

Author SHA1 Message Date
Fangrui Song
fe1d02b08c [sanitizer] Reject unsupported -static at link time (#83524)
Most sanitizers don't support static linking. One primary reason is the
incompatibility with interceptors. `GetTlsSize` is another reason.
asan/memprof use `__interception::DoesNotSupportStaticLinking`
(`_DYNAMIC` reference) to reject -static at link time. Port this
detector to other sanitizers. dfsan actually supports -static for
certain cases. Don't touch dfsan.
2024-03-12 23:09:36 -07:00
Vitaly Buka
bf8c7cda49 Revert "[NFC][compiler-rt] Try to collect more info about crashes on bot"
Catches nothing, reported #84654.

This reverts commit 6f7ebcb71f.
2024-03-09 14:33:26 -08:00
Vitaly Buka
6f7ebcb71f [NFC][compiler-rt] Try to collect more info about crashes on bot 2024-03-09 12:51:02 -08:00
Vitaly Buka
23aabdd66f [NFC][sanitizer] Move SymbolizedStackHolder into sanitizer_common (#77152)
And replace most `ClearAll()` uses.
2024-01-05 18:40:40 -08:00
Vitaly Buka
f78a742ab8 [NFC][sanitizer] Rename Lock{Before,After}Fork suffixes locking StackDepotBase (#76279)
This is preparation for performance optimization.

We need to highlight that this is very specific lock, and should not be
used for other purposes.
Add `fork_child` parameter to distinguish processes after fork.
2023-12-22 23:38:01 -08:00
Azharuddin Mohammed
2a03854e4c [sanitizer] [Darwin] Disable InstallAtForkHandler
This is a followup to d01be3c631.
2023-12-18 12:32:17 -08:00
Vitaly Buka
d01be3c631 [sanitizer] Disable InstallAtForkHandler on Solaris, NetBSD (#75659)
Handlers need missing FutexWait implementation.

Reported in #75290.
2023-12-18 10:50:55 +01:00
Vitaly Buka
14d7e0bb0f [lsan] Install pthread_atfork (#75281)
This prevents deadlocks in forked process on essencial
runtime components.
2023-12-13 13:09:36 -08:00
Vitaly Buka
e1e5f35409 [NFC][lsan] clang-format includes 2023-12-12 20:53:08 -08:00
Heejin Ahn
d859403037 [sanitizer] Fix pthread_exit interceptor's return type (#71253)
`pthread_exit`'s return type is void.
2023-11-05 22:41:37 -08:00
PiJoules
54fe7ef700 [compiler-rt][lsan][Fuchsia] Adjust lsan allocator settings (#69401)
These now match the settings for the asan allocator on Fuchsia+RISCV.
2023-10-23 11:53:15 -07:00
PiJoules
9efaff1b0c [NFC][lsan] Extract and rename SizeClassMap type from AP64 (#69526)
This will make it easier to read rather than using SizeClassMap in the
same namespace.
2023-10-23 11:49:59 -07:00
Vitaly Buka
5b7dfa968f [NFC][sanitizer] Rename InternalScopedString::append to AppendF (#66558)
Prepare to introduce trivial InternalScopedString::Append(const char*).
2023-09-15 17:06:20 -07:00
Leonard Chan
4db6803dc7 [lsan][fuchsia] Add extra check for allocator cache to avoid overflow
Prior to this, we would check if the end of the allocator cache was located
before the end of the chunk passed to the tls check. However, if the actual
allocator cache comes after the end of the chunk, then the sub in the
`end - params->allocator_caches[i]` bit overflows. Since the resulting type
is an unsigned uptr, this is not UB, but if the signed result would be a
negative value (ie. `end < params->allocator_caches[i]`) then this will
actually result in a very large unsigned value much bigger than the compared
`sizeof(AllocatorCache)` which will almost always be true. This can cause
ScanRangeForPointers to accept incorrect values: a begin pointing to some
address, and `params->allocator_caches[i]` pointing to some much larger
address way past the end of the chunk which can result in a page fault/stack overflow.

Differential Revision: https://reviews.llvm.org/D159518
2023-09-14 23:03:16 +00:00
Leonard Chan
1abcf58402 [lsan][Fuchsia] Fix bounds checking for thread_local allocator cache when scanning TLS regions
When scanning over TLS regions, we attempt to check if one of the regions is
one of the thread_local allocator caches which would be located in one of the
TLS blocks pointer to by the DTV. This is to prevent marking a pointer that was
allocated by the primary allocator (from a thread_local cache) as reachable. The
check is a simple bounds check to see if the allocator cache is within the
bounds of one of the TLS block we're iterating over, but it looks like the check
for the end of the cache is slightly incorrect.

Differential Revision: https://reviews.llvm.org/D156015
2023-08-30 20:49:21 +00:00
Vitaly Buka
cb0a183e5b [NFC][sanitizer] Add and use empty RTSanitizerCommonSymbolizerInternal
Follow patches will add implementation.

For https://github.com/llvm/llvm-project/issues/30098

Reviewed By: Enna1, phosek

Differential Revision: https://reviews.llvm.org/D157921
2023-08-14 23:43:27 -07:00
Hau Hsu
e7191fbec3 [RISCV][Lsan] Set allocator for AP64
This patch uses similar allocator configuration to Asan, i.e. dynamic
allocator start address (~(uptr)0) and 128 GB allocator size.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D152895
2023-08-08 18:17:48 +08:00
Kirill Stoimenov
0365ccd2a1 [HWASAN][LSAN] Fix false positive memory leak reports on X86_64
Before this patch when running HWASAN on x86_64 with with memory tagging support we got a bunch of false memory leak reports. The reason for that is that the heuristic used to detect if an 8 bytes could be a user pointer was not valid when memory tagging is used as the top byte could contain non-zero information.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D155338
2023-07-18 19:04:30 +00:00
Leonard Grey
ac604cc310 [lsan][Darwin] Unconditionally strip high bits from potential pointers
The method cache stashes a mask in the high bits under some circumstances:
689525d556/runtime/objc-cache.mm (L589)

I'm hitting this now on macOS 13.4 arm64, so we can no longer rely on OBJC_FAST_IS_RW to identify potential pointers that need to be transformed

Differential Revision: https://reviews.llvm.org/D153471
2023-07-17 15:18:53 -04:00
Dmitry Vyukov
1377179396 sanitizer_common: initialize sanitizer runtimes lazily from signal interceptors
Currently if a program calls sigaction very early (before non-lazy sanitizer
initialization, in particular if .preinit_array initialization is not enabled),
then sigaction will wrongly fail since the interceptor is not initialized yet.

In all other interceptors we do lazy runtime initialization for this reason,
but we don't do it in the signal interceptors.
Do lazy runtime initialization in signal interceptors as well.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D155188
2023-07-13 16:28:25 +02:00
Vitaly Buka
679d9ea14d [NFC][sanitizer] Rename sanitizer_common_range -> sanitizer_range 2023-06-12 15:36:27 -07:00
Vitaly Buka
99dc68387b [NFC][lsan] Use hash table to track root regions
This avoid O(N) in __lsan_unregister_root_region.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D151784
2023-06-02 14:38:01 -07:00
Vitaly Buka
0375a2dc7d [NFC][sanitizer] Avoid O(N^2) algorithm
Usually root_regions size is small so unlikey
this change will provide a noticable difference.

However it's easy to make sure that even with
large number of root_regions it works reasonably
fast.

Differential Revision: https://reviews.llvm.org/D151781
2023-06-02 14:32:03 -07:00
Vitaly Buka
6fb26348e9 [LSAN] Move ThreadCreate into child thread
Speeds up thread creation. Similar approach is already used
by other sanitizers.
2023-05-29 23:43:45 -07:00
Vitaly Buka
506923a12f [lsan] Don't use InternalMmapVectorNoCtor as local var 2023-05-28 23:33:47 -07:00
Vitaly Buka
19b7b93da9 [lsan] Iterate MemoryMappingLayout once
Iterating many time can be very expensive.
2023-05-28 23:09:59 -07:00
Vitaly Buka
0a6aec2fb3 [NFC][lsan] Change Mac root regions scan 2023-05-28 22:28:37 -07:00
Vitaly Buka
8ce66a1f79 [NFC][lsan] Add CHECKs for root regions 2023-05-28 22:10:00 -07:00
Vitaly Buka
e4b02c61d1 [NFC][lsan] Make mutex static 2023-05-28 21:52:20 -07:00
Vitaly Buka
1068cf787e [NFC][lsan] Rename RootRegion and replace size with end 2023-05-28 21:21:26 -07:00
Jin Xin Ng
7639265af4 [sanitizer] Implement __sanitizer_get_allocated_size_fast
The primary motivation for this change is to allow FreeHooks to obtain
the allocated size of the pointer being freed in a fast, efficient manner.

Differential Revision: https://reviews.llvm.org/D151360
2023-05-26 00:19:47 +00:00
Vitaly Buka
07edc1c16f [NFC][sanitizer] Rename *ThreadRegistry functions
Reviewed By: thurston

Differential Revision: https://reviews.llvm.org/D150407
2023-05-24 18:34:14 -07:00
Vitaly Buka
c46bc0d3e7 [lsan] Fix allocator_interface implementation
__sanitizer_get_current_allocated_bytes had as body, but allocator
caches were not registered to collect stats. It's done by
SizeClassAllocator64LocalCache::Init().

Reviewed By: thurston

Differential Revision: https://reviews.llvm.org/D151355
2023-05-24 13:27:23 -07:00
Marco Elver
175fcd6fd2 [compiler-rt] Simplify ALIAS() attribute macro
Most uses of ALIAS() are in conjunction with WRAPPER_NAME().

Simplify the code and just make ALIAS() turn its argument into a string
(similar to Linux kernel's __alias macro). This in turn allows removing
WRAPPER_NAME().

NFC.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D151216
2023-05-24 11:57:17 +02:00
Jin Xin Ng
90418dc95e [lsan] Invoke hooks on realloc
Previously lsan would not invoke hooks on reallocations.
An accompanying regression test is included in sanitizer_common.

This change also moves hook calls to a location where subsequent
calls (via an external caller) to __sanitizer_get_allocated_size
via hooks will return a valid size.

This allows a faster version of __sanitizer_get_allocated_size
to be implemented, which can skip checks.

Test to ensure RunFreeHooks' call order will come with
__sanitizer_get_allocated_size_fast

Differential Revision: https://reviews.llvm.org/D151175
2023-05-23 16:42:07 +00:00
Vitaly Buka
3cabfe666c [LSAN] Use ThreadArgRetval in LSAN
Fixes false leaks on thread retval.

Reviewed By: thurston

Differential Revision: https://reviews.llvm.org/D150165
2023-05-18 01:11:54 -07:00
Vitaly Buka
d2b434b4e9 Revert "[LSAN] Use ThreadArgRetval in LSAN"
https://bugs.chromium.org/p/chromium/issues/detail?id=1445676

This reverts commit 20a3c6e84e.
2023-05-16 10:49:45 -07:00
Vitaly Buka
0d846d206e Revert "[NFC][LSAN] Move ThreadCreate into child thread"
https://bugs.chromium.org/p/chromium/issues/detail?id=1445676

This reverts commit 6d7b26ae49.
2023-05-16 10:49:45 -07:00
Jon Roelofs
cd4ffbe0ff lsan-rt: silence a -Wformat-pedantic 2023-05-16 07:24:54 -07:00
Vitaly Buka
d1aee9c0cb [sanitizers] Remove assert from ThreadArgRetval::Finish
Bionic uses pthread_exit to set retval, when GLIBC does not.
This cause double call to Finish. Rather then tracking this difference
on interceptor size, we can just relax precondition. It does not make
a difference.
2023-05-12 10:15:11 -07:00
Vitaly Buka
2394f091df [ASAN][LSAN] Ignore main or uninitialized thead in pthread_exit
Fix crash on CHECK in ThreadArgRetval::Finish().
2023-05-11 22:58:09 -07:00
Vitaly Buka
6d7b26ae49 [NFC][LSAN] Move ThreadCreate into child thread 2023-05-11 16:18:52 -07:00
Vitaly Buka
20a3c6e84e [LSAN] Use ThreadArgRetval in LSAN
Fixes false leaks on thread retval.

Reviewed By: thurston

Differential Revision: https://reviews.llvm.org/D150165
2023-05-11 15:58:04 -07:00
Vitaly Buka
b5eb55d19d [NFC][LSAN] Move GetAdditionalThreadContextPtrsLocked 2023-05-08 12:44:13 -07:00
Vitaly Buka
da7943b637 [NFC][LSAN] Add more pthread interceptors
They are empty for now. Follow up patches will introduce behaviour
changes.
2023-05-07 16:22:41 -07:00
Vitaly Buka
437b7602e4 [NFC][lsan] Use LowLevelAllocator to allocate ThreadContext
This is more RAM and CPU efficient than allocating entire page per
context, and this approach is used by other sanitizers already.

With the patch "create_thread_loop2.cpp.tmp 5000" is 30% faster.
2023-04-17 20:05:26 -07:00
Vitaly Buka
6c4219f816 [lsan] Fix Darwin build 2023-04-17 16:35:47 -07:00
Vitaly Buka
914d082ff0 [lsan] Fix Darwin build 2023-04-17 16:29:55 -07:00
Vitaly Buka
7760272778 [lsan] Don't crash on ThreadRegistry::threads_ data race
Comment "No lock needed" in CurrentThreadContext was wrong.
Concurent ThreadRegistry::CreateThread can resize and relocate
ThreadRegistry::threads_ the same time CurrentThreadContext reads it.

To mitigate lock cost we store ThreadContext* instead of tid in
THREADLOCAL cache, we can tid from the ThreadContext*.

Reviewed By: kstoimenov, MaskRay

Differential Revision: https://reviews.llvm.org/D148281
2023-04-17 15:33:43 -07:00
Vitaly Buka
02eb818f64 [NFC][lsan] Add GetCurrentThreadId wrapper for GetCurrentThread
I am going to change return type of GetCurrentThreadId() in the next
patch.

Differential Revision: https://reviews.llvm.org/D148394
2023-04-14 23:02:15 -07:00