Commit Graph

4444 Commits

Author SHA1 Message Date
Vitaly Buka 5e9e463e1f [lsan] Test to show lsan dependency on globals
This test from @MaskRay comment on D69428. The patch is looking to
break this behavior. If we go with D69428 I hope we will have some
workaround for this test or include explicit test update into the patch.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D100906
2021-04-20 22:00:26 -07:00
George Balatsouras 98b114d480 [dfsan] Remove hard-coded constant in release_shadow_space.c
Reviewed By: stephan.yichao.zhao

Differential Revision: https://reviews.llvm.org/D100608
2021-04-15 17:24:35 -07:00
George Balatsouras b2b59f622e [dfsan] Add test for origin tracking stack traces
Reviewed By: stephan.yichao.zhao

Differential Revision: https://reviews.llvm.org/D100518
2021-04-15 16:22:47 -07:00
Fangrui Song afec953857 [sanitizer] Simplify GetTls with dl_iterate_phdr on Linux and use it on musl/FreeBSD
... so that FreeBSD specific GetTls/glibc specific pthread_self code can be
removed. This also helps FreeBSD arm64/powerpc64 which don't have GetTls
implementation yet.

GetTls is the range of

* thread control block and optional TLS_PRE_TCB_SIZE
* static TLS blocks plus static TLS surplus

On glibc, lsan requires the range to include
`pthread::{specific_1stblock,specific}` so that allocations only referenced by
`pthread_setspecific` can be scanned.

This patch uses `dl_iterate_phdr` to collect TLS blocks. Find the one
with `dlpi_tls_modid==1` as one of the initially loaded module, then find
consecutive ranges. The boundaries give us addr and size.

This allows us to drop the glibc internal `_dl_get_tls_static_info` and
`InitTlsSize`. However, huge glibc x86-64 binaries with numerous shared objects
may observe time complexity penalty, so exclude them for now. Use the simplified
method with non-Android Linux for now, but in theory this can be used with *BSD
and potentially other ELF OSes.

This removal of RISC-V `__builtin_thread_pointer` makes the code compilable with
more compiler versions (added in Clang in 2020-03, added in GCC in 2020-07).

This simplification enables D99566 for TLS Variant I architectures.

Note: as of musl 1.2.2 and FreeBSD 12.2, dlpi_tls_data returned by
dl_iterate_phdr is not desired: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=254774
This can be worked around by using `__tls_get_addr({modid,0})` instead
of `dlpi_tls_data`. The workaround can be shared with the workaround for glibc<2.25.

This fixes some tests on Alpine Linux x86-64 (musl)

```
test/lsan/Linux/cleanup_in_tsd_destructor.c
test/lsan/Linux/fork.cpp
test/lsan/Linux/fork_threaded.cpp
test/lsan/Linux/use_tls_static.cpp
test/lsan/many_tls_keys_thread.cpp

test/msan/tls_reuse.cpp
```

and `test/lsan/TestCases/many_tls_keys_pthread.cpp` on glibc aarch64.

The number of sanitizer test failures does not change on FreeBSD/amd64 12.2.

Differential Revision: https://reviews.llvm.org/D98926
2021-04-15 15:34:43 -07:00
Matt Morehouse b351590bae [libFuzzer] Fix fuzzer-oom.test.
SinkPtr was not correctly marked as volatile, causing the malloc to get
optimized out.  This was causing 20-minute timeouts for the test and no
OOM.
2021-04-13 11:33:41 -07:00
Matt Morehouse 4230249048 [libFuzzer] Fix MSan false positives with custom mutators.
We need to unpoison parameters before calling into MSan-instrumented
user-defined mutators.

Addresses https://github.com/google/oss-fuzz/issues/4605.

Reviewed By: metzman

Differential Revision: https://reviews.llvm.org/D100355
2021-04-13 10:49:42 -07:00
Julian Lettner 05df5c54e8 [TSan] Allow test contents to be copied before execution
Allow test contents to be copied before execution by using
`%ld_flags_rpath_so`, `%ld_flags_rpath_exe`, and `%dynamiclib`
substitutions.

rdar://76302416

Differential Revision: https://reviews.llvm.org/D100240
2021-04-12 13:30:06 -07:00
Mitch Phillips 15689f3af0 [asan] Replaceable new/delete is unsupported in Windows.
Mark the test as unsupported to bring the bot online. Could probably be
permanently fixed by using one of the workarounds already present in
compiler-rt.
2021-04-12 09:50:34 -07:00
Mitch Phillips 7df30e77d4 [ASan] Allow new/delete replacement by making interceptors weak
ASan declares these functions as strongly-defined, which results in
'duplicate symbol' errors when trying to replace them in user code when
linking the runtimes statically.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D100220
2021-04-09 14:19:39 -07:00
David Spickett 466fab5c94 [lsan] Mark 2 new lsan tests unsupported on arm-linux
These tests were added in:
1daa48f005
59e422c90b

malloc_zero.c and realloc_too_big.c fail when only
leak sanitizer is enabled.
http://lab.llvm.org:8011/#/builders/59/builds/1635
(also in an armv8 32 bit build)

(I would XFAIL them but the same test is run with
address and leak sanitizer enabled and that one does
pass)
2021-04-08 15:57:46 +01:00
Julian Lettner a3e1b11123 [Sanitizer] Adopt Python 3 for iOS simulator test scripts
Differential Revision: https://reviews.llvm.org/D99911
2021-04-06 09:14:14 -07:00
David Spickett 34f8a7f93c [lsan][test] Disable many_tls_keys_pthread.cpp on AArch64
Partially reverts 04dbb63400.

This test requires 9be8f8b34d
which is/has been reverted a few times but this test was
left enabled.

Currently that change is reverted and this test is failing:
http://lab.llvm.org:8011/#/builders/7/builds/2327
2021-04-06 11:28:02 +01:00
Nico Weber 0e92cbd6a6 Revert "[sanitizer] Simplify GetTls with dl_iterate_phdr on Linux"
This reverts commit ec575e3b0a.
Still doesn't work, see https://crbug.com/1196037
2021-04-05 19:00:18 -04:00
Fangrui Song ec575e3b0a [sanitizer] Simplify GetTls with dl_iterate_phdr on Linux
This was reverted by f176803ef1 due to
Ubuntu 16.04 x86-64 glibc 2.23 problems.
This commit additionally calls `__tls_get_addr({modid,0})` to work around the
dlpi_tls_data==NULL issues for glibc<2.25
(https://sourceware.org/bugzilla/show_bug.cgi?id=19826)

GetTls is the range of

* thread control block and optional TLS_PRE_TCB_SIZE
* static TLS blocks plus static TLS surplus

On glibc, lsan requires the range to include
`pthread::{specific_1stblock,specific}` so that allocations only referenced by
`pthread_setspecific` can be scanned.

This patch uses `dl_iterate_phdr` to collect TLS blocks. Find the one
with `dlpi_tls_modid==1` as one of the initially loaded module, then find
consecutive ranges. The boundaries give us addr and size.

This allows us to drop the glibc internal `_dl_get_tls_static_info` and
`InitTlsSize` entirely. Use the simplified method with non-Android Linux for
now, but in theory this can be used with *BSD and potentially other ELF OSes.

This simplification enables D99566 for TLS Variant I architectures.

See https://reviews.llvm.org/D93972#2480556 for analysis on GetTls usage
across various sanitizers.

Differential Revision: https://reviews.llvm.org/D98926
2021-04-04 15:35:53 -07:00
Petr Hosek b0d286b03c [CMake] Use append instead of set with the list
This addresses an issue introduced by D99706.
2021-04-01 20:30:49 -07:00
Petr Hosek 775e55462a [CMake] Include dependency on cxx-headers in compiler-rt tests
The missing dependency was revealed by D97572.

Differential Revision: https://reviews.llvm.org/D99706
2021-04-01 10:42:06 -07:00
Alex Richardson ce193ea9e8 [asan] Remove FreeBSD XFAIL from asan-sigbus.cpp test
This test passes for me on FreeBSD 12.2 and was probably fixed by
https://svnweb.freebsd.org/base?view=revision&revision=352807.

Reviewed By: emaste

Differential Revision: https://reviews.llvm.org/D98281
2021-03-31 09:17:48 +01:00
Fangrui Song 1daa48f005 [lsan] realloc: don't deallocate if requested size is too large
This is the behavior required by the standards.

Differential Revision: https://reviews.llvm.org/D99480
2021-03-29 13:35:10 -07:00
Fangrui Song 59e422c90b [lsan][test] Add malloc(0) and realloc(p, 0) tests 2021-03-29 11:41:07 -07:00
Fangrui Song 04dbb63400 [lsan][test] Enable many_tls_keys_pthread.cpp and disable swapcontext.cpp/fork_and_leak.cpp
With D98926, many_tls_keys_pthread.cpp appears to be working.

On glibc 2.30-0ubuntu2, swapcontext.cpp and Linux/fork_and_leak.cpp work fine
but they strangely fail on clang-cmake-aarch64-full
(https://lab.llvm.org/buildbot/#/builders/7/builds/2240).
Disable them for now.

Note: check-lsan was recently enabled on AArch64 in D98985. A test takes
10+ seconds. We should figure out the bottleneck.
2021-03-26 11:26:08 -07:00
Fangrui Song dc46783f7f [memprof][test] Make test_terse.cpp robust (sched_getcpu may happens to change)
```
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/memprof/TestCases/test_terse.cpp:11:11: error: CHECK: expected string not found in input
// CHECK: MIB:[[STACKID:[0-9]+]]/1/40.00/40/40/20.00/20/20/[[AVELIFETIME:[0-9]+]].00/[[AVELIFETIME]]/[[AVELIFETIME]]/0/0/0/0
          ^
<stdin>:1:1: note: scanning from here
MIB:StackID/AllocCount/AveSize/MinSize/MaxSize/AveAccessCount/MinAccessCount/MaxAccessCount/AveLifetime/MinLifetime/MaxLifetime/NumMigratedCpu/NumLifetimeOverlaps/NumSameAllocCpu/NumSameDeallocCpu
^
<stdin>:4:1: note: possible intended match here
MIB:134217729/1/40.00/40/40/20.00/20/20/7.00/7/7/1/0/0/0
```
2021-03-26 00:45:58 -07:00
Matt Morehouse 96a4167b4c [HWASan] Use page aliasing on x86_64.
Userspace page aliasing allows us to use middle pointer bits for tags
without untagging them before syscalls or accesses.  This should enable
easier experimentation with HWASan on x86_64 platforms.

Currently stack, global, and secondary heap tagging are unsupported.
Only primary heap allocations get tagged.

Note that aliasing mode will not work properly in the presence of
fork(), since heap memory will be shared between the parent and child
processes.  This mode is non-ideal; we expect Intel LAM to enable full
HWASan support on x86_64 in the future.

Reviewed By: vitalybuka, eugenis

Differential Revision: https://reviews.llvm.org/D98875
2021-03-25 07:04:14 -07:00
Jianzhou Zhao af9f461298 [dfsan] test flush on only x86 2021-03-25 02:45:43 +00:00
Jianzhou Zhao f9a135b652 [dfsan] Test dfsan_flush with origins
This is a part of https://reviews.llvm.org/D95835.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D99295
2021-03-25 00:12:53 +00:00
Matt Morehouse c8ef98e5de Revert "[HWASan] Use page aliasing on x86_64."
This reverts commit 63f73c3eb9 due to
breakage on aarch64 without TBI.
2021-03-24 16:18:29 -07:00
Julian Lettner 26e0fb88a3 [TSan] Support initialize/finalize hooks in dynamic libraries
Make TSan runtime initialization and finalization hooks work
even if these hooks are not built in the main executable.  When these
hooks are defined in another library that is not directly linked against
the TSan runtime (e.g., Swift runtime) we cannot rely on the "strong-def
overriding weak-def" mechanics and have to look them up via `dlsym()`.

Let's also define hooks that are easier to use from C-only code:
```
extern "C" void __tsan_on_initialize();
extern "C" int __tsan_on_finalize(int failed);
```
For now, these will call through to the old hooks.  Eventually, we want
to adopt the new hooks downstream and remove the old ones.

This is part of the effort to support Swift Tasks (async/await and
actors) in TSan.

rdar://74256720

Reviewed By: vitalybuka, delcypher

Differential Revision: https://reviews.llvm.org/D98810
2021-03-24 12:38:39 -07:00
Matt Morehouse 63f73c3eb9 [HWASan] Use page aliasing on x86_64.
Userspace page aliasing allows us to use middle pointer bits for tags
without untagging them before syscalls or accesses.  This should enable
easier experimentation with HWASan on x86_64 platforms.

Currently stack, global, and secondary heap tagging are unsupported.
Only primary heap allocations get tagged.

Note that aliasing mode will not work properly in the presence of
fork(), since heap memory will be shared between the parent and child
processes.  This mode is non-ideal; we expect Intel LAM to enable full
HWASan support on x86_64 in the future.

Reviewed By: vitalybuka, eugenis

Differential Revision: https://reviews.llvm.org/D98875
2021-03-24 11:43:41 -07:00
Jianzhou Zhao 4950695eba [dfsan] Add Origin ABI Wrappers
Supported ctime_r, fgets, getcwd, get_current_dir_name, gethostname,
getrlimit, getrusage, strcpy, time, inet_pton, localtime_r,
getpwuid_r, epoll_wait, poll, select, sched_getaffinity

Most of them work as calling their non-origin verision directly.

This is a part of https://reviews.llvm.org/D95835.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D98966
2021-03-24 18:22:03 +00:00
Jianzhou Zhao 91516925dd [dfsan] Add Origin ABI Wrappers
Supported strrchr, strrstr, strto*, recvmmsg, recrmsg, nanosleep,
    memchr, snprintf, socketpair, sprintf, getocketname, getsocketopt,
    gettimeofday, getpeername.

    strcpy was added because the test of sprintf need it. It will be
    committed by D98966. Please ignore it when reviewing.

    This is a part of https://reviews.llvm.org/D95835.

    Reviewed By: gbalats

    Differential Revision: https://reviews.llvm.org/D99109
2021-03-24 16:13:09 +00:00
Yvan Roux 608ee3593c [AArch64][ASAN] Re-enable fgets_fputs.cpp test.
Now that AArch64 mapping symbols are correctly handled by
llvm-symbolizer this test can be re-enabled on that target.
2021-03-24 10:06:04 +01:00
Fangrui Song fdf97bc738 [test] Enable check-lsan on aarch64-*-linux
`check-lsan` passed on an aarch64-*-linux machine.

Unsupport `many_tls_keys_pthread.cpp` for now: it requires GetTls to include
`specific_1stblock` and `specific` in `struct pthread`.

Differential Revision: https://reviews.llvm.org/D98985
2021-03-23 11:11:26 -07:00
Vitaly Buka 091706269c [lsan][lsan] Use --std=c++14 to fix Windows test 2021-03-22 21:43:07 -07:00
Matt Morehouse c21f72e65a [HWASan] Fix brittle stack-oob.c test. 2021-03-22 11:08:22 -07:00
Matt Morehouse 772851ca4e [HWASan] Disable stack, globals and force callbacks for x86_64.
Subsequent patches will implement page-aliasing mode for x86_64, which
will initially only work for the primary heap allocator.  We force
callback instrumentation to simplify the initial aliasing
implementation.

Reviewed By: vitalybuka, eugenis

Differential Revision: https://reviews.llvm.org/D98069
2021-03-22 08:02:27 -07:00
Emily Shi 6ca178cd78 [asan] specify c++ version in tests to fix compile error
If we don't specify the c++ version in these tests, it could cause compile errors because the compiler could default to an older c++

rdar://75247244

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D98913
2021-03-19 10:08:18 -07:00
Jianzhou Zhao 1fe042041c [dfsan] Add origin ABI wrappers
supported: dl_get_tls_static_info, calloc, clock_gettime,
dfsan_set_write_callback, dl_iterato_phdr, dlopen, memcpy,
memmove, memset, pread, read, strcat, strdup, strncpy

This is a part of https://reviews.llvm.org/D95835.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D98790
2021-03-19 16:23:25 +00:00
Jon Roelofs a14263e8f8 [compiler-rt] -fsanitize=cfi is not supported on Darwin
This was responsible for:

Failed Tests (2):
  cfi-devirt-x86_64 :: mfcall.cpp
  cfi-standalone-x86_64 :: mfcall.cpp
2021-03-17 13:28:42 -07:00
Rainer Orth 3b8b5d1f22 [sanitizer_common][test] Handle missing REG_STARTEND in Posix/regex_startend.cpp
As reported in D96348 <https://reviews.llvm.org/D96348>, the
`Posix/regex_startend.cpp` test `FAIL`s on Solaris because
`REG_STARTEND` isn't defined.  It's a BSD extension not present everywhere.
E.g. AIX doesn't have it, too.

Fixed by wrapping the test in `#ifdef REG_STARTEND`.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and
`x86_64-pc-linux-gnu`.

Differential Revision: https://reviews.llvm.org/D98425
2021-03-17 09:56:19 +01:00
Jianzhou Zhao ec5ed66cee [dfsan] Add origin ABI wrappers
supported: bcmp, fstat, memcmp, stat, strcasecmp, strchr, strcmp,
strncasecmp, strncp, strpbrk

This is a part of https://reviews.llvm.org/D95835.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D98636
2021-03-17 02:22:35 +00:00
Emily Shi c2f3b2f90e [asan] disable MallocNanoZone for no fd test on darwin
On Darwin, MallocNanoZone may log after execv, which messes up this test.
Disable MallocNanoZone for this test since we don't use it anyway with asan.

This environment variable should only affect Darwin and not change behavior on other platforms.

rdar://74992832

Reviewed By: delcypher

Differential Revision: https://reviews.llvm.org/D98735
2021-03-16 15:17:50 -07:00
Yvan Roux c0f224e630 [AArch64][ASAN] Disable fgets_fputs.cpp test.
This test is failing for long a time on AArch64 bots, disable it for now
to keep the bots green while investigating it.
2021-03-16 07:00:19 +01:00
Jianzhou Zhao 4e67ae7b6b [dfsan] Add origin ABI wrappers for thread/signal/fork
This is a part of https://reviews.llvm.org/D95835.

See bb91e02efd about the similar issue of fork in MSan's origin tracking.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D98359
2021-03-15 16:18:00 +00:00
Vy Nguyen 6f37d18d8c [asan] Fixed test failing on windows due to different printf behaviour.
%p reported prints upper case hex chars on Windows.
The fix  is to switch to using %#lx

Differential Revision: https://reviews.llvm.org/D98570
2021-03-15 10:58:40 -04:00
Vy Nguyen ab08c3865b Revert "Revert "[compiler-rt][asan] Make wild-pointer crash error more useful""
This reverts commit c578508b5b.

Reland now that unrelated crash has been resolved.
2021-03-12 11:35:50 -05:00
Vy Nguyen c578508b5b Revert "[compiler-rt][asan] Make wild-pointer crash error more useful"
This reverts commit f65e1aee40.
2021-03-11 22:13:40 -05:00
Vy Nguyen f65e1aee40 [compiler-rt][asan] Make wild-pointer crash error more useful
Right now, when you have an invalid memory address, asan would just crash and does not offer much useful info.
This patch attempted to give a bit more detail on the access.

Differential Revision: https://reviews.llvm.org/D98280
2021-03-11 21:48:39 -05:00
Emily Shi 03afd5cea4 [asan] disable no-fd test on darwin
If a log message is triggered between execv and child, this test fails.
In the meantime, disable the test to unblock CI

rdar://74992832

Reviewed By: delcypher

Differential Revision: https://reviews.llvm.org/D98453
2021-03-11 16:49:18 -08:00
Jianzhou Zhao 37520a0b2b [dfsan] Disable testing origin tracking on non x86_64 arch
Fix test cases related to https://reviews.llvm.org/D95835.
2021-03-11 21:22:43 +00:00
Jianzhou Zhao 6a9a686ce7 [dfsan] Tracking origins at phi nodes
This is a part of https://reviews.llvm.org/D95835.

Reviewed-by: morehouse

Differential Revision: https://reviews.llvm.org/D98268
2021-03-10 17:02:58 +00:00
Alex Richardson 6840fc4e7f [asan][tests] Handle FreeBSD in large_func_test and use-after-delete
This is the same fix as ab8a460241 for
Solaris and 23cd8d51ad (Windows+Darwin).
2021-03-10 11:17:33 +00:00