Commit Graph

14815 Commits

Author SHA1 Message Date
Kostya Kortchinsky 56a9effc42 [scudo] Skip AllocAfterFork test on machines with low max_map_count
Reducing the number of iterations in that test with D111342 helped,
but the failure still occured flakily when the test is ran as part
of a large test suite.

Reducing further the number of iterations might not be good enough,
so we will skip the test if the `max_map_count` variable can be
read, and if lower than a given threshold.

Differential Revision: https://reviews.llvm.org/D111465
2021-10-11 10:33:47 -07:00
Andrew Browne 50a08e2c6d [DFSan] Fix flakey release_shadow_space.c accounting for Origin chains.
Test sometimes fails on buildbot (after two non-Origins executions):

/usr/bin/ld: warning: Cannot export local symbol 'dfsan_flush'
RSS at start: 4620, after mmap: 107020, after mmap+set label: 209424, after fixed map: 4624, after another mmap+set label: 209424, after munmap: 4624
/usr/bin/ld: warning: Cannot export local symbol 'dfsan_flush'
RSS at start: 4620, after mmap: 107020, after mmap+set label: 209424, after fixed map: 4624, after another mmap+set label: 209424, after munmap: 4624
/usr/bin/ld: warning: Cannot export local symbol 'dfsan_flush'
RSS at start: 4620, after mmap: 107020, after mmap+set label: 317992, after fixed map: 10792, after another mmap+set label: 317992, after munmap: 10792
release_shadow_space.c.tmp: /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/dfsan/release_shadow_space.c:91: int main(int, char **): Assertion `after_fixed_mmap <= before + delta' failed.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D111522
2021-10-11 00:35:12 -07:00
Vitaly Buka 9ccb6024a0 [NFC][sanitizer] Add a few consts 2021-10-10 22:59:43 -07:00
Vitaly Buka 982bfec8f0 [NFC][sanitizer] Clang-format sanitizer_flat_map.h 2021-10-10 22:23:49 -07:00
Vitaly Buka eff6b369bf [NFC][sanitizer] Add constexpr to FlatMap::size 2021-10-10 22:23:48 -07:00
Vitaly Buka 76b7784bcd [NFC][sanitizer] Rename ByteMap to Map 2021-10-10 22:23:48 -07:00
Vitaly Buka 74277e254c [NFC] Allow to include sanitizer_allocator_bytemap.h 2021-10-10 22:23:48 -07:00
luxufan 590326382d [Orc] Support atexit in Orc(JITLink)
There is a bug reported at https://bugs.llvm.org/show_bug.cgi?id=48938

After looking through the glibc, I found the `atexit(f)` is the same as `__cxa_atexit(f, NULL, NULL)`. In orc runtime, we identify different JITDylib by their dso_handle value, so that a NULL dso_handle is invalid. So in this patch, I added a `PlatformJDDSOHandle` to ELFNixRuntimeState, and functions which are registered by atexit will be registered at PlatformJD.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D111413
2021-10-09 12:25:47 +08:00
Vitaly Buka 6800222068 [NFC][sanitizer] Add const to ChainedOriginDepotNode methods 2021-10-08 14:27:05 -07:00
Vitaly Buka df43d419de [NFC][sanitizer] Remove includes from header 2021-10-08 14:27:05 -07:00
Vitaly Buka d1aaef4296 [NFC][sanitizer] Parametrize PersistentAllocator with type 2021-10-08 14:07:05 -07:00
Vitaly Buka d2aa34e8d9 [NFC][sanitizer] Move ChainedOriginDepotNode into cpp file 2021-10-08 13:43:29 -07:00
Vitaly Buka 05d46f627c [NFC][sanitizer] Remove sanitizer_persistent_allocator.cpp
We need to make it a template
2021-10-08 13:43:28 -07:00
Andrew Browne 61ec2148c5 [DFSan] Remove -dfsan-args-abi support in favor of TLS.
ArgsABI was originally added in https://reviews.llvm.org/D965

Current benchmarking does not show a significant difference.
There is no need to maintain both ABIs.

Reviewed By: pcc

Differential Revision: https://reviews.llvm.org/D111097
2021-10-08 11:18:36 -07:00
Fangrui Song b3024ac084 [sanitizer] Use one #if instead of 3 nested #if after D111185 2021-10-08 10:31:57 -07:00
H.J. Lu c960c8c339 Reland [sanitizer] Support Intel CET
1. Include <cet.h> in sanitizer_common/sanitizer_asm.h, if it exists, to
mark Intel CET support when Intel CET is enabled.
2. Define _CET_ENDBR as empty if it isn't defined.
3. Add _CET_ENDBR to function entries in assembly codes so that ENDBR
instruction will be generated when Intel CET is enabled.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D111185
2021-10-08 10:22:39 -07:00
David Spickett 30677a043c [compiler-rt][fuzzer] Re-enable flags test on AArch64 Linux
This is now passing after bots were upgraded to Ubuntu Focal,
which comes with ld 2.34.
2021-10-08 08:55:22 +00:00
Arthur Eubanks d4c1f222f2 Revert "[sanitizer] Support Intel CET"
This reverts commit fdf4c03522.

Breaks macOS bots, e.g. https://crbug.com/1257863.
Still figuring out if this is actually supported on macOS. Other places
that include <cet.h> only do so on Linux.
2021-10-07 21:03:12 -07:00
Vitaly Buka ef85ea9a4f [msan] Print both shadow and user address
before:
00 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 00
Shadow map of [0x211000000005, 0x21100000012e), 297 bytes:
now:
0x2f60d213ac10[0x7f60d213ac10]  00 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 00
Shadow map [0x211000000005, 0x21100000012e) of [0x711000000005, 0x711000000135), 297 bytes:

Differential Revision: https://reviews.llvm.org/D111261
2021-10-07 17:56:46 -07:00
Kostya Kortchinsky 6727832c32 [scudo] Reduce the scope of AllocAfterFork
`ScudoWrappersCppTest.AllocAfterFork` was failing obscurely sometimes.
Someone pointed us to Linux's `vm.max_map_count` that can be
significantly lower on some machines than others. It turned out that
on a machine with that setting set to 65530, some `ENOMEM` errors
would occur with `mmap` & `mprotect` during that specific test.

Reducing the number of times we fork, and the maximum size allocated
during that test makes it pass on those machines.

Differential Revision: https://reviews.llvm.org/D111342
2021-10-07 14:01:58 -07:00
Vitaly Buka 0332d5d14d [NFC][sanitizer] Annotate a few branches in StackDepot 2021-10-07 13:54:02 -07:00
Vitaly Buka c86e7ec42c [sanitizer] Remove traces from the header
This will simplify removing id proposed by @dvyukov on D111183
Also now we have more flexiliby for traces compressio they
are not interleaving with uncompressable headers.

Depends on D111256.

Differential Revision: https://reviews.llvm.org/D111274
2021-10-07 13:54:01 -07:00
Vitaly Buka 8f3e52538d [NFC][sanitizer] Remove global PersistentAllocator
This way is easier to track memory usage and do other
incremental refactorings.

Differential Revision: https://reviews.llvm.org/D111256
2021-10-07 13:54:01 -07:00
Vitaly Buka 78c5754813 [sanitizer] Uninline slow path of PersistentAllocator::alloc 2021-10-07 13:54:01 -07:00
Leonard Chan 7afd956e0f [compiler-rt][memprof] Disambiguate checks for __tls_get_addr in output
TestCases/stress_dtls.c was failing when we ran memprof tests for the first
time. The test checks that __tls_get_addr is not in the output for the last
run when it is possible for the interceptor __interceptor___tls_get_addr to
be in the output from stack dumps. The test actually intends to check that
the various __tls_get_addr reports don't get emitted when intercept_tls_get_addr=0.
This updates the test to also check for the following `:` and preceding `==`
which should ignore the __interceptor___tls_get_addr interceptor.

Differential Revision: https://reviews.llvm.org/D111192
2021-10-06 13:54:42 -07:00
Dan Liew 9ed6b1cd97 Disable SANITIZER_CHECK_DEADLOCKS on Darwin platforms.
Although THREADLOCAL variables are supported on Darwin they cannot be
used very early on during process init (before dyld has set it up).

Unfortunately the checked lock is used before dyld has setup TLS leading
to an abort call (`_tlv_boostrap()` is never supposed to be called at
runtime).

To avoid this problem `SANITIZER_CHECK_DEADLOCKS` is now disabled on
Darwin platforms. This fixes running TSan tests (an possibly other
Sanitizers) when `COMPILER_RT_DEBUG=ON`.

For reference the crashing backtrace looks like this:

```
* thread #1, stop reason = signal SIGABRT
  * frame #0: 0x00000002044da0ae dyld`__abort_with_payload + 10
    frame #1: 0x00000002044f01af dyld`abort_with_payload_wrapper_internal + 80
    frame #2: 0x00000002044f01e1 dyld`abort_with_payload + 9
    frame #3: 0x000000010c989060 dyld_sim`abort_with_payload + 26
    frame #4: 0x000000010c94908b dyld_sim`dyld4::halt(char const*) + 375
    frame #5: 0x000000010c988f5c dyld_sim`abort + 16
    frame #6: 0x000000010c96104f dyld_sim`dyld4::APIs::_tlv_bootstrap() + 9
    frame #7: 0x000000010cd8d6d2 libclang_rt.tsan_iossim_dynamic.dylib`__sanitizer::CheckedMutex::LockImpl(this=<unavailable>, pc=<unavailable>) at sanitizer_mutex.cpp:218:58 [opt]
    frame #8: 0x000000010cd8a0f7 libclang_rt.tsan_iossim_dynamic.dylib`__sanitizer::Mutex::Lock() [inlined] __sanitizer::CheckedMutex::Lock(this=0x000000010d733c90) at sanitizer_mutex.h:124:5 [opt]
    frame #9: 0x000000010cd8a0ee libclang_rt.tsan_iossim_dynamic.dylib`__sanitizer::Mutex::Lock(this=0x000000010d733c90) at sanitizer_mutex.h:162:19 [opt]
    frame #10: 0x000000010cd8a0bf libclang_rt.tsan_iossim_dynamic.dylib`__sanitizer::GenericScopedLock<__sanitizer::Mutex>::GenericScopedLock(this=0x000000030c7479a8, mu=<unavailable>) at sanitizer_mutex.h:364:10 [opt]
    frame #11: 0x000000010cd89819 libclang_rt.tsan_iossim_dynamic.dylib`__sanitizer::GenericScopedLock<__sanitizer::Mutex>::GenericScopedLock(this=0x000000030c7479a8, mu=<unavailable>) at sanitizer_mutex.h:363:67 [opt]
    frame #12: 0x000000010cd8985b libclang_rt.tsan_iossim_dynamic.dylib`__sanitizer::LibIgnore::OnLibraryLoaded(this=0x000000010d72f480, name=0x0000000000000000) at sanitizer_libignore.cpp:39:8 [opt]
    frame #13: 0x000000010cda7aaa libclang_rt.tsan_iossim_dynamic.dylib`__tsan::InitializeLibIgnore() at tsan_interceptors_posix.cpp:219:16 [opt]
    frame #14: 0x000000010cdce0bb libclang_rt.tsan_iossim_dynamic.dylib`__tsan::Initialize(thr=0x0000000110141400) at tsan_rtl.cpp:403:3 [opt]
    frame #15: 0x000000010cda7b8e libclang_rt.tsan_iossim_dynamic.dylib`__tsan::ScopedInterceptor::ScopedInterceptor(__tsan::ThreadState*, char const*, unsigned long) [inlined] __tsan::LazyInitialize(thr=0x0000000110141400) at tsan_rtl.h:665:5 [opt]
    frame #16: 0x000000010cda7b86 libclang_rt.tsan_iossim_dynamic.dylib`__tsan::ScopedInterceptor::ScopedInterceptor(this=0x000000030c747af8, thr=0x0000000110141400, fname=<unavailable>, pc=4568918787) at tsan_interceptors_posix.cpp:247:3 [opt]
    frame #17: 0x000000010cda7bb9 libclang_rt.tsan_iossim_dynamic.dylib`__tsan::ScopedInterceptor::ScopedInterceptor(this=0x000000030c747af8, thr=<unavailable>, fname=<unavailable>, pc=<unavailable>) at tsan_interceptors_posix.cpp:246:59 [opt]
    frame #18: 0x000000010cdb72b7 libclang_rt.tsan_iossim_dynamic.dylib`::wrap_strlcpy(dst="\xd2", src="0xd1d398d1bb0a007b", size=20) at sanitizer_common_interceptors.inc:7386:3 [opt]
    frame #19: 0x0000000110542b03 libsystem_c.dylib`__guard_setup + 140
    frame #20: 0x00000001104f8ab4 libsystem_c.dylib`_libc_initializer + 65
    ...
```

rdar://83723445

Differential Revision: https://reviews.llvm.org/D111243
2021-10-06 12:05:33 -07:00
Leonard Chan 77d5ccdc6f [compiler-rt][test] Add shared_unwind requirement
When using a static libunwind, the check_memcpy.c can fail because it checks
that tsan intercepted all memcpy/memmoves in the final binary. Though if the
static libunwind is not instrumented, then this will fail because it may contain
regular memcpy/memmoves.

This adds a new REQUIRES check for ensuring that this test won't run unless a
dynamic libunwind.so is provided.

Differential Revision: https://reviews.llvm.org/D111194
2021-10-06 11:10:36 -07:00
Vitaly Buka b5b1b3aef1 [sanitizer] Switch to StackDepotNode to 64bit hash
Now we can avoid scanning the stack on fast path.
The price is the false stack trace with probability of the hash collision.
This increase performance of lsan by 6% and pre-requirement for stack compression.

Depends on D111182.

Reviewed By: morehouse, dvyukov

Differential Revision: https://reviews.llvm.org/D111183
2021-10-06 10:45:11 -07:00
H.J. Lu fdf4c03522 [sanitizer] Support Intel CET
1. Include <cet.h> in sanitizer_common/sanitizer_asm.h to mark Intel CET
support when Intel CET is enabled.
2. Add _CET_ENDBR to function entries in assembly codes so that ENDBR
instruction will be generated when Intel CET is enabled.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D111185
2021-10-06 10:12:50 -07:00
David Spickett f8f1bb7462 [compiler-rt][lsan] Add backup AArch64 register for use_registers test
On Ubuntu Focal x13 is used by something in the process of calling
sched_yield. Causing the test to fail depending on when the thread
is stopped.

Adding x14 works around this and the test passes consistently.

Not switching to only x14 because that could make other platforms
fail. With both we'll always find at least one and even if both
values are present we'll only get one report.

Reviewed By: oontvoo, vitalybuka

Differential Revision: https://reviews.llvm.org/D110931
2021-10-06 09:45:53 +01:00
Dmitry Vyukov 24af1ba605 tsan: don't instrument runtime callbacks in tests
These runtime callbacks are supposed to be non-instrumented,
we can't handle runtime recursion well, nor can we afford
explicit recursion checks in the hot functions (memory access,
function entry/exit).
It used to work (not crash), but it won't work with the new runtime.
Mark all runtime callbacks as non-instrumented.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D111157
2021-10-06 08:44:04 +02:00
David Carlier 18a7ebda99 [Sanitizers] intercept md5 and sha* apis on FreeBSD.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D110989
2021-10-06 06:01:50 +01:00
Vitaly Buka 3129aa5caf [NFC][sanitizers] Add StackDepotBase Node::hash_type
Depends on D111177.

Differential Revision: https://reviews.llvm.org/D111182
2021-10-05 20:54:06 -07:00
Vitaly Buka 5ae9a3e4bf [NFC][sanitizer] Add MurMur2Hash64Builder
Depends on D111176.

Differential Revision: https://reviews.llvm.org/D111177
2021-10-05 20:54:06 -07:00
Vitaly Buka dc603b0e53 [NFC][sanitizer] Add basic hash test
Differential Revision: https://reviews.llvm.org/D111176
2021-10-05 20:54:06 -07:00
Zequan Wu 4e8efff53e [Profile] Add missing fflush in __llvm_profile_set_file_object 2021-10-05 15:41:51 -07:00
Vitaly Buka 84afd02525 [sanitizer] Fix Android bot
We don't need to check for equality, we need to check
that storage is large enough.
2021-10-05 13:08:16 -07:00
Vitaly Buka 6fab808f6f [NFC][sanitizer] Combine MSAN data in single field
Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D111118
2021-10-05 12:34:02 -07:00
Petr Hosek 24c615fa6b [InstrProfData] Bump the raw profile version to 8
This is to account for the change that made CountersPtr in __profd_
relative which landed in a1532ed275.
That change hasn't updated the raw profile version, and while the
profile layout stayed the same, profiles generated by tip-of-tree
LLVM are incompatible with 13.x tooling.

Differential Revision: https://reviews.llvm.org/D111123
2021-10-05 09:57:56 -07:00
Dmitry Vyukov c483140f3c tsan: improve detection of stack/tls races
Print meaningful stack frames for stack/tls races
(instead of PC 1/2 that don't symbolize).

Imitate stack/tls writes after we create and initialize
the new thread, otherwise the races are not detected.

This is re-submit of the following reverted commits,
but without tests as they failed on a number of OSes/arches:
"tsan: fix and test detection of TLS races"
"tsan: fix tls_race3 test on darwin"
"tsan: print a meaningful frame for stack races"

Differential Revision: https://reviews.llvm.org/D111147
2021-10-05 15:32:39 +02:00
Dmitry Vyukov a0ed71ff29 tsan: make cur_thread_init return cur_thread
Whenever we call cur_thread_init, we call cur_thread on the next line.
So make cur_thread_init return the current thread directly.
Makes code a bit shorter, does not affect codegen.

Reviewed By: vitalybuka, melver

Differential Revision: https://reviews.llvm.org/D110384
2021-10-05 15:24:52 +02:00
Leonard Chan 993555beb8 [compiler-rt][scudo] Check for failing prctl call
A bunch of MTE tests like ./ScudoUnitTest-aarch64-Test/MemtagTest.StoreTags
can fail on aarch64-linux if the kernel doesn't support the tagged address ABI. It looks like
the call to prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0) can return -1, which
casted to an unsigned int and masked will return a value not equal to
PR_MTE_TCF_NONE, meaning systemDetectsMemoryTagFaultsTestOnly can return an incorrect value.

This updates the check to account for a failing prctl call.

Differential Revision: https://reviews.llvm.org/D110888
2021-10-04 13:14:20 -07:00
Amy Kwan 83539d73f9 Fix msan/tests/msan_test.cpp due to -Wbitwise-instead-of-logical
The LE Power sanitizer bot fails when testing standalone compiler-rt due to
an MSAN test warning introduced by -Wbitwise-instead-of-logical. As this option
along with -Werror is enabled on the bot, the test failure occurs.
This patch updates msan_test.cpp to fix the warning introduced by the
-Wbitwise-instead-of-logical.
2021-10-04 12:58:12 -05:00
Hans Wennborg c7bd643599 [libFuzzer] Use octal instead of hex escape sequences in PrintASCII
Previously, PrintASCII would print the string "\ta" as "\x09a". However,
in C/C++ those strings are not the same: the trailing 'a' is part of the
escape sequence, which means it's equivalent to "\x9a". This is an
annoying quirk of the standard. (See
https://eel.is/c++draft/lex.ccon#nt:hexadecimal-escape-sequence)

To fix this, output three-digit octal escape sequences instead. Since
octal escapes are limited to max three digits, this avoids the problem
of subsequent characters unintentionally becoming part of the escape
sequence.

Dictionary files still use the non-C-compatible hex escapes, but I
believe we can't change the format since it comes from AFL, and
libfuzzer never writes such files, it only has to read them, so they're
not affected by this change.

Differential revision: https://reviews.llvm.org/D110920
2021-10-04 11:29:54 +02:00
Dan Liew d6a4294d13 Use standard separator for TSan options in `stress.cpp` test case.
Use of space as a separator for options is problematic for wrapper
scripts (i.e. implementations of `%run`) that have to marshall
environment variables to target different than the host.

Rather than requiring every implementation of `%run` to support spaces
in `TSAN_OPTIONS` it is simpler to fix this single test case.

rdar://83637067

Differential Revision: https://reviews.llvm.org/D110967
2021-10-02 21:11:18 -07:00
Amy Kwan 103c1bd118 Revert "tsan: fix and test detection of TLS races"
This reverts commit b4c1e5cb73.

Reverting this as it contains a test that is currently failing on the PPC BE bots.
2021-10-01 16:42:31 -05:00
Amy Kwan 8b1984bb8c Revert "tsan: fix tls_race3 test on darwin"
This reverts commit ade5023c54.

Reverting this commit as it is dependent on a test breaking the PPC BE bots.
2021-10-01 16:42:31 -05:00
Amy Kwan 2df1019576 Revert "tsan: print a meaningful frame for stack races"
This reverts commit ccc83ac7c5.

Reverting this commit as it is dependent on additional commits breaking the
PPC BE bots.
2021-10-01 16:42:30 -05:00
Zequan Wu ab694cd845 [Profile] Add a warning when lock file failed in __llvm_profile_set_file_object with continuous mode 2021-10-01 14:37:09 -07:00
ZijunZhao 0e8862901c revert tsan part for investigation 2021-10-01 18:52:36 +00:00