12293 Commits

Author SHA1 Message Date
Marco Elver
ed9ef9b4f2 tsan: Consider SI_TIMER signals always asynchronous
POSIX timer can be configured to send any kind of signal, however, it
fundamentally does not make sense to consider a timer a synchronous
signal. Teach TSan that timers are never synchronous.

The tricky bit here is correctly defining compiler-rt's siginfo
replacement, which is a rather complex struct. Extend it in a limited
way that is mostly cross-platform compatible and add offset tests in
sanitizer_platform_limits_posix.cpp.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D142117
2023-01-20 11:47:30 +01:00
Lang Hames
3507df9c20 [ORC][ORC-RT] Add support for callback-based lookup of JIT'd MachO unwind info.
In LLVM the MachOPlatform class is modified to identify unwind info sections
and the address ranges of the functions these sections cover. These address
ranges are then communicated to the ORC runtime by attaching them to the
register-object-platform-sections allocation action.

In the ORC runtime the unwind-info section addresses are recorded and used to
support lookup of unwind info via the new `findDynamicUnwindSections` function.
At bootstrap time the ORC runtime checks for the presence of new
unwind-info-lookup-registration functions in libunwind (see
https://reviews.llvm.org/D142176), and if available uses them to register the
`findDynamicUnwindSections` function with libunwind to enable callback-based
lookup. If the new unwind-info-lookup-registration functions are not available
then the ORC runtime falls back to using the existing libunwind registration
APIs.

The callback-based scheme is intended to address three shortcomings in the
current registration scheme for JIT'd unwind info on Darwin: (1) Lack of
compact-unwind support, (2) inability to describe the subarchitecture of JIT'd
frames, and (3) lack of efficient address-based lookup data structures in
libunwind.

For more details see the proposed libunwind changes in
https://reviews.llvm.org/D142176.
2023-01-19 22:37:57 -08:00
Advenam Tacet
6c485409de Adding missing colon
Simple typo fix.
The absence of this colon may be confusing and result in misinterpretation of the result.

In normal libfuzzer mode, that colon is present.

You can compare with:
aa0e9046c1/compiler-rt/lib/fuzzer/FuzzerLoop.cpp (L356)

Reviewed By: #sanitizers, vitalybuka

Differential Revision: https://reviews.llvm.org/D142171
2023-01-19 20:57:12 -08:00
David Carlier
af05e818fb [Sanitizers] GetMemoryProfile implementation for FreeBSD.
Reviewers: dvyukov

Reviewed-By: dvyukov

Differental Revision: https://reviews.llvm.org/D140688
2023-01-19 18:01:03 +00:00
Kirill Stoimenov
f2b4b54417 [HWASAN] Init lsan and install at_exit hook
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D141146
2023-01-19 01:40:17 +00:00
Lang Hames
ad4b66fd9b [ORC-RT] Specialize non-coalescing-IntervalMap to allow non-comparable values.
In non-coalescing IntervalMaps the value type should not be requried to be
equality-comparable.
2023-01-18 17:39:45 -08:00
Kirill Stoimenov
9545580447 [HWASAN] Remove FindHeapChunkByAddressFastLocked
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D142042
2023-01-18 23:33:11 +00:00
Kirill Stoimenov
005c158121 [HWASAN] Fix Fuchsia link problem
Reviewed By: mysterymath

Differential Revision: https://reviews.llvm.org/D142057
2023-01-18 22:30:27 +00:00
Johan Erlandsson
8565e8352b [hwasan] add pattern for short tag in symbolizer
Lines with 'record_addr:' are not processed when failing to decode
access tag. The regular format is: %02x/%02x but for a short tag it's:
%02x/%02x(%02x). Now it will handle both cases.

Tested-by: Ivar Henckel <ivar.henckel@sony.com>

Reviewed By: fmayer

Differential Revision: https://reviews.llvm.org/D141906
2023-01-18 11:12:39 -08:00
Kirill Stoimenov
1cf17279cc [HWASAN] Add leak sanitizer flag support
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D141710
2023-01-18 00:03:51 -08:00
Vitaly Buka
0e08a85429 [HWASA] Restore LsanMetadata from D141642 Diff5
Unlike asan, we can't use pointer arithmetics to get from user ptr to
metadata. Asan does not use CombinedAllocator::GetMetadata and store
metadata next to the user data.
2023-01-17 23:45:51 -08:00
Vitaly Buka
c804775cd3 [hwasan] Fix LsanMetadata::LsanMetadata 2023-01-17 19:23:42 -08:00
Kirill Stoimenov
e022ca8b6e [HWASAN] Implemented LSAN SetLsanTag and IgnoreObjectLocked
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D141642
2023-01-17 17:59:17 -08:00
Florian Mayer
f3f4bc814b [NFC] [scudo] syntax-check DCHECK arguments if DCHECK is off
This is a widespread technique, used in at least:

* ABSL: https://github.com/abseil/abseil-cpp/blob/master/absl/log/internal/check_op.h#L52
* Chromium: https://source.chromium.org/chromium/chromium/src/+/main:base/check.h;l=185?q=DCHECK%20f:base&ss=chromium
* Android: https://cs.android.com/android/platform/superproject/+/master:system/libbase/include/android-base/logging.h;drc=bda7f0a0cc945c860713a1dc497919f17fad1651;l=321

Reviewed By: Chia-hungDuan, vitalybuka

Differential Revision: https://reviews.llvm.org/D141713
2023-01-17 16:56:49 -08:00
Florian Mayer
1ee2905764 [HWASan] link to doc in reports on Android
Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D141973
2023-01-17 16:29:51 -08:00
usama hameed
a44477b1f4 [CompilerRT] Remove ubsan static runtime on Apple
This patch removes the static ubsan runtime on Apple devices. The motivation
is to reduce the toolchain size.

rdar://102061519

Differential Revision: https://reviews.llvm.org/D141550
2023-01-17 14:33:31 -08:00
Lang Hames
bbb73fbceb [ORC-RT] Reapply ab59185fbfb (Add IntervalMap/Set), with missing files included.
The original commit was reverted in c151e8428a due missing files (thanks Kazu!).
2023-01-17 13:47:47 -08:00
Kazu Hirata
c151e8428a Revert "[ORC-RT] Add IntervalMap and IntervalSet collections."
This reverts commit ab59185fbfb15c9ce5a64e3aacd3a8c7f6a97621.

It looks like this commit is missing interval_set_test.cpp.
2023-01-17 13:36:03 -08:00
Lang Hames
ab59185fbf [ORC-RT] Add IntervalMap and IntervalSet collections.
IntervalMap is an optionally-coalescing map -- it uses half-open ranges as keys,
allows lookups based on elements of the ranges (returning an iterator to the
containing range) and optionally coalesces adjacent ranges that have the same
value.

IntervalSet is an optionally-coalescing set based on IntervalMap.

These collections will be used to store and lookup metadata section ranges,
e.g. unwind-info ranges.
2023-01-17 13:25:25 -08:00
Mitch Phillips
35b5499d72 Reland: [GWP-ASan] Add recoverable mode.
The GWP-ASan recoverable mode allows a process to continue to function
after a GWP-ASan error is detected. The error will continue to be
dumped, but GWP-ASan now has APIs that a signal handler (like the
example optional crash handler) can call in order to allow the
continuation of a process.

When an error occurs with an allocation, the slot used for that
allocation will be permanently disabled. This means that free() of that
pointer is a no-op, and use-after-frees will succeed (writing and
reading the data present in the page).

For heap-buffer-overflow/underflow, the guard page is marked as accessible
and buffer-overflows will succeed (writing and reading the data present
in the now-accessible guard page). This does impact adjacent
allocations, buffer-underflow and buffer-overflows from adjacent
allocations will no longer touch an inaccessible guard page. This could
be improved in future by having two guard pages between each adjacent
allocation, but that's out of scope of this patch.

Each allocation only ever has a single error report generated. It's
whatever came first between invalid-free, double-free, use-after-free or
heap-buffer-overflow, but only one.

Reviewed By: eugenis, fmayer

Differential Revision: https://reviews.llvm.org/D140173
2023-01-17 10:21:01 -08:00
Thurston Dang
fd9f04a555 tsan: fix broken aarch64_39/42 mappings and expand them
The aarch64 39- and 42-bit mappings were broken: mappings to meta and shadow were not fully invertible. This CL introduces a working set of mappings, and also increases the size of some app regions:
* aarch64, 39-bit (2^39 == 512GB):
 - Low: (Old) 4GB -> (New) 20GB
 - Mid: 4GB -> 20GB
 - Heap: 4GB -> 12GB
 - High: 8GB -> 12GB
* aarch64, 42-bit (2^42 == 4TB):
 - Low: 64GB -> 128GB
 - Mid: 4GB -> 88GB
 - Heap: 64GB -> 192GB
 - High: 64GB

Additionally, this CL improves the code comments for all the linux aarch64 mappings.

Differential Revision: https://reviews.llvm.org/D141640
2023-01-17 17:34:09 +00:00
Alex Brachet
6be602f79c [scudo] Fix -Wsign-compare warning 2023-01-17 17:02:50 +00:00
Rainer Orth
951cf656b2 [sanitizer_common] Don't intercept __tls_get_addr on Solaris
When building/testing ASan inside the GCC tree on Solaris while using GNU
`ld` instead of Solaris `ld`, a large number of tests SEGVs on both sparc
and x86 like this:

  Thread 2 received signal SIGSEGV, Segmentation fault.
  [Switching to Thread 1 (LWP 1)]
  0xfe014cfc in __sanitizer::atomic_load<__sanitizer::atomic_uintptr_t>
(a=0xfc602a58, mo=__sanitizer::memory_order_acquire) at
sanitizer_common/sanitizer_atomic_clang_x86.h:46
  46	      v = a->val_dont_use;
  1: x/i $pc
  => 0xfe014cfc
<_ZN11__sanitizer11atomic_loadINS_16atomic_uintptr_tEEENT_4TypeEPVKS2_NS_12memory_orderE+62>:
mov (%eax),%eax
  (gdb) bt
  #0 0xfe014cfc in __sanitizer::atomic_load<__sanitizer::atomic_uintptr_t>
(a=0xfc602a58, mo=__sanitizer::memory_order_acquire) at
sanitizer_common/sanitizer_atomic_clang_x86.h:46
  #1 0xfe0bd1d7 in __sanitizer::DTLS_NextBlock (cur=0xfc602a58) at
sanitizer_common/sanitizer_tls_get_addr.cpp:53
  #2 0xfe0bd319 in __sanitizer::DTLS_Find (id=1) at
sanitizer_common/sanitizer_tls_get_addr.cpp:77
  #3 0xfe0bd466 in __sanitizer::DTLS_on_tls_get_addr (arg_void=0xfeffd068,
res=0xfe602a18, static_tls_begin=0, static_tls_end=0) at
sanitizer_common/sanitizer_tls_get_addr.cpp:116
  #4 0xfe063f81 in __interceptor___tls_get_addr (arg=0xfeffd068) at
sanitizer_common/sanitizer_common_interceptors.inc:5501
  #5 0xfe0a3054 in __sanitizer::CollectStaticTlsBlocks (info=0xfeffd108,
size=40, data=0xfeffd16c) at
sanitizer_common/sanitizer_linux_libcdep.cpp:366
  #6  0xfe6ba9fa in dl_iterate_phdr () from /usr/lib/ld.so.1
  #7 0xfe0a3132 in __sanitizer::GetStaticTlsBoundary (addr=0xfe608020,
size=0xfeffd244, align=0xfeffd1b0) at
sanitizer_common/sanitizer_linux_libcdep.cpp:382
  #8 0xfe0a33f7 in __sanitizer::GetTls (addr=0xfe608020, size=0xfeffd244)
at sanitizer_common/sanitizer_linux_libcdep.cpp:482
  #9 0xfe0a34b1 in __sanitizer::GetThreadStackAndTls (main=true,
stk_addr=0xfe608010, stk_size=0xfeffd240, tls_addr=0xfe608020,
tls_size=0xfeffd244) at sanitizer_common/sanitizer_linux_libcdep.cpp:565

The address being accessed is unmapped.  However, even when the tests
`PASS` with Solaris `ld`, `ASAN_OPTIONS=verbosity=2` shows

  ==6582==__tls_get_addr: Can't guess glibc version

Given that that the code is stricly `glibc`-specific according to
`sanitizer_tls_get_addr.h`, there seems little point in using the
interceptor on non-`glibc` targets.

That's what this patch does.  Tested on `i386-pc-solaris2.11` and
`sparc-sun-solaris2.11` inside the GCC tree.

Differential Revision: https://reviews.llvm.org/D141385
2023-01-17 09:41:00 +01:00
Lang Hames
9afe78d1fc [ORC-RT] Fix a typo in file header. 2023-01-15 22:25:10 -08:00
Kirill Stoimenov
c68926d7e6 [HWASAN][Fuchsia] Fixed Fuchsia build.
Reviewed By: kstoimenov

Differential Revision: https://reviews.llvm.org/D141771
2023-01-14 18:25:21 +00:00
Haojian Wu
e2d0eeba43 Fix a -Wgnu-designator warning, NFC. 2023-01-14 17:46:39 +01: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
Khem Raj
dc9c41125c [hwasan] Replace j __interceptor_sigsetjmp instead with tail for RISC-V
R_RISCV_JAL referencing a preemptible symbol is disallowed with ld.lld and binutils 2.40 (https://sourceware.org/PR28509)

    riscv64-yoe-linux-ld: relocation R_RISCV_JAL against `__interceptor_sigsetjmp' which may bind externally can not be used when making a shared object; recompile with -fPIC

Reviewed By: kito-cheng, MaskRay

Differential Revision: https://reviews.llvm.org/D141656
2023-01-13 17:44:38 -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
Lang Hames
217fd59cc5 [ORC] Introduce deferred allocation-actions scheme for MachOPlatform bootstrap.
This patch modifies the MachOPlatform bootstrap process to record allocation
actions for ORC runtime platform support code in a "deferred actions" vector
rather than attaching it to the corresponding LinkGraphs up-front. The deferred
allocation-actions are run after all the platform support code has been loaded
by attaching them to a separate "bootstrap-complete" graph.

This change should allow the mach-o platform support code in the ORC runtime to
use advanced mach-o platform features (e.g. static inits, TLVs), provided that
the support code does not use these features at runtime before the bootstrap
process completes, or after the shutdown process starts. This is a nice
improvement in and of itself but is motivated by specific future plans: we
want to start recording unwind info in the mach-o platform state object*, and
the recording functions will have their own frame info that needs registering.
The deferred allocation-actions scheme allows for this.

* The plan is to add a new unwind-info-lookup path to libunwind to allow it to
  call back to the ORC runtime to find unwind sections. This will simplify the
  implementation of support for JIT'd compact-unwind info.
2023-01-13 16:15:57 -08:00
Florian Mayer
ee6536b936 [NFC] [scudo] actually fix DCHECK now 2023-01-13 10:24:45 -08:00
Florian Mayer
1f58aa3797 [NFC] [scudo] fix mistake in DCHECK
sorry, my test build (and all the pre-merge bots) did not exercise this.
2023-01-13 10:20:42 -08:00
Blue Gaston
87850e9bb1 [Sanitizer] Clean up SANITIZER_CAN_USE_ALLOCATOR64 logic
Update: A change to this code recently broke our bots after this change enabled the 64 bit allocator for defined(aarch64): https://reviews.llvm.org/D137136

We added logic initially to get our test passing, but want to further clean up this code to enable MacOS to use allocator64 and increase readability and clarity of the logic.

rdar://103647896

Differential Revision: https://reviews.llvm.org/D141171
2023-01-13 09:57:34 -08:00
Florian Mayer
47bd46e20c allocation_ring_buffer_size to 0 disables stack collection
Reviewed By: hctim, eugenis

Differential Revision: https://reviews.llvm.org/D141631
2023-01-13 09:56:12 -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 f001e50f955c3cdf2deb79e38a9fd19c9a781882.
This reverts commit 2924189233fdb724453ead4b94595107b1ce9cfa.
2023-01-12 17:32:40 -08:00
Alex Brachet
f001e50f95 [lsan] Fix build for Fuchsia after D140039 2023-01-13 00:47:46 +00:00
Mitch Phillips
7cc12cb6c8 Revert "[GWP-ASan] Add recoverable mode."
This reverts commit 90a9beb7cc9755791caa23dfc4e36bc544e98ed3.

Reason: Broke an internal build.
2023-01-12 15:59:58 -08:00
Mitch Phillips
d99120939e Revert "[GWP-ASan] Fix test to work with Fuchsia's zxtest"
This reverts commit 64138725e4cf0ab5e3f9c0dba38e11ce3d3b4017.

Parent change https://reviews.llvm.org/D140173 broke an internal build.
I'll land this bit as part of the re-land for
https://reviews.llvm.org/D140173.
2023-01-12 15:59:58 -08:00
Mitch Phillips
4c0b3964cb Revert "[GWP-ASan] Fix 6413872"
This reverts commit df87e62cbd4b5090b5349247d29457706d2ac4e8.

Parent change https://reviews.llvm.org/D140173 broke an internal build.
I'll integrate this patch into the re-land for
https://reviews.llvm.org/D140173.
2023-01-12 15:59:58 -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
Florian Mayer
91063baa43 [NFC] [scudo] avoid casting in a circle 2023-01-12 14:47:03 -08:00
Luke Nicholson
3fb470fe67 [scudo] Fix RingBuffer initialization.
Several map implementations require that map calls provide a page
aligned size.

Reviewed By: fmayer

Differential Revision: https://reviews.llvm.org/D141630
2023-01-12 13:10:27 -08:00
Vitaly Buka
b55ab96ec8 [tsan] Remove rtl-old
Reviewed By: dvyukov, MaskRay

Differential Revision: https://reviews.llvm.org/D141455
2023-01-11 18:18:11 -08:00
Florian Mayer
ed864f0a09 [NFC] fix more type conversion issues 2023-01-11 17:24:29 -08:00
Florian Mayer
9a8e461648 [NFC] fix type conversion issue 2023-01-11 17:03:08 -08:00
Florian Mayer
2426cc773a Dynamically allocate scudo allocation buffer.
This is so we can increase the buffer size for finding elusive bugs.

Tested by hand with this program

```

int main(int argc, char** argv) {
  if (argc < 2)
    return 1;
  int n = atoi(argv[1]);
  char* x = reinterpret_cast<char*>(malloc(1));
  *((volatile char*)x) = 1;
  free(x);
  for (; n > 0; --n) {
    char* y = reinterpret_cast<char*>(malloc(1024));
    *((volatile char*)y) = 1;
    free(y);
  }
  *x = 2;
  return 0;
}
```

SCUDO_OPTIONS=allocation_ring_buffer_size=30000 ./uaf 1000000
-> no allocation trace
SCUDO_OPTIONS=allocation_ring_buffer_size=30000000 ./uaf 1000000
-> allocation trace

Reviewed By: hctim, eugenis

Differential Revision: https://reviews.llvm.org/D140932
2023-01-11 16:53:12 -08:00
Alex Brachet
df87e62cbd [GWP-ASan] Fix 6413872
Use testing not zxtest in non-Fuchsia case
2023-01-11 23:43:27 +00:00
Alex Brachet
64138725e4 [GWP-ASan] Fix test to work with Fuchsia's zxtest 2023-01-11 23:16:19 +00:00
Mitch Phillips
90a9beb7cc [GWP-ASan] Add recoverable mode.
The GWP-ASan recoverable mode allows a process to continue to function
after a GWP-ASan error is detected. The error will continue to be
dumped, but GWP-ASan now has APIs that a signal handler (like the
example optional crash handler) can call in order to allow the
continuation of a process.

When an error occurs with an allocation, the slot used for that
allocation will be permanently disabled. This means that free() of that
pointer is a no-op, and use-after-frees will succeed (writing and
reading the data present in the page).

For heap-buffer-overflow/underflow, the guard page is marked as accessible
and buffer-overflows will succeed (writing and reading the data present
in the now-accessible guard page). This does impact adjacent
allocations, buffer-underflow and buffer-overflows from adjacent
allocations will no longer touch an inaccessible guard page. This could
be improved in future by having two guard pages between each adjacent
allocation, but that's out of scope of this patch.

Each allocation only ever has a single error report generated. It's
whatever came first between invalid-free, double-free, use-after-free or
heap-buffer-overflow, but only one.

Reviewed By: eugenis, fmayer

Differential Revision: https://reviews.llvm.org/D140173
2023-01-11 13:11:23 -08:00