103 Commits

Author SHA1 Message Date
Hans Wennborg
ee5367bedb Revert "[compiler-rt]: fix CodeQL format-string warnings via explicit casts (#153843)"
It broke the build:

compiler-rt/lib/hwasan/hwasan_thread.cpp:177:11: error: unknown type name 'ssize_t'; did you mean 'size_t'?
   177 |          (ssize_t)unique_id_, (void *)this, (void *)stack_bottom(),
       |           ^~~~~~~
       |           size_t

> This change addresses CodeQL format-string warnings across multiple
> sanitizer libraries by adding explicit casts to ensure that printf-style
> format specifiers match the actual argument types.
>
> Key updates:
> - Cast pointer arguments to (void*) when used with %p.
> - Use appropriate integer types and specifiers (e.g., size_t -> %zu,
> ssize_t -> %zd) to avoid mismatches.
> - Fix format specifier mismatches across xray, memprof, lsan, hwasan,
> dfsan.
>
> These changes are no-ops at runtime but improve type safety, silence
> static analysis warnings, and reduce the risk of UB in variadic calls.

This reverts commit d3d5751a39452327690b4e011a23de8327f02e86.
2025-08-22 12:50:53 +02:00
Amit Kumar Pandey
d3d5751a39
[compiler-rt]: fix CodeQL format-string warnings via explicit casts (#153843)
This change addresses CodeQL format-string warnings across multiple
sanitizer libraries by adding explicit casts to ensure that printf-style
format specifiers match the actual argument types.

Key updates:
- Cast pointer arguments to (void*) when used with %p.
- Use appropriate integer types and specifiers (e.g., size_t -> %zu,
ssize_t -> %zd) to avoid mismatches.
- Fix format specifier mismatches across xray, memprof, lsan, hwasan,
dfsan.

These changes are no-ops at runtime but improve type safety, silence
static analysis warnings, and reduce the risk of UB in variadic calls.
2025-08-22 11:51:13 +05:30
Kazu Hirata
c9680bcdc5 [compiler-rt] Fix a warning
This patch fixes:

  compiler-rt/lib/hwasan/hwasan_report.cpp:331:57: error: format
  specifies type 'void *' but the argument has type 'const uptr *'
  (aka 'const unsigned long *') [-Werror,-Wformat-pedantic]
2024-07-11 23:30:55 -07:00
Vitaly Buka
c9df9565ea
[NFC][hwasan] Use %p to print addresses (#98576) 2024-07-11 22:40:48 -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
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
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
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
Vitaly Buka
58fdfe77ef [NFC][hwasan] More consts in BaseReport (#66682) 2023-09-20 20:56:21 -07:00
Vitaly Buka
2613c77cba
[HWASAN] Prevent SEGV in report near inaccessible memory (#66861)
We can't use IsAccessibleMemoryRange on short granule check because of
performance impact. However we can prevent crashing if report prints out
"Tags for short granules around the buggy address".
2023-09-20 14:07:30 -07:00
Vitaly Buka
41934f2d1f [NFC][hwasan] Collect heap allocations early (#66682) 2023-09-19 19:29:33 -07:00
Vitaly Buka
22602c48d1 [NFC][hwasan] Extract announce_by_id (#66682) 2023-09-19 19:29:33 -07:00
Vitaly Buka
5670ef44f8 [NFC][hwasan] Extract a few BaseReport::Copy methods (#66682) 2023-09-19 19:29:33 -07:00
Vitaly Buka
1c91b1ebad [NFC][hwasan] Clang-format c557621176f5f38b5757a325cc72be0a11a91c78 2023-09-19 19:28:08 -07:00
Vitaly Buka
97abf2e755 [NFC][hwasan] Find overflow candidate early (#66682) 2023-09-19 19:17:55 -07:00
Vitaly Buka
c557621176 [NFC][hwasan] Make ShowHeapOrGlobalCandidate a method (#66682) 2023-09-19 18:54:30 -07:00
Vitaly Buka
dc810e880f [NFC][hwasan] Collect heap related data early (#66682) 2023-09-18 18:41:00 -07:00
Vitaly Buka
d307d20717 [NFC][hwasan] Make PrintAddressDescription method of BaseReport (#66682) 2023-09-18 18:34:12 -07:00
Vitaly Buka
13deda4f22 [NFC][hwasan] Remove default argument 2023-09-18 18:28:24 -07:00
Vitaly Buka
8519d4fda1 [NFC][hwasan] Add access_size into base report (#66682) 2023-09-18 18:21:40 -07:00
Vitaly Buka
542f91f755 [NFC][hwasan] Store thread id in SavedStackAllocations (#66682) 2023-09-18 18:13:57 -07:00
Vitaly Buka
810bca56f0 [NFC][hwasan] Move PrintAddressDescription (#66682) 2023-09-18 17:20:50 -07:00
Vitaly Buka
9094b3b4ae [NFC][hwasan] Extract BaseReport (#66682) 2023-09-18 17:19:53 -07:00
Vitaly Buka
75fdf2e7b6 [NFC][hwasan] Move Report classes together (#66682) 2023-09-18 17:16:01 -07:00
Vitaly Buka
d39d86da4a [NFC][hwasan] Use unnamed namespace and static (#66682) 2023-09-18 17:16:01 -07:00
Vitaly Buka
0fb6da8bab [NFC][hwasan] Create *Report classes (#66682)
This prepare the code for rework to collect all nececcecary data before
symbolization. Symbolization as any untrivial computations may affect
hwasan metadata.
2023-09-18 17:14:44 -07:00
Vitaly Buka
b2ef297b6e [NFC][hwasan] Remove default argument 2023-09-18 17:09:55 -07:00