621 Commits

Author SHA1 Message Date
Brad Smith
e0cd57decb
[compiler-rt] Remove support and workarounds for Android 4 and older (#124056) 2025-01-23 13:00:39 -05:00
Fangrui Song
ac38ab594f
[lsan] Use VReport if not REGISTERS_AVAILABLE (#116555)
Certain tests (many are from lld/test) run `... '2>&1 | count 0` to
ensure that there is no stderr message.

GetRegistersAndSP may rarely fail, leading to
a spurious failure like (with a local hack to make `count` dump the
input):

```
+ /home/ray/llvm/out/asan/bin/ld.lld func1-gcs.o func2-gcs.o func3-gcs.o -o /dev/null -z gcs-report=warning -z gcs=never
+ /home/ray/llvm/out/asan/bin/count 0
Expected 0 lines, got 1.
==2403039==Unable to get registers from thread 2403018.
```

The failure can reliably be reproduced by running `ninja check-lld` a
few times under asan+lsan (see the bot
sanitizer-x86_64-linux-bootstrap-asan).
2024-11-20 01:07:28 -08:00
Vitaly Buka
b5fa4fee46
[lsan] Fix compilation on Android (#113003) 2024-10-18 18:40:29 -07:00
Vitaly Buka
0138adb68f
[nfc][lsan] Rename ScanExtraStack and pass region_type (#113004) 2024-10-18 16:35:59 -07:00
Vitaly Buka
f4c6088346
[lsan] Process non-suspended threads (#112807)
For such threads we have no registers, so no exact
stack range, and no guaranties that stack is mapped
at all.

To avoid crashes on unmapped memory,
 `MemCpyAccessible` copies intersting range into
 temporarily buffer, and we search for pointers there.
2024-10-18 15:23:52 -07:00
Vitaly Buka
d60fdc1ca3
[nfc][lsan] Parametrize ScanForPointers with loader (#112803)
Use `DirectLoader` which is equivalent to existing
behaviour of loading pointers directly from memory.
2024-10-18 11:42:13 -07:00
Vitaly Buka
3142dff704
[nfc][lsan] Extract significant part of the loop into a function (#112610)
Co-authored-by: thetruestblue <92476612+thetruestblue@users.noreply.github.com>
2024-10-16 22:45:40 -07:00
Vitaly Buka
6ffd3bbcd7
[nfc][lsan] Restructure loop in ProcessThreads (#112609)
The goal is to move `SuspendedThreadsList` related code into
the beginning of the loop, and prepare for extraction the rest
of the loop body into a function.
2024-10-16 18:32:14 -07:00
Vitaly Buka
dd9a34fd7e
[nfc][lsan] Move up vectors cleanup (#112608) 2024-10-16 18:30:20 -07:00
Vitaly Buka
1834660b4c
[nfc][lsan] Replace suspended_threads.GetThreadID(i) with local var (#112607) 2024-10-16 16:40:24 -07:00
Vitaly Buka
b2b0e6c01e [NFC][lsan] Fix name of local var 2024-10-15 20:44:51 -07:00
Vitaly Buka
fa81868fe6
[lsan] Log thread history (#111949)
Only with high verbosity and leak reports, or thread logging requested.
2024-10-11 18:09:37 -07:00
Vitaly Buka
e1cff8bf81
[lsan] Add debug option to "deflake" leaks (#112037)
There are hard to debug leaks which look like
false.

In general, repeating leak checking should not
affect set of leaks significantly, especial
`at_exit` leak checking.

But if we see significant discrepancy, it may give
us a clue for investigation.
2024-10-11 16:57:19 -07:00
Vitaly Buka
36bd9aebc4
[sanitizer] VReport BeforeFork/AfterFork (#111900)
Forks are common suspects for unusual sanitizer behavior.
It can be handy to see them without rebuild.
2024-10-10 13:12:36 -07:00
Vitaly Buka
453d373e80 [lsan] Add a few "\n" missing from VReport 2024-10-10 11:24:36 -07:00
Hans Wennborg
3137b6a263 [lsan] Make ReportUnsuspendedThreads return bool also for Fuchsia
Follow-up to 9766ce4db57212646f135fe7033972a7a51aef4d
2024-10-07 11:19:32 +02:00
Vitaly Buka
9766ce4db5 [lsan] Add thread_suspend_fail flag 2024-10-04 22:53:37 -07:00
Vitaly Buka
a0bb2e21c1
[NFC][sanitizer] Move InitTlsSize into InitializePlatformEarly (#108921) 2024-09-18 16:19:35 -07:00
Vitaly Buka
f13b7d0b02
Reland "[sanitizer] Fix partially initialized static TLS range" (#108883)
Reland llvm/llvm-project#108685

Arguments order was wrong on Windows and Darwin.
2024-09-16 14:05:00 -07:00
Vitaly Buka
9a1d0744ed
Revert "[sanitizer] Fix partially initialized static TLS range" (#108881)
Reverts llvm/llvm-project#108685

Breaks Darwin and Windows
https://lab.llvm.org/buildbot/#/builders/107/builds/2930
https://ci.swift.org/view/all/job/llvm.org/view/LLDB/job/as-lldb-cmake/11684/
2024-09-16 13:51:23 -07:00
Vitaly Buka
b7c9ebe4ec
[sanitizer] Fix partially initialized static TLS range (#108685)
Fixes asan, msan crash on check added in #108684.
The #108684 includes reproducer of the issue.

Change interface of `GetThreadStackAndTls` to
set `tls_begin` and `tls_end` at the same time.
2024-09-16 12:48:24 -07:00
Vitaly Buka
b07f1be92c
[sanitizer] Remove DTLS_on_libc_memalign (#108120)
`DTLS_on_libc_memalign` is called from primary
allocator, so `__sanitizer_get_allocated_begin`
should also be aware of allocation,
and correctly handled by `GetDTLSRange`.
2024-09-12 00:50:54 -07:00
tmiasko
ae0ed3d586
[lsan] Fix free(NULL) interception during initialization (#106912)
Previously an attempt to free a null pointer during initialization would
fail on ENSURE_LSAN_INITED assertion (since a null pointer is not owned
by DlsymAlloc).
2024-09-11 15:37:02 -07:00
David CARLIER
7cbd89921b
[compiler-rt] lsan remove unneeded comma for pthread_atfork declaration. (#99788) 2024-07-20 23:51:04 +01:00
Fangrui Song
ba66d60b1c
[sanitizer] Replace ALIGNED with alignas
C++11 `alignas` is already used extensively. `alignas` must precede
`static`, so adjust the ordering accordingly.

msan.cpp: Clang 15 doesn't allow `__attribute__((visibility("default"))) alignas(16)`.
Use the order `alignas(16) SANITIZER_INTERFACE_ATTRIBUTE`. Tested with Clang 7.

Pull Request: https://github.com/llvm/llvm-project/pull/98958
2024-07-15 16:12:42 -07:00
Fangrui Song
bb8230bb2b
[sanitizer] Internalize .preinit_array variables
We can use an internal linkage variable to make it clear the variable is
not exported. The special section .preinit_array is a GC root.

Pull Request: https://github.com/llvm/llvm-project/pull/98584
2024-07-12 11:15:46 -07:00
Vitaly Buka
d38a8e937b
Undo lsan part of #98240 (#98409)
Undo lsan, ubsan from #98240 and
388c55a3e676a75ac242ff4f2db3fa39e5f0b0a3

There are parts which do not check COMPILER_RT_HAS_*.
2024-07-10 16:34:55 -07:00
Vitaly Buka
b96eb76d21
Revert "Revert "[compiler-rt] Remove redundant COMPILER_RT_HAS_*SAN checks"" (#98395)
Reverts llvm/llvm-project#98380

Probably some incremental build issue, the build before revert was
green:
https://lab.llvm.org/buildbot/#/builders/109/builds/817
2024-07-10 14:35:45 -07:00
Vitaly Buka
145ae81fa4
Revert "[compiler-rt] Remove redundant COMPILER_RT_HAS_*SAN checks" (#98380)
Reverts llvm/llvm-project#98240

https://lab.llvm.org/buildbot/#/builders/109/builds/816
2024-07-10 13:30:19 -07:00
Vitaly Buka
e6352604cd
[compiler-rt] Remove redundant COMPILER_RT_HAS_*SAN checks (#98240)
They are checked in the parent CMakeLists in
`compiler_rt_build_runtime` and `compiler_rt_test_runtime`.

There are non-redundant checks when a sanitizer checks
for the presense of another one. They should not be removed.
2024-07-10 13:03:48 -07:00
Vitaly Buka
f0f774ebf0
[sanitizer] Rename DEFINE_REAL_PTHREAD_FUNCTIONS (#96527)
We use REAL() calls in interceptors, but
DEFINE_REAL_PTHREAD_FUNCTIONS has nothing to do
with them and only used for internal maintenance
threads.

This is done to avoid confusion like in #96456.
2024-06-25 09:42:01 -07:00
Wu Yingcong
511077df76
[sanitizers] Bump malloc limit to 1TB for MSAN, LSAN & DFSAN (#89728)
We already have `const uptr kMaxAllowedMallocSize = 1ULL << 40;` set for
ASAN, HWASAN, memprof, TSAN. This patch bumps the malloc limit for MSAN,
LSAN and DFSAN to 1TB as well. 8GB is simply not enough nowadays.
2024-05-22 10:15:22 +08:00
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 6f7ebcb71f4e89309c613da9600991850f15f74f.
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 d01be3c63109986627c1c029d6d0130f76a63a2f.
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