16433 Commits

Author SHA1 Message Date
Han Zhu
7a2f3d1886 [NFC] Update tsan_rtl.h comment after D142039 2023-01-24 10:47:02 -08:00
Marco Elver
5265adc737 [SanitizerBinaryMetadata] Declare callbacks extern weak
Declare callbacks extern weak (if no existing declaration exists), and
only call if the function address is non-null.

This allows to attach semantic metadata to binaries where no user of
that metadata exists, avoiding to have to link empty stub callbacks.

Once the binary is linked (statically or dynamically) against a tool
runtime that implements the callbacks, the respective callbacks will be
called. This vastly simplifies gradual deployment of tools using the
metadata, esp. avoiding having to recompile large codebases with
different compiler flags (which negatively impacts compiler caches).

Reviewed By: dvyukov, vitalybuka

Differential Revision: https://reviews.llvm.org/D142408
2023-01-24 12:54:20 +01:00
Vitaly Buka
5b190c4a2d Revert "[profile] Disable test which needs update after D141512"
Work around with -fno-slp-vectorize.

This reverts commit 31260a4ce43aab7c04f501095a9032de063ccaf9.
2023-01-23 17:35:38 -08:00
Kirill Stoimenov
2b0322ed56 [HWASAN] Fix PointsIntoChunk to untag pointers. Also added some checks where we know that the pointer should be untagged.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D142389
2023-01-24 00:35:17 +00:00
Kirill Stoimenov
eba322e9d7 [Sanitizer] Make GetBlockBeginFastLocked parameters const.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D142402
2023-01-24 00:01:35 +00:00
Kirill Stoimenov
cf6c43189f [HWASAN] Fix memory leaks in tests.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D142383
2023-01-23 23:59:07 +00:00
Vitaly Buka
31260a4ce4 [profile] Disable test which needs update after D141512 2023-01-23 14:57:01 -08:00
Han Zhu
84bec0a219 [tsan] Always initialize tsan when building shared lib
Differential Revision: https://reviews.llvm.org/D142039
2023-01-23 10:30:18 -08:00
Dimitry Andric
abf399737e Revert "[compiler-rt][builtins] Skip building (b)float16 support on i386-freebsd"
This reverts commit 45368c75582f0bded1f06d5c82c1f2ee023fb186.

There were some unexpected failures in aarch64 and arm buildbots, I will
have to investigate why these suddenly fell over.
2023-01-23 11:22:28 +01:00
Dimitry Andric
45368c7558 [compiler-rt][builtins] Skip building (b)float16 support on i386-freebsd
Since bfloat16 and float16 support is not available for i386-freebsd,
the `truncdfbf2.c` and `truncsfbf2.c` builtin sources should be skipped
when targeting that platform, and `COMPILER_RT_HAS_FLOAT16` should not
be defined.

However, the CMake configuration stage runs its tests with the default
target, which normally is amd64-freebsd, so it will detect both bfloat16
and float16 support.

Move adding of the `COMPILER_RT_HAS_FLOAT16` define to the `foreach()`
loop where all the supported architectures are handled, and do not
enable it when targeting i386-freebsd.

Also remove the bfloat16 sources from the `i386_SOURCES` list, when
targeting i386-freebsd.

Differential Revision: https://reviews.llvm.org/D136044
2023-01-22 22:16:51 +01:00
Dmitry Vyukov
f7f01599ec sanmd: refine selection of functions for UAR checking
There are no intrinsic functions that leak arguments.
If the called function does not return, the current function
does not return as well, so no possibility of use-after-return.
Sanitizer function also don't leak or don't return.
It's safe to both pass pointers to local variables to them
and to tail-call them.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D142190
2023-01-21 09:51:15 +01:00
Arthur Eubanks
2329a9266d Revert "sanmd: refine selection of functions for UAR checking"
This reverts commit 9d4f1a9eff27716069dc6a2d991baa228c197b85.

Breaks under -DCOMPILER_RT_BUILD_SANITIZERS=OFF
2023-01-20 13:40:50 -08:00
David Carlier
b4c840e70b [Sanitizers] intercept hexdump on FreeBSD.
Reviewers: vitalybuka
Reviewed-By: vitalybuka

Differential Revision: https://reviews.llvm.org/D110471
2023-01-20 18:00:38 +00:00
Dmitry Vyukov
9d4f1a9eff sanmd: refine selection of functions for UAR checking
There are no intrinsic functions that leak arguments.
If the called function does not return, the current function
does not return as well, so no possibility of use-after-return.
Sanitizer function also don't leak or don't return.
It's safe to both pass pointers to local variables to them
and to tail-call them.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D142190
2023-01-20 16:22:37 +01:00
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
Arthur Eubanks
1f3f3c0ea7 Revert "Reland [pgo] Avoid introducing relocations by using private alias"
This reverts commit da5a8d14b8cc6cea16ee0929413c0672b47c93d9.

Causes more duplicate symbol errors, see https://bugs.chromium.org/p/chromium/issues/detail?id=1408161.
2023-01-19 10:20:38 -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
Vitaly Buka
0ce4fca316 [NFC][sanitizers] Add COMPILER_RT_HAS_WTHREAD_SAFETY_*_FLAG 2023-01-18 17:27:10 -08:00
Paul Kirth
da5a8d14b8 Reland [pgo] Avoid introducing relocations by using private alias
In many cases, we can use an alias to avoid a symbolic relocations,
instead of using the public, interposable symbol. When the instrumented
function is in a COMDAT, we can use a hidden alias, and still avoid
references to discarded sections.

Previous versions of this patch allowed the compiler to name the
generated alias, but that would only be valid when the functions were
local. Since the alias may be used across TUs we use a more
deterministic naming convention, and add a ".local" suffix to the alias
name just as we do for relative vtables aliases.

https://reviews.llvm.org/rG20894a478da224bdd69c91a22a5175b28bc08ed9
removed an incorrect assertion on Mach-O which caused assertion failures in LLD.

We addressed the link errors under ThinLTO + PGO + CFI by being more
selective about which comdat functions can be given aliases.
Specifically, we now do not emit an alias in the case of a comdat
function with hidden visibility, since the alias would have the same
linkage and visibility, giving no benefit over using the symbol
directly. This also prevents LowerTypeTest from incorrectly updating the
dangling alias after GlobalOpt replaces uses, and introducing a
duplicate symbol.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D137982
2023-01-18 23:56:35 +00: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
Arthur Eubanks
c43f38ec63 Revert ""Reland "[pgo] Avoid introducing relocations by using private alias""
This reverts commit 6e5cbc097a5ac7fa95a8f425af8b03958151c763.

Causes link errors, see http://go/crb/1408161.
2023-01-17 15:41:26 -08:00
usama hameed
4729f6e03a [CompilerRT] Remove sanitizer support for i386 iossim
Summary:
This patch removes building sanitizers for i386 iossim. This is to reduce the toolchain size.
Reviewers:

Subscribers:
2023-01-17 14:37:06 -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