23 Commits

Author SHA1 Message Date
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
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
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
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
b5eb55d19d [NFC][LSAN] Move GetAdditionalThreadContextPtrsLocked 2023-05-08 12:44:13 -07:00
Fangrui Song
8c63dc6f6d Internalize AllocationBegin functions after D147005
Reviewed By: thurston

Differential Revision: https://reviews.llvm.org/D148195
2023-04-13 10:28:58 -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
Thurston Dang
d644ab022a Update __sanitizer_get_allocated_begin to return const void*
D147005 introduced __sanitizer_get_allocated_begin, with a return
value of void*. This involved a few naughty casts that dropped the
const. This patch adds back the const qualifier.

Differential Revision: https://reviews.llvm.org/D147489
2023-04-04 00:43:36 +00:00
Jie Fu
c81a322476 [compiler-rt] Fix -Wcast-qual after D147005 (NFC)
/home/jiefu/llvm-project/compiler-rt/lib/lsan/lsan_allocator.cpp:161:18: error: cast from 'const void *' to 'void *' drops const qualifier [-Werror,-Wcast-qual]
  return (void *)beg;
                 ^
1 error generated.
2023-04-04 07:40:34 +08:00
Thurston Dang
415b1cfd57 Add __sanitizer_get_allocated_begin API and implementations
This function will return the start of the allocation, if given a pointer that lies within an allocation. Otherwise, it returns NULL.

It will be useful for detecting dynamic TLS allocations in glibc >=2.25, which
uses malloc (see https://github.com/google/sanitizers/issues/1409#issuecomment-1214244142).

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D147005
2023-04-03 21:27:51 +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
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 f001e50f955c3cdf2deb79e38a9fd19c9a781882.
This reverts commit 2924189233fdb724453ead4b94595107b1ce9cfa.
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
Vitaly Buka
7788b0c097 [lsan] malloc_usable_size returns 0 for nullptr 2022-07-02 20:16:30 -07:00
Vitaly Buka
12e137ab24 [NFC][sanitizer] Consolidate malloc hook invocations 2022-04-12 20:08:29 -07:00
Vitaly Buka
ce1cb9d2c1 [NFC][sanitizer] Clang format some code 2022-04-12 18:45:50 -07:00
Clemens Wasser
33e3554ea3 Change __lsan::kMaxAllowedMallocSize literal types to unsigned long long
It is required for the [Leak Sanitizer port to Windows](https://reviews.llvm.org/D115103).
The currently used `unsigned long` type is 64 bits wide on UNIX like systems but only 32 bits wide on Windows.
Because of that, the literal `8UL << 30` causes an integer overflow on Windows.
By changing the type of the literals to `unsigned long long`, we have consistent behavior and no overflows on all Platforms.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D115186
2021-12-07 10:38:13 -08:00
Vitaly Buka
6318001209 [sanitizer] Support IsRssLimitExceeded in all sanitizers
Reviewed By: kstoimenov

Differential Revision: https://reviews.llvm.org/D115000
2021-12-03 12:45:44 -08:00
Fangrui Song
1daa48f005 [lsan] realloc: don't deallocate if requested size is too large
This is the behavior required by the standards.

Differential Revision: https://reviews.llvm.org/D99480
2021-03-29 13:35:10 -07:00
Dan Liew
dd922bc2a6 [LSan] Introduce a callback mechanism to allow adding data reachable from ThreadContexts to the frontier.
This mechanism is intended to provide a way to treat the `arg` pointer
of a created (but not yet started) thread as reachable. In future
patches this will be implemented in `GetAdditionalThreadContextPtrs`.

A separate implementation of `GetAdditionalThreadContextPtrs` exists
for ASan and LSan runtimes because they need to be implemented
differently in future patches.

rdar://problem/63537240

Differential Revision: https://reviews.llvm.org/D95183
2021-01-22 19:26:02 -08:00
Matt Morehouse
7904bd9409 [sanitizer_common] Create max_allocation_size_mb flag.
Summary:
The flag allows the user to specify a maximum allocation size that the
sanitizers will honor.  Any larger allocations will return nullptr or
crash depending on allocator_may_return_null.

Reviewers: kcc, eugenis

Reviewed By: kcc, eugenis

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D69576
2019-10-30 11:26:05 -07:00
Nico Weber
ae1fc9baae compiler-rt: Rename .cc file in lib/lsan to .cpp
Like r367463, but for lsan.

llvm-svn: 367561
2019-08-01 14:01:30 +00:00