Commit Graph

13930 Commits

Author SHA1 Message Date
Jianzhou Zhao bf4e1cf80a Revert "[sanitizer_common] Recycle StackDepot memory"
This reverts commit 78804e6b20.
2021-05-05 00:57:34 +00:00
Jianzhou Zhao 1fb612d060 [dfsan] Add a DFSan allocator
This is a part of https://reviews.llvm.org/D101204

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D101666
2021-05-05 00:51:45 +00:00
Jianzhou Zhao 78804e6b20 [sanitizer_common] Recycle StackDepot memory
This relates to https://reviews.llvm.org/D95835.

In DFSan origin tracking we use StackDepot to record
stack traces and origin traces (like MSan origin tracking).

For at least two reasons, we wanted to control StackDepot's memory cost
1) We may use DFSan origin tracking to monitor programs that run for
   many days. This may eventually use too much memory for StackDepot.
2) DFSan supports flush shadow memory to reduce overhead. After flush,
   all existing IDs in StackDepot are not valid because no one will
   refer to them.
2021-05-05 00:51:45 +00:00
Jianzhou Zhao 36cec26b38 [dfsan] move dfsan_flags.h to cc files
D101666 needs this change.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D101857
2021-05-04 22:54:02 +00:00
Matt Morehouse 84bf107d50 [libFuzzer] Disable non-exec-time test again.
It was previously disabled for the past 6+ months.  I tried to re-enable
it after some deflaking, but it still fails occasionally.
2021-05-04 10:51:46 -07:00
Matt Morehouse 632ee38513 [libFuzzer] Further deflake exec-time test.
Increase runs to 200,000 since we currently get a random failure about
once per day on the buildbot.
2021-05-04 10:47:05 -07:00
Fabian Meumertzheim b1048ff682 [libFuzzer] Preserve position hint in auto dictionary
Currently, the position hint of an entry in the persistent auto
dictionary is fixed to 1. As a consequence, with a 50% chance, the entry
is applied right after the first byte of the input. As the position 1
does not appear to have any particular significance, this is likely a
bug that may have been caused by confusing the constructor parameter
with a success count.

This commit resolves the issue by preserving any existing position hint
or disabling the hint if the original entry didn't have one.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D101686
2021-05-04 09:06:51 -07:00
Nico Weber bfb9c749c0 Fix some typos in d7ec48d71b 2021-05-04 10:44:01 -04:00
Nico Weber d7ec48d71b [clang] accept -fsanitize-ignorelist= in addition to -fsanitize-blacklist=
Use that for internal names (including the default ignorelists of the
sanitizers).

Differential Revision: https://reviews.llvm.org/D101832
2021-05-04 10:24:00 -04:00
Fangrui Song 2fec8860d8 [sanitizer] Set IndentPPDirectives: AfterHash in .clang-format
Code patterns like this are common, `#` at the line beginning
(https://google.github.io/styleguide/cppguide.html#Preprocessor_Directives),
one space indentation for if/elif/else directives.
```
#if SANITIZER_LINUX
# if defined(__aarch64__)
# endif
#endif
```

However, currently clang-format wants to reformat the code to
```
#if SANITIZER_LINUX
#if defined(__aarch64__)
#endif
#endif
```

This significantly harms readability in my review.  Use `IndentPPDirectives:
AfterHash` to defeat the diagnostic. clang-format will now suggest:

```
#if SANITIZER_LINUX
#  if defined(__aarch64__)
#  endif
#endif
```

Unfortunately there is no clang-format option using indent with 1 for
just preprocessor directives. However, this is still one step forward
from the current behavior.

Reviewed By: #sanitizers, vitalybuka

Differential Revision: https://reviews.llvm.org/D100238
2021-05-03 13:49:41 -07:00
Mitch Phillips e8f7241e0b [scudo] Don't track free/use stats for transfer batches.
The Scudo C unit tests are currently non-hermetic. In particular, adding
or removing a transfer batch is a global state of the allocator that
persists between tests. This can cause flakiness in
ScudoWrappersCTest.MallInfo, because the creation or teardown of a batch
causes mallinfo's uordblks or fordblks to move up or down by the size of
a transfer batch on malloc/free.

It's my opinion that uordblks and fordblks should track the statistics
related to the user's malloc() and free() usage, and not the state of
the internal allocator structures. Thus, excluding the transfer batches
from stat collection does the trick and makes these tests pass.

Repro instructions of the bug:
 1. ninja ./projects/compiler-rt/lib/scudo/standalone/tests/ScudoCUnitTest-x86_64-Test
 2. ./projects/compiler-rt/lib/scudo/standalone/tests/ScudoCUnitTest-x86_64-Test --gtest_filter=ScudoWrappersCTest.MallInfo

Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D101653
2021-05-03 11:50:00 -07:00
Matt Morehouse ac512890b4 [libFuzzer] Deflake entropic exec-time test. 2021-05-03 10:37:44 -07:00
Fabian Meumertzheim 62e4dca94e [libFuzzer] Fix off-by-one error in ApplyDictionaryEntry
In the overwrite branch of MutationDispatcher::ApplyDictionaryEntry in
FuzzerMutate.cpp, the index Idx at which W.size() bytes are overwritten
with the word W is chosen uniformly at random in the interval
[0, Size - W.size()). This means that Idx + W.size() will always be
strictly less than Size, i.e., the last byte of the current unit will
never be overwritten.

This is fixed by adding 1 to the exclusive upper bound.

Addresses https://bugs.llvm.org/show_bug.cgi?id=49989.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D101625
2021-05-03 10:37:44 -07:00
Vitaly Buka 95aa116d0c [scudo][NFC] Fix clang-tidy warnings 2021-05-01 01:55:21 -07:00
Vitaly Buka d56ef8523c [scudo] Use require_constant_initialization
Attribute guaranties safe static initialization of globals.

Reviewed By: hctim

Differential Revision: https://reviews.llvm.org/D101514
2021-05-01 01:46:47 -07:00
Dmitry Vyukov bf61690e92 asan: fix a windows test
Before commit "sanitizer_common: introduce kInvalidTid/kMainTid"
asan invalid/unknown thread id was 0xffffff, so presumably we printed "T16777215".
Now it's -1, so we print T-1. Fix the test.
I think the new format is even better, "T-1" clearly looks like something special
rather than a random large number.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D101634
2021-04-30 13:51:58 -07:00
Vitaly Buka f0c9d1e95f [tsan] Remove special SyncClock::kInvalidTid
Followup for D101428.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D101604
2021-04-30 13:39:15 -07:00
Vitaly Buka cbd5aceb62 [NFC][tsan] Fix cast after D101428 2021-04-30 11:53:09 -07:00
Dmitry Vyukov 92a3a2dc3e sanitizer_common: introduce kInvalidTid/kMainTid
Currently we have a bit of a mess related to tids:
 - sanitizers re-declare kInvalidTid multiple times
 - some call it kUnknownTid
 - implicit assumptions that main tid is 0
 - asan/memprof claim their tids need to fit into 24 bits,
   but this does not seem to be true anymore
 - inconsistent use of u32/int to store tids

Introduce kInvalidTid/kMainTid in sanitizer_common
and use them consistently.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D101428
2021-04-30 15:58:05 +02:00
Dmitry Vyukov b6df852901 tsan: fix fork syscall test
Arm64 builders failed with:
error: use of undeclared identifier 'SYS_fork'
https://lab.llvm.org/buildbot/#/builders/7/builds/2575

Indeed, not all arches have fork syscall.
Implement fork via clone on these arches.

Differential Revision: https://reviews.llvm.org/D101603
2021-04-30 10:23:34 +02:00
Dmitry Vyukov ed7bf7d73f tsan: refactor fork handling
Commit efd254b636 ("tsan: fix deadlock in pthread_atfork callbacks")
fixed another deadlock related to atfork handling.
But builders with DCHECKs enabled reported failures of
pthread_atfork_deadlock2.c and pthread_atfork_deadlock3.c tests
related to the fact that we hold runtime locks on interceptor exit:
https://lab.llvm.org/buildbot/#/builders/70/builds/6727
This issue is somewhat inherent to the current approach,
we indeed execute user code (atfork callbacks) with runtime lock held.

Refactor fork handling to not run user code (atfork callbacks)
with runtime locks held. This change does this by installing
own atfork callbacks during runtime initialization.
Atfork callbacks run in LIFO order, so the expectation is that
our callbacks run last, right before the actual fork.
This way we lock runtime mutexes around fork, but not around
user callbacks.

Extend tests to also install after fork callbacks just to cover
more scenarios. Some tests also started reporting real races
that we previously suppressed.

Also extend tests to cover fork syscall support.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D101517
2021-04-30 08:48:20 +02:00
Jianzhou Zhao c027272ac2 [msan] Add static to some msan allocator functions
This is to help review refactor the allocator code.
So it is easy to see which are the real public interfaces.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D101586
2021-04-30 04:49:10 +00:00
Steven Wu 7259394b32 [CMake][compiler-rt] avoid conflict with builtin check_linker_flag
Rename `check_linker_flag` in compiler_rt to avoid conflict. Follow up
as the fix in D100901.

Patched by radford.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D101581
2021-04-29 19:32:39 -07:00
Jianzhou Zhao 75be3681d1 [msan] Remove dead function/fields
To see how to extract a shared allocator interface for D101204,
found some unused code. Tests passed. Are they safe to remove?

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D101559
2021-04-29 23:08:39 +00:00
Vitaly Buka ea7618684c Revert "[scudo] Use require_constant_initialization"
This reverts commit 7ad4dee3e7.
2021-04-29 09:55:54 -07:00
Vitaly Buka 7ad4dee3e7 [scudo] Use require_constant_initialization
Attribute guaranties safe static initialization of globals.

Differential Revision: https://reviews.llvm.org/D101514
2021-04-29 09:47:59 -07:00
Vitaly Buka c50796475d [NFC][scudo] Suppress "division by zero" warning 2021-04-29 01:24:40 -07:00
Dmitry Vyukov d78782f6a6 tsan: fix warnings in tests
Fix format specifier.
Fix warnings about non-standard attribute placement.
Make free_race2.c test a bit more interesting:
test access with/without an offset.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D101424
2021-04-29 07:42:18 +02:00
Dmitry Vyukov aff73487c9 tsan: increase dense slab alloc capacity
We've got a user report about heap block allocator overflow.
Bump the L1 capacity of all dense slab allocators to maximum
and be careful to not page the whole L1 array in from .bss.
If OS uses huge pages, this still may cause a limited RSS increase
due to boundary huge pages, but avoiding that looks hard.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D101161
2021-04-29 07:34:50 +02:00
Roland McGrath 3341324d82 [gwp_asan] Use __sanitizer_fast_backtrace on Fuchsia
Reviewed By: phosek, cryptoad, hctim

Differential Revision: https://reviews.llvm.org/D101407
2021-04-28 16:48:14 -07:00
Vitaly Buka f7164c7714 [NFC][scudo] Add reference to a QEMU bug
D101031 added workaround for the bug.
2021-04-28 14:57:53 -07:00
Tres Popp d1e08b124c Revert "tsan: refactor fork handling"
This reverts commit e1021dd1fd.
2021-04-28 14:08:33 +02:00
Alex Richardson 777ca513c8 [builtins] Fix ABI-incompatibility with GCC for floating-point compare
While implementing support for the float128 routines on x86_64, I noticed
that __builtin_isinf() was returning true for 128-bit floating point
values that are not infinite when compiling with GCC and using the
compiler-rt implementation of the soft-float comparison functions.
After stepping through the assembly, I discovered that this was caused by
GCC assuming a sign-extended 64-bit -1 result, but our implementation
returns an enum (which then has zeroes in the upper bits) and therefore
causes the comparison with -1 to fail.

Fix this by using a CMP_RESULT typedef and add a static_assert that it
matches the GCC soft-float comparison return type when compiling with GCC
(GCC has a __libgcc_cmp_return__ mode that can be used for this purpose).

Also move the 3 copies of the same code to a shared .inc file.

Reviewed By: compnerd

Differential Revision: https://reviews.llvm.org/D98205
2021-04-28 12:19:19 +01:00
Vitaly Buka b1a77e465e [scudo] Enable arm32 arch 2021-04-27 18:35:45 -07:00
Dmitry Vyukov f69853ac40 tsan: fix build with COMPILER_RT_TSAN_DEBUG_OUTPUT
COMPILER_RT_TSAN_DEBUG_OUTPUT enables TSAN_COLLECT_STATS,
which changes layout of runtime structs (some structs contain
stats when the option is enabled).
It's not OK to build runtime with the define, but tests without it.
The error is detected by build_consistency_stats/nostats.
Fix this by defining TSAN_COLLECT_STATS for tests to match the runtime.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D101386
2021-04-27 22:38:56 +02:00
Dmitry Vyukov e1021dd1fd tsan: refactor fork handling
Commit efd254b636 ("tsan: fix deadlock in pthread_atfork callbacks")
fixed another deadlock related to atfork handling.
But builders with DCHECKs enabled reported failures of
pthread_atfork_deadlock2.c and pthread_atfork_deadlock3.c tests
related to the fact that we hold runtime locks on interceptor exit:
https://lab.llvm.org/buildbot/#/builders/70/builds/6727
This issue is somewhat inherent to the current approach,
we indeed execute user code (atfork callbacks) with runtime lock held.

Refactor fork handling to not run user code (atfork callbacks)
with runtime locks held. This change does this by installing
own atfork callbacks during runtime initialization.
Atfork callbacks run in LIFO order, so the expectation is that
our callbacks run last, right before the actual fork.
This way we lock runtime mutexes around fork, but not around
user callbacks.

Extend tests to also install after fork callbacks just to cover
more scenarios. Some tests also started reporting real races
that we previously suppressed.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D101385
2021-04-27 22:37:27 +02:00
Evgenii Stepanov 5275d772da Revert "tsan: fix deadlock in pthread_atfork callbacks"
Tests fail on debug builders. See the forward fix in
https://reviews.llvm.org/D101385.

This reverts commit efd254b636.
2021-04-27 12:36:31 -07:00
Evgenii Stepanov 561f4b9087 Fix -Wunused-but-set-variable warning in msan_test.cpp 2021-04-27 12:07:13 -07:00
Vitaly Buka 0e6f934cc3 [NFC][lsan] Another attempt to fix arm bot 2021-04-27 10:46:36 -07:00
Dmitry Vyukov efd254b636 tsan: fix deadlock in pthread_atfork callbacks
We take report/thread_registry locks around fork.
This means we cannot report any bugs in atfork handlers.
We resolved this by enabling per-thread ignores around fork.
This resolved some of the cases, but not all.
The added test triggers a race report from a signal handler
called from atfork callback, we reset per-thread ignores
around signal handlers, so we tried to report it and deadlocked.
But there are more cases: a signal handler can be called
synchronously if it's sent to itself. Or any other report
types would cause deadlocks as well: mutex misuse,
signal handler spoiling errno, etc.
Disable all reports for the duration of fork with
thr->suppress_reports and don't re-enable them around
signal handlers.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D101154
2021-04-27 13:25:26 +02:00
Vitaly Buka 3c47f5f46e [asan][NFC] Fix "not used" warning in test 2021-04-26 20:07:20 -07:00
Leonard Chan a786f2badc [compiler-rt][hwasan] Add definition for Symbolizer::SymbolizeFrame
This is undefined if SANITIZER_SYMBOLIZER_MARKUP is 1, which is the case for
Fuchsia, and will result in a undefined symbol error. This function is needed
by hwasan for online symbolization, but is not needed for us since we do
offline symbolization.

Differential Revision: https://reviews.llvm.org/D99386
2021-04-26 13:25:10 -07:00
Vitaly Buka 337a024bba [scudo][NFC] Fix cast warning 2021-04-25 15:47:28 -07:00
Vitaly Buka 98a7563261 [scudo] Mark ARM64 as supported platform 2021-04-25 15:47:28 -07:00
Vitaly Buka 51b4a7ef52 [sanitizer] Use COMPILER_RT_EMULATOR with gtests
Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D100998
2021-04-25 15:41:13 -07:00
Lang Hames 5e537ea1d7 [ORC-RT] Re-apply "Initial ORC Runtime directories and build..." with fixes.
This reapplies 1e1d75b190, which was reverted in ce1a4d5323 due to build
failures.

The unconditional dependencies on clang and llvm-jitlink in
compiler-rt/test/orc/CMakeLists.txt have been removed -- they don't appear to
be necessary, and I suspect they're the cause of the build failures seen
earlier.
2021-04-24 16:00:20 -07:00
Lang Hames ce1a4d5323 Revert "[ORC-RT] Initial ORC Runtime directories and build system files."
Some builders failed with a missing clang dependency. E.g.

CMake Error at /Users/buildslave/jenkins/workspace/clang-stage1-RA/clang-build \
  /lib/cmake/llvm/AddLLVM.cmake:1786 (add_dependencies):
The dependency target "clang" of target "check-compiler-rt" does not exist.

Reverting while I investigate.

This reverts commit 1e1d75b190.
2021-04-23 20:36:59 -07:00
Lang Hames 1e1d75b190 [ORC-RT] Initial ORC Runtime directories and build system files.
This patch contains initial directories and build files for the ORC runtime.

Differential Revision: https://reviews.llvm.org/D100711
2021-04-23 20:21:22 -07:00
Mitch Phillips 643ccf6e4b Revert "[Scudo] Use GWP-ASan's aligned allocations and fixup postalloc hooks."
This reverts commit a683abe5c0.

Broke the upstream buildbots:
https://lab.llvm.org/buildbot/#/builders/37/builds/3731/steps/16/logs/stdio
2021-04-23 15:40:38 -07:00
Peter Collingbourne f2819ee6cc scudo: Work around gcc 8 conversion warning.
Should fix:
https://lab.llvm.org/buildbot#builders/99/builds/2953
2021-04-23 11:26:12 -07:00