Commit Graph

85 Commits

Author SHA1 Message Date
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
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 9766ce4db5
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
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
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
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
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
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
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
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
Vitaly Buka
39c0602414 [lsan] Rename IgnoreObjectLocked into IgnoreObject
We don't lock allocator for this call.
2023-04-05 16:17:44 -07:00
Bojun Seo
cbb9369b9e [lsan] Initialize uptr value with number not boolean
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D145354
2023-03-07 21:47:39 -08:00
Kirill Stoimenov
b4b5006be5 [LSAN] Mask out tags from pointers on ARM in MaybeUserPointer heuristic
This caused false positives because the existing logic was not taking into account that pointers could have a tag in them.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D144305
2023-02-18 03:37:56 +00:00
Kirill Stoimenov
eb3be66028 [LSAN] Add GetUserAddr function which returns the user visible address of an internal pointer
For HWASAN this would be the tagged address. It is the same pointer when pointer tagging is not used. Coincidently this also fixes some test which rely on comparing pointers.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D143121
2023-02-02 00:39:00 +00:00
Kirill Stoimenov
af210ee506 [LSAN][Fuchsia] Added ForEachExtraThreadStackRange to support Fuchsia code.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D141724
2023-01-13 21:20:41 -08:00
Youling Tang
3a58e11961 [lsan] Add lsan support for loongarch64
This patch enabled lsan for loongarch64 with 47-bit VMA layout.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D139686
2023-01-14 09:23:51 +08:00
Kirill Stoimenov
c184423e70 [LSAN] More LSAN interface tweaking.
Main goal is to remove thread registry dependency from the interface because HWASAN is using its own code to manage threads.

Reviewed By: vitalybuka, kstoimenov

Differential Revision: https://reviews.llvm.org/D140039
2023-01-12 17:58:11 -08:00
Vitaly Buka
eb2db81eba Revert "[LSAN] More LSAN interface tweaking."
Breaks bots.
Also it's missing changes we discussed on review.

This reverts commit f001e50f95.
This reverts commit 2924189233.
2023-01-12 17:32:40 -08:00
Kirill Stoimenov
2924189233 [LSAN] More LSAN interface tweaking.
Main goal is to remove thread registry dependency from the interface because HWASAN is using its own code to manage threads.

Reviewed By: vitalybuka, kstoimenov

Differential Revision: https://reviews.llvm.org/D140039
2023-01-12 23:44:08 +00:00
Kirill Stoimenov
e43e0ffbe7 [LSAN][NFC] Eliminated GetThreadRegistryLocked from the LSAN interface to avoid the need to implement it in HWASAN.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D139976
2022-12-14 00:15:40 +00:00
Vitaly Buka
ca3c58f0d1 [lsan] Add logs for debugging 2022-11-28 22:59:38 -08:00
Wiktor Garbacz
e851f7dbca Fix LSan build
This change fixes a build bug introduced in
39db491957

Differential Revision: https://reviews.llvm.org/D135860
2022-10-13 10:44:27 -07:00
Wiktor Garbacz
39db491957 [LeakSanitizer] Capture calling thread SP early to avoid false negatives.
As shown in https://github.com/llvm/llvm-project/issues/42932 dead
pointers might be overlapped by a new stack frame inside CheckForLeaks,
which does not use bytes with pointers. This leads to false negatives.

It's not a full solution for the problem as it does not solve
"overlapping" new/old frames for frames below the CheckForLeaks and in
other threads. It should improve leaks found in direct callers of
__lsan_do_leak_check.

Differential Revision: https://reviews.llvm.org/D130237
2022-10-12 16:46:32 -07:00
Leonard Grey
f458d9f6f8 [lsan][darwin] Unmask camouflaged class_rw_t pointers
Detailed motivation here: https://docs.google.com/document/d/1xUNo5ovPKJMYxitiHUQVRxGI3iUmspI51Jm4w8puMwo

check-asan (with LSAN enabled) and check-lsan are currently broken on recent macOS versions, due to pervasive false positives. Whenever the Objective-C runtime realizes a class, it allocates data for it, then stores that data with flags in the low bits. This means LSAN can not recognize it as a pointer while scanning.

This change checks every potential pointer on Apple platforms, and if the high bit is set, attempts to extract a pointer by masking out the high bit and flags. This is ugly, but it's also the best approach I could think of (see doc above); very open to other suggestions.

Differential Revision: https://reviews.llvm.org/D133126
2022-09-02 11:25:22 -04:00
Leonard Grey
b15cf06fb3 [lsan][nfc] Add missing newline to VReport 2022-07-15 15:44:23 -04:00
Andrew Ng
e06a81d810 [LSAN] Fix up LSAN weak symbols for Windows
Differential Revision: https://reviews.llvm.org/D126703
2022-06-01 10:18:51 +01:00
Mariusz Borsa
8246b2e156 [Sanitizers][Darwin] Replace SANITIZER_MAC with SANITIZER_APPLE in source files
This is a follow up to [Sanitizers][Darwin] Rename Apple macro SANITIZER_MAC -> SANITIZER_APPLE (D125816)

Performed a global search/replace as in title against LLVM sources

Differential Revision: https://reviews.llvm.org/D126263
2022-05-24 12:59:27 -07:00
Leonard Chan
c8644ea88e [compiler-rt][lsan] Update CanBeAHeapPointer for AArch64
While attempting to get the 64-bit lsan allocator working for Fuchsia, I
noticed this function would incorrectly return false for pointers returned
by the 64-bit allocator. On AArch64, this function attempts to get the VMA
size dynamically by counting the number of leading zeros from the function
frame address. This will fail if the frame address is significantly below an
allocated pointer (that is, the frame address has more leading zeros than an
allocated pointer). This is possible on Fuchsia and linux (when not called
from the initial thread stack).

It seems the intended use of this function is to speed up pointer scanning by
filtering out addresses that user code might not be able to access. Other
platforms this check is done on seem to hardcode the VMA size/shift, so it
seems appropriate to do this for aarch64 as well. This implies pointers on
aarch64 where the VMA size is <64 will pass through, but bad pointers will
still be caught by subsequent scan checks.

This patch also renames the function to something more fitting of what it's
trying to do.

Differential Revision: https://reviews.llvm.org/D123814
2022-05-24 10:22:46 -07:00
Vitaly Buka
a63932a815 [lsan] Allow suppression of "unknown module"
If sanitizer cannot determine name of the module it
will use "<unknown module>". Then it can be suppressed
if needed.

Reviewed By: kda

Differential Revision: https://reviews.llvm.org/D121674
2022-03-15 13:35:21 -07:00
Vitaly Buka
f86deb18ca [lsan] Move out suppression of invalid PCs from StopTheWorld
This removes the last use of StackDepot from StopTheWorld.

Depends on D115284.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D115319
2021-12-09 12:17:35 -08:00