579 Commits

Author SHA1 Message Date
Florian Mayer
dfaa144d0c
[NFC] [HWASan] clarify FIXME comment (#87689) 2024-04-04 12:55:05 -07:00
Florian Mayer
beded9b9ce
[HWASan] Allow stack_history_size of 4096 (#86362)
There is no reason to limit the minimum to two pages.
2024-04-04 12:28:10 -07:00
NAKAMURA Takumi
8f86c6bf95 compiler-rt: Fix variadic macro warnings [-Wc++20-extensions]
They began complaining since #84520.
2024-03-26 08:45:12 +09:00
Florian Mayer
7ef1a59ed1 remove incorrect DCHECK
this DCHECK was not valid for hwasan_load1, and was not necessary for
the. the function is written without any assumptions of alignment of the
pointer.
2024-03-18 15:39:48 -07: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
Enna1
371e6d0f24
[NFC][hwasan] Do not include sanitizer_placement_new.h in header files (#82993)
Do not include sanitizer_placement_new.h into header files, only into
source files.
2024-02-26 15:45:06 -08:00
Thurston Dang
0673fb6e77
[hwasan] Add missing printf parameter in __hwasan_handle_longjmp (#82559)
The diagnostic message had four format specifiers but only three
parameters. This patch adds what I assume to be the missing
parameter.
2024-02-23 09:53:55 -08:00
Vitaly Buka
39e32b451c
[hwasan] Fix stack tag mismatch report (#81939)
Existing code worked only for local, recorder FP, and the faulty address
are the same 1 MiB page.

Now, instead of guessing FP, we guess variable address.
We need to try just two cases of addresses around of faulty one.

Fixes https://github.com/google/sanitizers/issues/1723
2024-02-15 16:59:49 -08:00
Vitaly Buka
72e14fb33f [NFC][hwasan] Reduce nesting in function 2024-02-15 15:29:12 -08:00
Vitaly Buka
fbacf70f64 [NFC][hwasan] Add CHECK_LT(fp, kRecordFPModulus) 2024-02-15 15:29:12 -08:00
Enna1
b7cc401df5
[hwasan] Call user provided callback function for both fatal and non-… (#80429)
…fatal error report

This makes the behavior of HWASan matching with ASan: always call user
provided callback function for an error report, but only call
`SetAbortMessage()` on Android when `flags()->halt_on_error` is true.
2024-02-10 09:10:24 +08:00
Enna1
abe102b872
[Sanitizer][NFC] Replaces a few InternalScopedString::AppendF with InternalScopedString::Append (#80574) 2024-02-06 09:18:06 +08:00
Wu Yingcong
8bef13ef4f
[hwasan] Fix a possible null dereference problem (#77737)
This is clearly a copy-paste mistake, fix it with this patch.
After checking the `local.function_name` is not null, it should check
the len for `local.function_name`, not `local.name`. And this could lead
to possible null dereference since the second
`internal_strlen(local.name)` does not guarantee `local.name` is not
null.
2024-01-21 21:42:38 -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
7962bd5719
[hwasan] Make stack variables output consistent with globals (#76197) 2023-12-26 13:45:24 -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
Vitaly Buka
7db28dd3f8
[hwasan] Classify stack overflow, and use after scope (#76133)
We can't distinguish UAR and UAS, but by definition
UAR is already UAS.
2023-12-21 17:51:14 -08:00
Vitaly Buka
7c3b67d203
[hwasan] Respect strip_path_prefix printing locals (#76132) 2023-12-21 16:03:06 -08:00
Vitaly Buka
528150b90b
[hwasan] Separate sections in report (#76130)
It makes them easier to read.
2023-12-21 12:37:17 -08:00
Vitaly Buka
8d300e67d2
[hwasan] Improve support of forking with threads (#75291)
Lock Lsan and Thread related date at_fork.

Clean shadow before thread starts, forked process may reuse already
mapped stack of 'lost' parent thread for new threads.
2023-12-13 14:50:26 -08:00
Vitaly Buka
64fa90bf89
[hwasan] Add __hwasan_get_tag_from_pointer (#75267)
This simplifies handling tags by user code. Now code does not need
to know bit size of tag and its position.
2023-12-13 11:22:10 -08:00
Thurston Dang
ea991a11b2
[hwasan] Add fixed_shadow_base flag (#73980)
When set to non-zero, the HWASan runtime will map the shadow base at the
specified constant address.

This is particularly useful in conjunction with the existing compiler
option
'hwasan-mapping-offset', which bakes a hardcoded constant address into
the instrumentation.

---------

Co-authored-by: Thurston Dang <thurston@google.com>
2023-12-07 09:45:32 -08:00
Vitaly Buka
ae6db862a9
[hwasan] Use ErrorAction::Recover in interceptors (#74000) 2023-12-04 15:00:08 -08:00
Vitaly Buka
5fcf3bbb1a [NFC][HWASAN] Remove unused macro parameter 2023-12-02 16:40:14 -08:00
Nikita Popov
89361007aa
[hwasan] Move __hwasan_thread_enter/__hwasan_thread_exit out of namespace (#72123)
Due to a GCC bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25940),
GCC doesn't consider extern "C" functions with the same name but
different namespace to be the same. As such, the default visibility
attribute (on a declaration outside the namespace) doesn't get applied
to the definition in the namespace and the symbol is not exported.

This came up as an ABI diff when switching between gcc and clang for
compiling compiler-rt.
2023-11-15 09:38:24 +01:00
Kirill Stoimenov
4d9f3ca77c
[HWASAN] Add memset interceptor (#71244)
Co-authored-by: Vitaly Buka <vitalybuka@google.com>
2023-11-07 00:01:04 -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
Kirill Stoimenov
3cf9bf343d
[HWASAN] Enable memcpy and memmove interceptors (#71217) 2023-11-03 14:17:45 -07:00
Vitaly Buka
3e5187ea83 Revert "[HWASAN] Enable memcpy, memmove and memset interceptors (#70387)"
Breaks build bots, details in #70387.

This reverts commit 91cdd7d615da38a1f025646f526c2fce265a37e2.
2023-10-30 21:09:21 -07:00
Kirill Stoimenov
91cdd7d615
[HWASAN] Enable memcpy, memmove and memset interceptors (#70387) 2023-10-30 15:01:21 -07:00
Kirill Stoimenov
ff1329e297
[HWASAN] Add bcmp interceptor (#69257) 2023-10-16 16:09:44 -07:00
Kirill Stoimenov
46c1671620
[HWASAN]Implement memcmp interceptor in HWASAN (#67204)
The plan is to fix memcmp interceptor in HWASAN and remove the
unsupported statement at that time.

---------

Co-authored-by: Vitaly Buka <vitalybuka@gmail.com>
2023-09-29 16:14:48 -07:00
Vitaly Buka
0cff5805f5
[hwasan] Fixing relocation R_AARCH64_CONDBR19 out of range (#67354) 2023-09-25 11:22:15 -07:00
Vitaly Buka
b300f8c898 [hwasan] Enabled internal_symbolizer with hwasan 2023-09-22 13:51:05 -07:00
Vitaly Buka
43aa6e6bf3
[hwasan] Fixing false invalid-free with disabled tagging (#67169)
This problem was accidentally discovered by the internal symbolizer, but
it's relevant for external one as well, see the test.

If we just disable tagging, there may still be tagged allocations that
have already been freed. After disabling tagging, these tagged
allocations can be released to the user as-is, which would later break
the "invalid-free" check.

We cannot just disable the "invalid-free" check with disabled tagging,
because if we re-enable tagging, the issue still applies to allocations
created when it was disabled.

The fix is to continue tagging with zero even if tagging is disabled.

This makes the "disabled" mode less efficient, but this is not the
primary use case.
2023-09-22 13:35:35 -07:00
Vitaly Buka
a15fbf0552 [NFC][hwasan] Remove redundant constant 2023-09-21 21:10:44 -07:00
Vitaly Buka
0984843d7f [NFC][hwasan] Return to one loop in CopyShadow
Looks simpler.
2023-09-21 17:19:36 -07:00
Vitaly Buka
de4850c1c8
[hwasan] Optimize shadow shapshot size (#67068)
Now we copy only tags we will print.
CHECKs in GetTagCopy and GetShortTagCopy ensure that.
2023-09-21 17:03:21 -07:00
Vitaly Buka
d12c892ee4 [hwasan] Fix consts after 6eaaf0916 2023-09-21 16:25:16 -07:00
Vitaly Buka
a1584dd201
[hwasan] Store some report data early (#66682)
Please review them one by one in order, and let me know which are OK.
It's mostly code shuffling.

The goal is to make HWASA collect all needed info the first, and
printout later.
This way we avoid the printing changes HWASAN metadata.
2023-09-21 15:27:03 -07:00
Vitaly Buka
6eaaf09168 [NFC][hwasan] Add a few const 2023-09-21 14:57:16 -07:00
Vitaly Buka
21e84e6d3a [NFC][hwasan] Remove unused members 2023-09-21 14:28:58 -07:00
Vitaly Buka
c567e942f5 [NFC][HWASAN] Extract BaseReport::PrintTags 2023-09-21 14:27:36 -07:00
Andres Villegas
f8ae2e4277
Reland: [sanitizer_symbolizer] Add StackTracePrinter virtual class (#66689)
Introduce a new virtual class StackTracePrinter and an implementation
FormattedStackTracePrinter in preparation of enabling symbolizer markup
for linux.
This change allows us to implement other behaviour under the same api
for StackTracePrinter, for example, MarkupStackTracePrinter.

Reason for revert: A missing header file for the
sanitizer_symbolizer_markup.cpp files.
This was not caught in local builds or pre-merge checks given that to
trigger the error, the code
has to be compiled for Fuchsia.
For this reland I've build for the fuchsia targets as well as linux.
2023-09-21 11:28:20 -07:00
Vitaly Buka
08aeac0387 [NFC][hwasan] Store shadow bytes early (#66682) 2023-09-20 22:14:28 -07:00
Vitaly Buka
6d9857167a Revert "[NFC][hwasan] Store shadow bytes early (#66682)"
InvalidFreeReport prints invalid ptr/mem.

This reverts commit 7641c220a03f6ecef13a5ec76d1b2056ff7bbde5.
2023-09-20 22:14:28 -07:00
Vitaly Buka
7641c220a0 [NFC][hwasan] Store shadow bytes early (#66682) 2023-09-20 21:26:20 -07:00
Vitaly Buka
ac750e237b [NFC][hwasan] Stored tail early (#66682) 2023-09-20 21:03:06 -07:00
Vitaly Buka
ddedad8070 [NFC][hwasan] Use stored chunk in TailOverwrittenReport (#66682) 2023-09-20 21:03:06 -07:00
Vitaly Buka
5cd0e5d047 [NFC][hwasan] Set more fields by value and make them const (#66682) 2023-09-20 21:03:06 -07:00