Commit Graph

12656 Commits

Author SHA1 Message Date
Fangrui Song
5a9b792d72 [gcov] Temporarily unsupport host-byteorder-big-endian
llvm-cov gcov does not support host-byteorder-big-endian yet.
2020-05-10 10:29:09 -07:00
Jinsong Ji
a72b9dfd45 [sanitizer] Enable whitelist/blacklist in new PM
https://reviews.llvm.org/D63616 added `-fsanitize-coverage-whitelist`
and `-fsanitize-coverage-blacklist` for clang.

However, it was done only for legacy pass manager.
This patch enable it for new pass manager as well.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D79653
2020-05-10 02:34:29 +00:00
Evgenii Stepanov
9fcd2b68e7 [hwasan] Untag destination address in hwasan_posix_memalign.
Required on X86 because no TBI.
2020-05-08 16:35:48 -07:00
Evgenii Stepanov
eaea9ed835 [hwasan] Reset current thread pointer on thread exit.
Summary:
This is necessary to handle calls to free() after __hwasan_thread_exit,
which is possible in glibc.

Also, add a null check to GetCurrentThread, otherwise the logic in
GetThreadByBufferAddress turns it into a non-null value. This means that
all of the checks for GetCurrentThread() != nullptr do not have any
effect at all right now!

Reviewers: pcc, hctim

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D79608
2020-05-08 10:31:25 -07:00
Arthur Eubanks
355633860e Fix MSan test use-after-dtor.cpp under new pass manager
Summary: The new pass manager symbolizes the location as ~Simple instead of Simple::~Simple.

Reviewers: rnk, leonardchan, vitalybuka

Subscribers: #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D79594
2020-05-08 09:12:41 -07:00
Calixte Denizet
0da37bedc2 [compiler-rt] Reduce the number of threads in gcov test to avoid failure
Summary:
Patch in D78477 introduced a new test for gcov and this test is failing on arm:
 - http://lab.llvm.org:8011/builders/clang-cmake-thumbv7-full-sh/builds/4752/steps/ninja%20check%202/logs/stdio
  - http://lab.llvm.org:8011/builders/clang-cmake-armv7-full/builds/10501/steps/ninja%20check%202/logs/stdio
So try to fix it in reducing the number of threads.

Reviewers: marco-c

Reviewed By: marco-c

Subscribers: dberris, kristof.beyls, #sanitizers, serge-sans-paille, sylvestre.ledru

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D79621
2020-05-08 12:48:07 +02:00
Calixte Denizet
bec223a9bc [profile] Don't crash when forking in several threads
Summary:
When forking in several threads, the counters were written out in using the same global static variables (see GCDAProfiling.c): that leads to crashes.
So when there is a fork, the counters are resetted in the child process and they will be dumped at exit using the interprocess file locking.
When there is an exec, the counters are written out and in case of failures they're resetted.

Reviewers: jfb, vsk, marco-c, serge-sans-paille

Reviewed By: marco-c, serge-sans-paille

Subscribers: llvm-commits, serge-sans-paille, dmajor, cfe-commits, hiraditya, dexonsmith, #sanitizers, marco-c, sylvestre.ledru

Tags: #sanitizers, #clang, #llvm

Differential Revision: https://reviews.llvm.org/D78477
2020-05-07 14:13:11 +02:00
Julian Lettner
5e4740c212 [Darwin] Improve ASan diagnostics on arm64e with pointer auth
When reporting diagnostics from ASan's (and other sanitizer's) signal
handlers we should strip the "invalid signature" bit before printing
addresses.  This makes the report less confusing and let's the user
focus on the real issue.

rdar://62615826

Reviewed By: kubamracek, delcypher

Differential Revision: https://reviews.llvm.org/D79132
2020-05-06 18:32:31 -07:00
Vitaly Buka
d9c529c2a8 [lsan] Fix warnings lit config 2020-05-05 22:42:14 -07:00
Vitaly Buka
d059d01c23 [dfsan] Remove realloc from done_abilist.txt
Summary:
Currently, realloc is marked as "discard" in done_abilist.txt. As discussed in PR#45583, this is probably not the expected behavior; a custom wrapper seems to be required. Since this wrapper has not been implemented yet, realloc should not be in the done_abilist.txt file so that a warning is displayed when it is called.

Reviewers: kcc, pcc, vitalybuka

Reviewed By: vitalybuka

Subscribers: #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78379
2020-05-05 22:32:45 -07:00
Dan Liew
4155784cdf Try to make duplicate_os_log_reports.cpp more reliable.
It looks like some bots are failing with os log not giving any
output. This might be due to the system under test being heavy
load so the 2 minute window might not be large enough. This
patch makes the window larger in the hope that this test will
be more reliable.

rdar://problem/62141527
2020-05-04 13:49:55 -07:00
Peter Collingbourne
8fac07a12a scudo: Exclude previous tag when retagging freed memory.
This means that immediate use after free will be detected 100% of
the time.

Differential Revision: https://reviews.llvm.org/D79216
2020-05-01 09:35:38 -07:00
Evgenii Stepanov
45b7d44ecb [scudo] Zero- and pattern-initialization of memory.
Summary:
Implement pattern initialization of memory (excluding the secondary
allocator because it already has predictable memory contents).
Expose both zero and pattern initialization through the C API.

Reviewers: pcc, cryptoad

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D79133
2020-04-30 15:00:55 -07:00
Evgenii Stepanov
7a555958f1 [scudo] Initialize the allocator in setTrackAllocationStacks.
Summary:
If this is called before the malloc call in a thread (or in the whole
program), the lazy initialization of the allocation can overwrite
Options.

Reviewers: pcc, cryptoad

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D79130
2020-04-29 17:01:58 -07:00
Julian Lettner
d56f62e0df [compiler-rt] Fix issue related to switch to Python3 in lit config 2020-04-29 14:34:32 -07:00
Julian Lettner
82ed13cd28 [Darwin] Fix compilation issues on arm64
Newer iOS SDK introduce accessors to retrieve the register values
(arm_thread_state64_get_*) and disallows direct access to fields. If
arm_thread_state64_get_sp is defined, the accessors are available.
2020-04-29 13:46:59 -07:00
Nico Weber
e071ea48e9 Unbreak check-builtins on macOS after Python3 switch.
See https://crbug.com/1076480 for details.
2020-04-29 16:42:14 -04:00
Vitaly Buka
efba642171 Revert "[tsan] Relax stack trace check"
Edited hwasan by mistake.

This reverts commit a3b942edc8.
2020-04-28 23:57:03 -07:00
Vitaly Buka
d1fafa40b8 [tsan] Relax stack trace check
With GCC 8 stack is different.
2020-04-28 23:57:03 -07:00
Vitaly Buka
a3b942edc8 [tsan] Relax stack trace check
With GCC 8 stack is different.
2020-04-28 14:06:00 -07:00
Saleem Abdulrasool
a5d79e5fa1 build: use Python3 for compiler-rt
compiler-rt is built in a unified configuration on some of the builders
which requires that this is updated to follow the same pattern as LLVM.
2020-04-28 17:29:04 +00:00
KAWASHIMA Takahiro
89f6a2376e [gcov][test] Work around PR45673 - NFC
Work around PR45673 until the test code is fixed.
2020-04-28 20:19:19 +09:00
Ian Levesque
4b9bef7e6c [xray] Preserve x8 in trampoline on AArch64
Summary: Fixes an ABI violation in the trampoline code for AArch64 that causes the indirect result register to get overwritten if the XRay handler function is complex enough to use it.

Reviewers: MaskRay, dberris, johnislarry

Subscribers: kristof.beyls, danielkiss, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78596
2020-04-27 14:57:26 -04:00
Ayke van Laethem
4d41df6482
[builtins] Support architectures with 16-bit int
This is the first patch in a series to add support for the AVR target.
This patch includes changes to make compiler-rt more target independent
by not relying on the width of an int or long.

Differential Revision: https://reviews.llvm.org/D78662
2020-04-26 01:22:10 +02:00
Pratyai Mazumder
73812f3d0b [SanitizerCoverage] Add __sanitizer_cov_bool_flag_init as the weak interface functions.
Summary:
Following up the discussion on D77638 (and following rGd6cfed6060c283dc4a6bf9ca294dcd732e8b9f72
as example), defining `__sanitizer_cov_bool_flag_init` as the weak interface
functions in various compiler-rt/ files.

Reviewers: vitalybuka

Reviewed By: vitalybuka

Subscribers: dberris, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D77857
2020-04-24 19:54:54 -07:00
Fangrui Song
10bc12588d [XRay] Change Sled.Function to PC-relative for sled version 2 and make llvm-xray support sled version 2 addresses
Follow-up of D78082 and D78590.

Otherwise, because xray_instr_map is now read-only, the absolute
relocation used for Sled.Function will cause a text relocation.
2020-04-24 14:41:56 -07:00
Fangrui Song
25e22613df [XRay] Change ARM/AArch64/powerpc64le to use version 2 sled (PC-relative address)
Follow-up of D78082 (x86-64).

This change avoids dynamic relocations in `xray_instr_map` for ARM/AArch64/powerpc64le.

MIPS64 cannot use 64-bit PC-relative addresses because R_MIPS_PC64 is not defined.
Because MIPS32 shares the same code, for simplicity, we don't use PC-relative addresses for MIPS32 as well.

Tested on AArch64 Linux and ppc64le Linux.

Reviewed By: ianlevesque

Differential Revision: https://reviews.llvm.org/D78590
2020-04-24 08:35:43 -07:00
Ayke van Laethem
1109dcba20
[builtins] Add void prototype to unprototyped functions
This patch replaces () prototypes with (void) prototypes.

Differential Revision: https://reviews.llvm.org/D78641
2020-04-22 21:43:44 +02:00
Peter Collingbourne
3616e851f6 scudo: Change the macro used to check whether we're targeting the platform.
Differential Revision: https://reviews.llvm.org/D78594
2020-04-22 10:32:51 -07:00
Ian Levesque
5081468a66 [xray] Avoid text relocations in trampolines for ARM/AArch64
Summary: Switch to pc-relative lookup of the xray handler function to avoid text relocations.

Reviewers: MaskRay, dberris, johnislarry

Subscribers: kristof.beyls, danielkiss, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78595
2020-04-21 23:21:02 -04:00
Ian Levesque
eeaabe64e3 [xray] Use hidden symbol visibility for xray trampolines
Summary: We load multiple copies of the trampolines into memory when instrumenting DSOs.  Hidden visibility prevents conflicts in this scenario.

Reviewers: MaskRay, dberris, johnislarry

Subscribers: #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78593
2020-04-21 23:19:52 -04:00
Dan Liew
da820f4f57 Add missing call to __sanitizer::InitializePlatformEarly() in UBSan's standalone init.
Summary:
While working on rdar://problem/62083617 I noticed this call was
missing.

This is a no-op for all platforms except Darwin. For Darwin this
means the `use_xnu_fast_mmap` flag is initialized as it was intended
when using UBSan in standalone mode.

Reviewers: vitalybuka, vsk, kubamracek, yln, samsonov

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78532
2020-04-21 18:43:43 -07:00
Dan Liew
564530e50a Add missing call to Symbolizer::LateInitialize() in UBSan's standalone init.
Summary:
This fixes symbolization in Standalone UBSan mode for the Darwin simulators.

861b69faee (rdar://problem/58789439) tried to fix
symbolization for all sanitizers on Darwin simulators but unfortunately it only
fixed the problem for TSan.

For UBSan in standalone mode the fix wasn't sufficient because UBSan's
standalone init doesn't call `Symbolizer::LateInitialize()` like ASan
and TSan do. This meant that `AtosSymbolizerProcess::LateInitialize()`
was never being called before
`AtosSymbolizerProcess::StartSymbolizerSubprocess()` which breaks an
invariant we expect to hold.

The missing call to `Symbolizer::LateInitialize()` during UBSan's
standalone init seems like an accidently omission so this patch simply
adds it.

rdar://problem/62083617

Reviewers: vitalybuka, kubamracek, yln, samsonov

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78530
2020-04-21 18:43:33 -07:00
Dan Liew
c860262bd2 Disable a Darwin test under LSan.
* Changing source lines seems to cause us to hit rdar://problem/62132428.
* Even if I workaround the above issue sometimes the source line in the dylib reported by atos is off by one.

It's simpler to just disable the test for now.

rdar://problem/61793759
2020-04-21 15:17:21 -07:00
Evgenii Stepanov
2e1cfd02d0 Fix Solaris build of ubsan.
Summary: Broken in D78325.

Reviewers: ro

Subscribers: mgorny, fedor.sergeev, #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78510
2020-04-21 12:06:30 -07:00
Fangrui Song
5771c98562 [XRay] Change xray_instr_map sled addresses from absolute to PC relative for x86-64
xray_instr_map contains absolute addresses of sleds, which are relocated
by `R_*_RELATIVE` when linked in -pie or -shared mode.

By making these addresses relative to PC, we can avoid the dynamic
relocations and remove the SHF_WRITE flag from xray_instr_map.  We can
thus save VM pages containg xray_instr_map (because they are not
modified).

This patch changes x86-64 and bumps the sled version to 2. Subsequent
changes will change powerpc64le and AArch64.

Reviewed By: dberris, ianlevesque

Differential Revision: https://reviews.llvm.org/D78082
2020-04-21 09:36:09 -07:00
Dan Liew
7039773b24 Unbreak ASan runtime in the simulators.
Summary:
861b69faee (rdar://problem/58789439) while
fixing symbolization for TSan completely broke ASan's runtime for the
simulators.

The problem with the previous patch is that the memory passed to
`putenv()` was poisoned and when passed to `putenv()` it tripped
an interceptor for `strchr()` which saw the memory was poisoned and
raised an ASan issue.

The memory was poisoned because `AtosSymbolizerProcess` objects
are created using ASan's internal allocator. Memory from this
allocator gets poisoned with `kAsanInternalHeapMagic`.

To workaround this, this patch makes the memory for the environment
variable entry a global variable that isn't poisoned.

This pass also adds a `DCHECK(getenv(K_ATOS_ENV_VAR))` because the
following DCHECK would crash because `internal_strcmp()` doesn't
work on nullptr.

rdar://problem/62067724

Reviewers: kubamracek, yln

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78525
2020-04-20 19:08:08 -07:00
Sam Kerner
e5ce95c660 [dfsan] Fix a bug in strcasecmp() and strncasecmp(): Compare the lowercase versions of the characters when choosing a return value.
Summary:
Resolves this bug:

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

Reviewers: morehouse, pcc

Reviewed By: morehouse

Subscribers: #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78490
2020-04-20 17:13:40 -07:00
Oliver Stannard
78fe93030f [LSan] Disable a failing test on ARM
This started failing after an OS upgrade on a buildbot machine, and I
don't see anything obvious to fix or revert, so disable it for now to
get the bot green.

Covered by https://bugs.llvm.org/show_bug.cgi?id=44158

Differential revision: https://reviews.llvm.org/D78496
2020-04-20 17:48:19 +01:00
Julian Lettner
a54e18df0a [compiler-rt] Use --standalone when running tests on the iOS simulator
We can use `simctl spawn --standalone` to enable running tests without
the need for an already-booted simulator instance.  This also side-steps
the problem of not having a good place to shutdown the instance after
we are finished with testing.

rdar://58118442

Reviewed By: delcypher

Differential Revision: https://reviews.llvm.org/D78409
2020-04-20 08:42:57 -07:00
kpdev
1b0436cd4b [scudo] Silent warning for u64 -> u32 convertion
Error is raised because of using -Werror=convertion
2020-04-17 09:29:55 +03:00
Petr Hosek
6919b708a1 [CMake] Set UBSAN_LINK_FLAGS for ubsan
This variable is being used, but it's not being set (it's only set
for ubsan_minimal, but not ubsan). This addresses a regression that
was introduced in D78325.

Differential Revision: https://reviews.llvm.org/D78410
2020-04-17 23:21:59 -07:00
Peter Collingbourne
21d50019ca scudo: Add support for diagnosing memory errors when memory tagging is enabled.
Introduce a function __scudo_get_error_info() that may be called to interpret
a crash resulting from a memory error, potentially in another process,
given information extracted from the crashing process. The crash may be
interpreted as a use-after-free, buffer overflow or buffer underflow.

Also introduce a feature to optionally record a stack trace for each
allocation and deallocation. If this feature is enabled, a stack trace for
the allocation and (if applicable) the deallocation will also be available
via __scudo_get_error_info().

Differential Revision: https://reviews.llvm.org/D77283
2020-04-17 17:26:30 -07:00
Dan Liew
861b69faee [Darwin] Fix symbolization for recent simulator runtimes.
Summary:
Due to sandbox restrictions in the recent versions of the simulator runtime the
atos program is no longer able to access the task port of a parent process
without additional help.

This patch fixes this by registering a task port for the parent process
before spawning atos and also tells atos to look for this by setting
a special environment variable.

This patch is based on an Apple internal fix (rdar://problem/43693565) that
unfortunately contained a bug (rdar://problem/58789439) because it used
setenv() to set the special environment variable. This is not safe because in
certain circumstances this can trigger a call to realloc() which can fail
during symbolization leading to deadlock. A test case is included that captures
this problem.

The approach used to set the necessary environment variable is as
follows:

1. Calling `putenv()` early during process init (but late enough that
malloc/realloc works) to set a dummy value for the environment variable.

2. Just before `atos` is spawned the storage for the environment
variable is modified to contain the correct PID.

A flaw with this approach is that if the application messes with the
atos environment variable (i.e. unsets it or changes it) between the
time its set and the time we need it then symbolization will fail. We
will ignore this issue for now but a `DCHECK()` is included in the patch
that documents this assumption but doesn't check it at runtime to avoid
calling `getenv()`.

The issue reported in rdar://problem/58789439 manifested as a deadlock
during symbolization in the following situation:

1. Before TSan detects an issue something outside of the runtime calls
setenv() that sets a new environment variable that wasn't previously
set. This triggers a call to malloc() to allocate a new environment
array. This uses TSan's normal user-facing allocator. LibC stores this
pointer for future use later.

2. TSan detects an issue and tries to launch the symbolizer. When we are in the
symbolizer we switch to a different (internal allocator) and then we call
setenv() to set a new environment variable. When this happen setenv() sees
that it needs to make the environment array larger and calls realloc() on the
existing enviroment array because it remembers that it previously allocated
memory for it. Calling realloc() fails here because it is being called on a
pointer its never seen before.

The included test case closely reproduces the originally reported
problem but it doesn't replicate the `((kBlockMagic)) ==
((((u64*)addr)[0])` assertion failure exactly. This is due to the way
TSan's normal allocator allocates the environment array the first time
it is allocated. In the test program addr[0] accesses an inaccessible
page and raises SIGBUS. If TSan's SIGBUS signal handler is active, the
signal is caught and symbolication is attempted again which results in
deadlock.

In the originally reported problem the pointer is successfully derefenced but
then the assert fails due to the provided pointer not coming from the active
allocator. When the assert fails TSan tries to symbolicate the stacktrace while
already being in the middle of symbolication which results in deadlock.

rdar://problem/58789439

Reviewers: kubamracek, yln

Subscribers: jfb, #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78179
2020-04-17 15:08:14 -07:00
Fangrui Song
17772995d4 [builtins] Add missing header in D77912 and make __builtin_clzll more robust 2020-04-17 08:29:58 -07:00
Petr Hosek
485862ecda [profile] Avoid duplicating or leaking VMO
Now that write data continously into the memory mapping, we don't need
to keep the VMO handle around after it has been mapped. This change also
ensures that the VMO is always closed on error.

Differential Revision: https://reviews.llvm.org/D76963
2020-04-17 00:54:12 -07:00
Evgenii Stepanov
77e3a2e0fe [ubsan] Link shared runtime library with a version script.
Summary:
Do not reexport libgcc.a symbols and random sanitizer internal symbols
by applying a version script to the shared library build.

This fixes unwinder conflicts on Android that are created by reexporting
the unwinder interface from libgcc_real.a. The same is already done in
asan and hwasan.

Reviewers: vitalybuka, srhines

Subscribers: mgorny, #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78325
2020-04-16 17:33:54 -07:00
Dan Liew
fccea7f372 [NFC] Introduce a LateInitialize() method to SymbolizerTool that is called during the LateInitialize stage of the sanitizer runtimes.
Summary:
This is implemented by adding a `Symbolizer::LateInitializeTools()`
method that iterates over the registered tools and calls the
`LateInitialize()` method on them.

`Symbolizer::LateInitializeTools()` is now called from the various
`Symbolizer::LateInitialize()` implementations.

The default implementation of `SymbolizerTool::LateInitialize()`
does nothing so this change should be NFC.

This change allows `SymbolizerTool` implementations to perform
any initialization that they need to perform at the
LateInitialize stage of a sanitizer runtime init.

rdar://problem/58789439

Reviewers: kubamracek, yln, vitalybuka, cryptoad, phosek, rnk

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78178
2020-04-16 17:25:58 -07:00
Pratyai Mazumder
a1526cd62b [NFC, tsan] Update tsan tests expectation
Summary:
These tests pass with clang, but fail if gcc was used.
gcc build creates similar but not the same stacks.

Reviewers: vitalybuka

Reviewed By: vitalybuka

Subscribers: dvyukov, llvm-commits, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78114
2020-04-16 17:19:52 -07:00
Julian Lettner
80022ae2b5 [UBSan] Fix vptr checks on arm64e
Fix UBSan's vptr checks in the presence of arm64e pointer signing.

Radar-Id: rdar://61786404

Reviewed By: vsk

Differential Revision: https://reviews.llvm.org/D78230
2020-04-16 16:09:05 -07:00