Commit Graph

11484 Commits

Author SHA1 Message Date
Mitch Phillips 85bbf57bf9 [HWASan] Remove address significance from tag_mismatch.
Actually fix the issue referenced in rL355840.

llvm-svn: 355844
2019-03-11 17:34:17 +00:00
Mitch Phillips 5ccb339107 [HWASan] Fixed minor AArch64/GCC build error.
Fixed buildbot clang-cmake-aarch64-lld by ensuring clang-only features
are guarded by clang-only #defines.

llvm-svn: 355840
2019-03-11 17:06:39 +00:00
Mitch Phillips 790edbc16e [HWASan] Save + print registers when tag mismatch occurs in AArch64.
Summary:
This change change the instrumentation to allow users to view the registers at the point at which tag mismatch occured. Most of the heavy lifting is done in the runtime library, where we save the registers to the stack and emit unwind information. This allows us to reduce the overhead, as very little additional work needs to be done in each __hwasan_check instance.

In this implementation, the fast path of __hwasan_check is unmodified. There are an additional 4 instructions (16B) emitted in the slow path in every __hwasan_check instance. This may increase binary size somewhat, but as most of the work is done in the runtime library, it's manageable.

The failure trace now contains a list of registers at the point of which the failure occured, in a format similar to that of Android's tombstones. It currently has the following format:

Registers where the failure occurred (pc 0x0055555561b4):
    x0  0000000000000014  x1  0000007ffffff6c0  x2  1100007ffffff6d0  x3  12000056ffffe025
    x4  0000007fff800000  x5  0000000000000014  x6  0000007fff800000  x7  0000000000000001
    x8  12000056ffffe020  x9  0200007700000000  x10 0200007700000000  x11 0000000000000000
    x12 0000007fffffdde0  x13 0000000000000000  x14 02b65b01f7a97490  x15 0000000000000000
    x16 0000007fb77376b8  x17 0000000000000012  x18 0000007fb7ed6000  x19 0000005555556078
    x20 0000007ffffff768  x21 0000007ffffff778  x22 0000000000000001  x23 0000000000000000
    x24 0000000000000000  x25 0000000000000000  x26 0000000000000000  x27 0000000000000000
    x28 0000000000000000  x29 0000007ffffff6f0  x30 00000055555561b4

... and prints after the dump of memory tags around the buggy address.

Every register is saved exactly as it was at the point where the tag mismatch occurs, with the exception of x16/x17. These registers are used in the tag mismatch calculation as scratch registers during __hwasan_check, and cannot be saved without affecting the fast path. As these registers are designated as scratch registers for linking, there should be no important information in them that could aid in debugging.

Reviewers: pcc, eugenis

Reviewed By: pcc, eugenis

Subscribers: srhines, kubamracek, mgorny, javed.absar, krytarowski, kristof.beyls, hiraditya, jdoerfert, llvm-commits, #sanitizers

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D58857

llvm-svn: 355738
2019-03-08 21:22:35 +00:00
Hubert Tong 57b38a8593 [msan] Properly guard tests added by r355348; NFC
r355348 uses builtins without proper guards, breaking the test on
various platforms.

llvm-svn: 355718
2019-03-08 19:57:27 +00:00
Julian Lettner 9e18875ba3 [TSan] Initialize libdispatch interceptors if necessary
On Linux (and other non-Darwin platforms) we need to initialize
interceptors. Since tsan_libdispatch.cc is compiled optionally, add a
weak default implementation of `InitializeLibdispatchInterceptors`.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D59113

llvm-svn: 355717
2019-03-08 19:52:45 +00:00
Manman Ren e73ae9a142 Reland compiler-rt support for order file instrumentation.
r355343 was landed and was reverted in r355363 due to build breakage.
This patch adds Linux/Windows support on top of r355343.

In this patch, Darwin should be working with testing case. Linux should be working,
I will enable the testing case in a follwup diff. Windows/Other should be building.
Correct implementation for Other platforms will be added.

Thanks David for reviewing the original diff, helping me with issues on Linux, and
giving suggestions for adding support for Other platforms.

llvm-svn: 355701
2019-03-08 15:30:56 +00:00
Clement Courbet a3c43cfd63 [sanitizer] Update global_symbols.txt
Add `bcmp` after r355672.

llvm-svn: 355692
2019-03-08 12:41:42 +00:00
Kostya Kortchinsky 16d9a3a4b6 [scudo][standalone] Adding a stats class
Summary:
This adds simple local & global stats classes to be used by the Primary
and Secondary, and associated test. Note that we don't need the strict
atomicity of the addition & subtraction (as is in sanitizer_common) so
we just use load & store.

Reviewers: morehouse, vitalybuka, eugenis, flowerhack, dmmoore415

Reviewed By: morehouse, vitalybuka

Subscribers: mgorny, delcypher, jfb, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

Differential Revision: https://reviews.llvm.org/D59031

llvm-svn: 355643
2019-03-07 21:44:35 +00:00
Julian Lettner ed77926f99 [TSan] Temporarily disable test which fails on build bot
llvm-svn: 355642
2019-03-07 21:42:48 +00:00
Julian Lettner 9d782f998d [TSan] Temporarily disable test which fails on build bot
llvm-svn: 355633
2019-03-07 20:30:18 +00:00
Vlad Tsyrklevich 2e1479e2f2 Delete x86_64 ShadowCallStack support
Summary:
ShadowCallStack on x86_64 suffered from the same racy security issues as
Return Flow Guard and had performance overhead as high as 13% depending
on the benchmark. x86_64 ShadowCallStack was always an experimental
feature and never shipped a runtime required to support it, as such
there are no expected downstream users.

Reviewers: pcc

Reviewed By: pcc

Subscribers: mgorny, javed.absar, hiraditya, jdoerfert, cfe-commits, #sanitizers, llvm-commits

Tags: #clang, #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D59034

llvm-svn: 355624
2019-03-07 18:56:36 +00:00
Julian Lettner a30357d1e0 [NFC][TSan] Remove unnecessary #include
llvm-svn: 355620
2019-03-07 18:22:22 +00:00
Julian Lettner 011a90b96a [TSan][Linux] Fix libdispatch interception macros compilation errors
Most libdispatch functions come in two variants: callbacks can be
specified via blocks or function pointers. Some of our interceptors for
the block variant actually forward to the function variant. However, on
Linux, `DECLARE_REAL(name)` has to appear before `REAL(name)`.

This patch reorders _f variant interceptors before _b variants
where possible and forward declares the _f variant in the remaining
cases (cyclic dependency between _f and _b interceptors).

Also rename macro to DISPATCH_INTERCEPT_ASYNC_F for better consistency.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D59067

llvm-svn: 355619
2019-03-07 18:15:29 +00:00
Julian Lettner 9ee68ffffd [NFC][TSan] Add libdispatch tests for non-Darwin platforms
Add new sets of tests (copy instead of move existing tests) because
there could be subtle differences between C/Obj-C and with/without
Foundation etc.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D59047

llvm-svn: 355618
2019-03-07 18:15:26 +00:00
Julian Lettner 98a00defe1 [Sanitizer] Add 'dispatch' feature to be used in compiler-rt tests
Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D59037

llvm-svn: 355617
2019-03-07 18:15:23 +00:00
Julian Lettner eacde7d2b0 [NFC][TSan][libdispatch] Rename tsan_block_context_t -> block_context_t
'tsan_' part of the struct name is redundant since we are already inside
the __tsan namespace.

llvm-svn: 355539
2019-03-06 19:27:10 +00:00
Julian Lettner 96ef52ccf0 [tsan] Support interception of libdispatch on Linux
This is a new attempt for bringing TSan libdispatch support to Linux.
The main issue with the last patch (https://reviews.llvm.org/D53171) was
that we want to avoid building a separate library.

The updated plan is as follows:
1) Hide libdispatch support behind a flag: true on Darwin, false
   elsewhere. If flag is specified, assume that libdispatch header and
   -flbocks is available for building. This way we can directly include
   the libdispatch header and rely on blocks runtime for our
   implementation.
2) Optionally/weakly intercept libdispatch API functions.

This patch accomplishes 1). It compiles (without the flag enabled) on
Linux. Follow-up patches will provide 2) and enabling of tests on Linux.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D58935

llvm-svn: 355538
2019-03-06 19:25:09 +00:00
Martin Liska a25a2c7c9a Always compare C++ typeinfo (based on libstdc++ implementation).
Differential Revision: https://reviews.llvm.org/D58028

llvm-svn: 355488
2019-03-06 08:36:50 +00:00
Kostya Kortchinsky 7421f7bd66 [scudo][standalone] Add bytemap classes
Summary:
The bytemap classes will be used by the primary32 allocator to associate
classes with memory regions. It's similar to the sanitizer_common one
except for the fact that the base (level1) maps are mapped instead of
being static to reduce the memory footprint of an uninitialized allocator.

Reviewers: vitalybuka, eugenis, morehouse, flowerhack, dmmoore415, mcgrathr

Reviewed By: vitalybuka, morehouse

Subscribers: mgorny, delcypher, jfb, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

Differential Revision: https://reviews.llvm.org/D58723

llvm-svn: 355416
2019-03-05 17:36:11 +00:00
Martin Storsjo 826624f00a [sanitizers] Don't use Windows Trace Logging with Clang in MSVC mode either
The TraceLoggingProvider.h header does work with clang-cl in general
these days with Win SDK 10.0.17763.0, but when compiled in 32 bit x86
mode, with the -Z7 flag, compilation fails with the following error:

fatal error: error in backend: assembler label '' can not be undefined

With older Win SDKs, there are other build failures (regardless of
architecture or the -Z7 flag).

Differential Revision: https://reviews.llvm.org/D58958

llvm-svn: 355397
2019-03-05 12:50:06 +00:00
Vitaly Buka 816e7b43dc [NFC] Simplify BufferedStackTrace::UnwindImpl
llvm-svn: 355381
2019-03-05 05:52:34 +00:00
Vitaly Buka 1ac22bfef0 [NFC] Move isUnwinding check into ScopedUnwinding
llvm-svn: 355380
2019-03-05 05:40:05 +00:00
Vitaly Buka 7cbb408850 [NFC] Move ScopedUnwinding from .h to .cc
llvm-svn: 355377
2019-03-05 04:36:56 +00:00
Vitaly Buka 4d9d2251ab [NFC] Reorder ifs in BufferedStackTrace::UnwindImpl
llvm-svn: 355376
2019-03-05 04:36:49 +00:00
Vitaly Buka 3d7e9c843b [NFC] Return on SANITIZER_MIPS && !IsValidFrame
llvm-svn: 355372
2019-03-05 02:51:04 +00:00
Vitaly Buka b214bd4b71 [NFC] Put bp into Unwind(.. false) for consistency
It's not used there anyway

llvm-svn: 355371
2019-03-05 02:50:57 +00:00
Vitaly Buka 3eb19449f9 [NFC] Move asan_inited and size reset on top of ::UnwindImpl
llvm-svn: 355370
2019-03-05 02:50:49 +00:00
Vitaly Buka 0d973a5311 Revert "[NFC][Sanitizer] Cleanup ASan's GetStackTrace implementation"
I've missed that UnwindSlow was removed from ScopedUnwinding.

This reverts commit 4ce918e394.

llvm-svn: 355369
2019-03-05 02:35:49 +00:00
Manman Ren ff4bb36d7c Revert compiler-rt diffs for order file instrumentation to get bot green!
This caused issues on Linux/Windows and other platforms.

r355343 355350 355350

llvm-svn: 355363
2019-03-05 01:21:40 +00:00
Manman Ren 31b31e5111 Attemp to fix windows profile-rt build breakage.
Followup to D57530.

llvm-svn: 355357
2019-03-05 00:52:00 +00:00
Julian Lettner 4ce918e394 [NFC][Sanitizer] Cleanup ASan's GetStackTrace implementation
Cleanup ASan's  __sanitizer::BufferedStackTrace::UnwindImpl (formerly
GetStackTrace) implementation. Start with ASan because it is the most
complex implementation.

GetStackTrace implementations seem to have started out as exact copies
of the original implementation in ASan, but have diverged in subtle
ways. My goal is to parameterize this algorithm (via templating or
callbacks) so we can share the implementation and get rid of the
inversed dependency (sanitizer_common depends on concrete
implementations in asan, ubsan, etc.). This should also help us to avoid
those pesky linker errors caused by undefined, duplicate, and weak
symbols on Windows.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D58861

llvm-svn: 355355
2019-03-05 00:41:15 +00:00
Manman Ren 03d5348132 Attemp to fix build brokage due to D57530.
By adding implementations for __llvm_profile_begin_orderfile for non-Darwin platforms.

llvm-svn: 355350
2019-03-04 23:41:57 +00:00
Evgeniy Stepanov 53d7c5cd44 [msan] Instrument x86 BMI intrinsics.
Summary:
They simply shuffle bits. MSan needs to do the same with shadow bits,
after making sure that the shuffle mask is fully initialized.

Reviewers: pcc, vitalybuka

Subscribers: hiraditya, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D58858

llvm-svn: 355348
2019-03-04 22:58:20 +00:00
Evgeniy Stepanov 8cee2e8539 [sanitizer] Intercept bzero.
Summary:
Intercept bzero and enable existing __bzero interceptor in Linux.
bzero is deprecated but still used occasionally.

Reviewers: vitalybuka

Subscribers: srhines, kubamracek, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D58850

llvm-svn: 355347
2019-03-04 22:58:11 +00:00
Manman Ren 4737abc71c Order File Instrumentation: dump the data in compiler-rt
The profile data will be dumped in a file default_xxx.profraw.order.

Differential Revision: https://reviews.llvm.org/D57530

llvm-svn: 355343
2019-03-04 22:28:38 +00:00
Shoaib Meenai 5be71faf4b [build] Rename clang-headers to clang-resource-headers
Summary:
The current install-clang-headers target installs clang's resource
directory headers. This is different from the install-llvm-headers
target, which installs LLVM's API headers. We want to introduce the
corresponding target to clang, and the natural name for that new target
would be install-clang-headers. Rename the existing target to
install-clang-resource-headers to free up the install-clang-headers name
for the new target, following the discussion on cfe-dev [1].

I didn't find any bots on zorg referencing install-clang-headers. I'll
send out another PSA to cfe-dev to accompany this rename.

[1] http://lists.llvm.org/pipermail/cfe-dev/2019-February/061365.html

Reviewers: beanz, phosek, tstellar, rnk, dim, serge-sans-paille

Subscribers: mgorny, javed.absar, jdoerfert, #sanitizers, openmp-commits, lldb-commits, cfe-commits, llvm-commits

Tags: #clang, #sanitizers, #lldb, #openmp, #llvm

Differential Revision: https://reviews.llvm.org/D58791

llvm-svn: 355340
2019-03-04 21:19:53 +00:00
Evgeniy Stepanov 02a913367a Revert "[sanitizer] Fix return type of __bzero and __aeabi_mem* interceptors."
Breaks TSan on Mac, which does
  return REAL(func)(...
in COMMON_INTERCEPTOR_ENTER, which is not OK when REAL(func) has return
type of void.

llvm-svn: 355256
2019-03-02 01:33:52 +00:00
Vlad Tsyrklevich a8af6ca065 Revert "Revert "[sanitizers] Don't use Windows Trace Logging on MinGW""
This reverts my orignal revert in r355250, I misread the buildbot logs.
Volodymyr's commit in r355244 fixed the build.

llvm-svn: 355251
2019-03-02 00:46:54 +00:00
Vlad Tsyrklevich a75077bc73 Revert "[sanitizers] Don't use Windows Trace Logging on MinGW"
This reverts commits r355236 and r355244, they broke the Linux sanitizer
build.

llvm-svn: 355250
2019-03-02 00:39:36 +00:00
Volodymyr Sapsai 738f697a19 [sanitizers] Fix build on macOS with LogFullErrorReport redefinition error.
macOS has implementation of LogFullErrorReport and

    INLINE void LogFullErrorReport(const char *buffer) {}

was causing

> compiler-rt/lib/sanitizer_common/sanitizer_mac.cc:658:6: error: redefinition of 'LogFullErrorReport'

Fixup for r355236.

rdar://problem/48526020

llvm-svn: 355244
2019-03-02 00:05:04 +00:00
Julian Lettner a30b116e6f [NFC][Sanitizer] Replace last uses of old Unwind API
Replace remaining uses of old Unwind API in unit tests.

Allows us to remove the old API and WillUseFastUnwind can be made
private.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D58754

llvm-svn: 355242
2019-03-01 23:50:47 +00:00
Julian Lettner f6ca8cba5c [NFC][Sanitizer] Test unexpectedly passes on ppc64be bot
llvm-svn: 355239
2019-03-01 22:35:40 +00:00
Martin Storsjo ad596c8d8c [CMake] Don't use llvm_replace_compiler_option
Building compiler-rt standalone outside of the main llvm
tree is supported, and in this case, the llvm cmake modules
are unavailable. (And even if they are available, it requires
including LLVMProcessSources.cmake, which currently isn't
included.)

This fixes building compiler-rt standalone with MSVC/clang-cl.

Differential Revision: https://reviews.llvm.org/D58767

llvm-svn: 355237
2019-03-01 22:30:17 +00:00
Martin Storsjo 05394af3ff [sanitizers] Don't use Windows Trace Logging on MinGW
mingw-w64 currently is lacking the headers for this feature.

Make the include lowercase at the same time. We consistently
use lowercase for windows header includes, as windows itself is
case insensitive, the SDK headers (in general, not necessarily
considering this particular header) aren't consistent among themselves
about what the proper canonical capitalization for headers are,
and MinGW uses all lowercase names for the headers (as it is often
used on case sensitive filesystems).

In case mingw-w64 later gets this header, we can revert this
(but keep the include lowercased).

Differential Revision: https://reviews.llvm.org/D58765

llvm-svn: 355236
2019-03-01 22:30:14 +00:00
Julian Lettner 628472dde2 [NFC][Sanitizer][Windows] Fix refactoring oversight
Fix mistake in previous commit: 9fe3b4906f

llvm-svn: 355234
2019-03-01 22:26:45 +00:00
Julian Lettner 9fe3b4906f [NFC][Sanitizer] Make GetStackTrace a private method of BufferedStackTrace
GetStackTrace is a implementation detail of BufferedStackTrace. Make it
a private method.

Reviewed By: vitalybuka

Differential-Revision: https://reviews.llvm.org/D58753
llvm-svn: 355232
2019-03-01 22:10:49 +00:00
Evgeniy Stepanov ddc4b7c1d6 [sanitizer] Fix return type of __bzero and __aeabi_mem* interceptors.
llvm-svn: 355231
2019-03-01 21:59:18 +00:00
Evgeniy Stepanov 72e83488f3 Revert "[sanitizer] Fix return type of __bzero and __aeabi_mem* interceptors."
This change is incomplete.

llvm-svn: 355230
2019-03-01 21:49:40 +00:00
Evgeniy Stepanov 3bbac856f9 [sanitizer] Fix return type of __bzero and __aeabi_mem* interceptors.
They return void, unlike memset/memcpy/memmove.

llvm-svn: 355225
2019-03-01 20:54:16 +00:00
Evgeniy Stepanov c7b322a3d9 [msan] Add an interceptor for ttyname().
llvm-svn: 355214
2019-03-01 18:22:44 +00:00