Commit Graph

48 Commits

Author SHA1 Message Date
Fangrui Song 2d7fd38cf7 [sanitizers] Remove unneeded MaybeCall*DefaultOptions() and nullptr checks
D28596 added SANITIZER_INTERFACE_WEAK_DEF which can guarantee `*_default_options` are always defined.
The weak attributes on the `__{asan,lsan,msan,ubsan}_default_options` declarations can thus be removed.

`MaybeCall*DefaultOptions` no longer need nullptr checks, so their call sites can just be replaced by `__*_default_options`.

Reviewed By: #sanitizers, vitalybuka

Differential Revision: https://reviews.llvm.org/D87175
2020-09-08 10:12:05 -07:00
Vitaly Buka 0b1ea8cb28 Improve error message when '=' is missing in {ASAN,...}_OPTIONS.
Summary:
It's handling isses as described here:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89832

Patch by Martin Liška.

Reviewers: kcc, vitalybuka

Reviewed By: vitalybuka

Subscribers: cryptoad, kubamracek

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

llvm-svn: 363480
2019-06-15 01:37:14 +00:00
Nico Weber 77d972b94c cfi: Rename source file from cc to cpp
See discussion on https://reviews.llvm.org/D58620 for the review.

llvm-svn: 355144
2019-02-28 22:03:41 +00:00
Evgeniy Stepanov 443c034391 [sanitizer] Decorate /proc/self/maps better.
Summary:
Refactor the way /proc/self/maps entries are annotated to support most
(all?) posix platforms, with a special implementation for Android.
Extend the set of decorated Mmap* calls.

Replace shm_open with internal_open("/dev/shm/%s"). Shm_open is
problematic because it calls libc open() which may be intercepted.

Generic implementation has limits (max number of files under /dev/shm is
64K on my machine), which can be conceivably reached when sanitizing
multiple programs at once. Android implemenation is essentially free, and
enabled by default.

The test in sanitizer_common is copied to hwasan and not reused directly
because hwasan fails way too many common tests at the moment.

Reviewers: pcc, vitalybuka

Subscribers: srhines, kubamracek, jfb, llvm-commits, kcc

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

llvm-svn: 353255
2019-02-06 01:14:50 +00:00
Chandler Carruth 2946cd7010 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

llvm-svn: 351636
2019-01-19 08:50:56 +00:00
David Carlier 50a46a5961 Unbreak linux cfi build
llvm-svn: 343512
2018-10-01 18:14:02 +00:00
David Carlier dc0624844f [Cfi] Compiling cfi library on FreeBSD and NetBSD
Making the library slighty more portable.

Reviewers: vitalybuka, krytarowski

Reviewed By: vitalybuka

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

llvm-svn: 343510
2018-10-01 18:01:55 +00:00
Peter Collingbourne dfd1c96d97 cfi: Remove blacklist entries for libc++.
These functions have had no-CFI annotations in the source code for
a while now.

llvm-svn: 339800
2018-08-15 18:05:55 +00:00
Chandler Carruth 4abbd13ab2 Fix warnings in a static assert added to CFI.
llvm-svn: 337178
2018-07-16 15:01:26 +00:00
Filipe Cabecinhas 3bc3fb477a [cfi] Don't pass a uint16_t to memset. Make sure the 16-bit constant is appropriate for us.
Reviewers: eugenis, pcc, kcc

Subscribers: delcypher, #sanitizers, llvm-commits

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

llvm-svn: 337170
2018-07-16 13:41:54 +00:00
Kostya Kortchinsky 754da0cc7e [sanitizer] Build failures fixes post D45457
Summary: Adding a couple missed RTSanitizerCommonSymbolizer in makefiles.

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

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

llvm-svn: 330134
2018-04-16 16:58:34 +00:00
Kostya Kortchinsky 988fab3f66 [sanitizer] Split coverage into separate RT in sanitizer_common
Summary:
`sanitizer_common`'s coverage support is fairly well separated, and libcdep by
default. Several sanitizers don't make use of coverage, and as far as I can
tell do no benefit from the extra dependencies pulled in by the coverage public
interface functions.

The following sanitizers call `InitializeCoverage` explicitely: MSan, ASan,
LSan, HWAsan, UBSan. On top of this, any sanitizer bundling RTUBSan should
add the coverage RT as well: ASan, Scudo, UBSan, CFI (diag), TSan, MSan, HWAsan.

So in the end the following have no need: DFSan, ESan, CFI, SafeStack (nolibc
anyway), XRay, and the upcoming Scudo minimal runtime.

I tested this with all the sanitizers check-* with gcc & clang, and in
standalone on Linux & Android, and there was no issue. I couldn't test this on
Mac, Fuchsia, BSDs, & Windows for lack of an environment, so adding a bunch of
people for additional scrunity. I couldn't test HWAsan either.

Reviewers: eugenis, vitalybuka, alekseyshl, flowerhack, kubamracek, dberris, rnk, krytarowski

Reviewed By: vitalybuka, alekseyshl, flowerhack, dberris

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

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

llvm-svn: 328204
2018-03-22 15:04:31 +00:00
Vitaly Buka 1aa98f4294 [cfi] Lazy initialization of CFI interceptors
Summary:
Interceptors initialization may need to allocate memory. So if we initialize too
early we can crash in non initialized allocator.

Reviewers: pcc, eugenis

Subscribers: llvm-commits

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

llvm-svn: 326025
2018-02-24 06:58:56 +00:00
Peter Collingbourne 7351a22b7d cfi: Add a blacklist entry for MSVC's std::get_temporary_buffer function.
Differential Revision: https://reviews.llvm.org/D42150

llvm-svn: 322607
2018-01-17 01:15:33 +00:00
Evgeniy Stepanov 0379d3f844 (NFC) Rename GetMax{,User}VirtualAddress.
Future change will introduce GetMaxVirtualAddress that will not take
the kernel area into account.

llvm-svn: 317638
2017-11-07 23:51:22 +00:00
Vlad Tsyrklevich a0b02833bc Limit CFI blacklist entries to specific CFI mode
Summary:
Since D37924 and D37925 were merged, it's now possible to specify
individual sanitizers or CFI modes in sanitizer blacklists. Update the
CFI blacklist entries to only apply to cfi-unrelated-cast checks.

Reviewers: eugenis, pcc

Reviewed By: eugenis

Subscribers: kcc

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

llvm-svn: 315216
2017-10-09 17:11:44 +00:00
Peter Collingbourne 107a9f624d Make the cfi target available on more platforms.
On non-Linux targets it just installs the blacklist.

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

llvm-svn: 315215
2017-10-09 17:07:47 +00:00
Vlad Tsyrklevich 8d7755e7aa CFI: Move STL allocator blacklist to clang
Summary:
The regular expression to match STL allocators can't easily account for
C++ mangling compression and fails to match some valid instances of STL
allocators. Perform this logic in clang instead.

Motivated by crbug.com/751385.

Reviewers: pcc, kcc, llvm-commits

Reviewed By: pcc

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

llvm-svn: 310109
2017-08-04 20:04:01 +00:00
Peter Collingbourne 36df72b50a Remove STL/microsoft-specific CFI blacklist entries
Patch by Vlad Tsyrklevich!

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

llvm-svn: 309617
2017-07-31 20:39:32 +00:00
Peter Collingbourne 44781f1b0c CFI: Add a blacklist entry for std::_Sp_counted_ptr_inplace::_Sp_counted_ptr_inplace().
This ctor is used by std::make_shared and needs to cast to uninitialized T*
in order to call std::allocator_traits<T>::construct.

llvm-svn: 302272
2017-05-05 18:46:14 +00:00
Evgeniy Stepanov bacee5c04f [cfi] Accept weak definition of __cfi_check.
https://reviews.llvm.org/D31796 results in LLD emitting __cfi_check
as a weak symbol, while Gold keeps it strong. Accept both.

llvm-svn: 299804
2017-04-07 22:52:08 +00:00
Evgeniy Stepanov 7e94d38374 [cfi] Fix symbol lookup hack in cross-dso cfi to handle LLD binaries.
llvm-svn: 299604
2017-04-06 00:34:45 +00:00
Mike Aizatsky 9700acba11 Revert "[sancov] moving sancov rt to sancov/ directory"
This reverts commit https://reviews.llvm.org/rL291734
Reason: mac breakage
http://lab.llvm.org:8080/green//job/clang-stage1-configure-RA_build/28798/consoleFull#1657087648e9a0fee5-ebcc-4238-a641-c5aa112c323e

llvm-svn: 291736
2017-01-12 01:37:35 +00:00
Mike Aizatsky 875572f358 [sancov] moving sancov rt to sancov/ directory
Subscribers: kubabrecka, mgorny

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

llvm-svn: 291734
2017-01-12 01:19:34 +00:00
Anna Zaks 691644f3ca [compiler-rt] Do not introduce __sanitizer namespace globally
The definitions in sanitizer_common may conflict with definitions from system headers because:

The runtime includes the system headers after the project headers (as per LLVM coding guidelines).
lib/sanitizer_common/sanitizer_internal_defs.h pollutes the namespace of everything defined after it, which is all/most of the sanitizer .h and .cc files and the included system headers with: using namespace __sanitizer; // NOLINT
This patch solves the problem by introducing the namespace only within the sanitizer namespaces as proposed by Dmitry.

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

llvm-svn: 281657
2016-09-15 21:02:18 +00:00
Chris Bieneman 21395f9839 [CMake] Connect Compiler-RT targets to LLVM Runtimes directory
This patch builds on LLVM r279776.

In this patch I've done some cleanup and abstracted three common steps runtime components have in their CMakeLists files, and added a fourth.

The three steps I abstract are:

(1) Add a top-level target (i.e asan, msan, ...)
(2) Set the target properties for sorting files in IDE generators
(3) Make the compiler-rt target depend on the top-level target

The new step is to check if a command named "runtime_register_component" is defined, and to call it with the component name.

The runtime_register_component command is defined in llvm/runtimes/CMakeLists.txt, and presently just adds the component to a list of sub-components, which later gets used to generate target mappings.

With this patch a new workflow for runtimes builds is supported. The new workflow when building runtimes from the LLVM runtimes directory is:

> cmake [...]
> ninja runtimes-configure
> ninja asan

The "runtimes-configure" target builds all the dependencies for configuring the runtimes projects, and runs CMake on the runtimes projects. Running the runtimes CMake generates a list of targets to bind into the top-level CMake so subsequent build invocations will have access to some of Compiler-RT's targets through the top-level build.

Note: This patch does exclude some top-level targets from compiler-rt libraries because they either don't install files (sanitizer_common), or don't have a cooresponding `check` target (stats).
llvm-svn: 279863
2016-08-26 20:52:22 +00:00
Etienne Bergeron ab42f4ddba [compiler-rt] Fix VisualStudio virtual folders layout
Summary:
This patch is a refactoring of the way cmake 'targets' are grouped.
It won't affect non-UI cmake-generators.

Clang/LLVM are using a structured way to group targets which ease
navigation through Visual Studio UI. The Compiler-RT projects
differ from the way Clang/LLVM are grouping targets.

This patch doesn't contain behavior changes.

Reviewers: kubabrecka, rnk

Subscribers: wang0109, llvm-commits, kubabrecka, chrisha

Differential Revision: http://reviews.llvm.org/D21952

llvm-svn: 275111
2016-07-11 21:51:56 +00:00
Mike Aizatsky 6d8a876159 [sancov] common flags initialization.
Summary:
Introducing InitializeCommonFlags accross all sanitizers to simplify
common flags management.

Setting coverage=1 when html_cov_report is requested.

Differential Revision: http://reviews.llvm.org/D18273

llvm-svn: 263820
2016-03-18 19:28:07 +00:00
Chris Bieneman 86792ea718 [CMake] Assign components and dependencies during add_compiler_rt_resource_file
This makes it so that component-based installations will include resource files (i.e. blacklists). My next patch will add support for component-based installations.

llvm-svn: 261699
2016-02-23 21:50:39 +00:00
Evgeniy Stepanov 73583d5f2d [cfi] Safe handling of unaddressable vtable pointers (compiler-rt).
Avoid crashing when printing diagnostics for vtable-related CFI
errors. In diagnostic mode, the frontend does an additional check of
the vtable pointer against the set of all known vtable addresses and
lets the runtime handler know if it is safe to inspect the vtable.

http://reviews.llvm.org/D16824

llvm-svn: 259717
2016-02-03 22:19:04 +00:00
Alexey Samsonov f54e67dcc9 Cast the fifth arg to mremap to void *
Summary:
Since the prototype of mremap is

```
void *mremap(void *old_address, size_t old_size, size_t new_size,
             int flags, ... /* void *new_address*/);
```
we need to cast new_address to void * when calling mremap.  Otherwise,
the wrong value will be passed to mremap on x32.

Patch by H.J Lu!

Reviewers: kcc, eugenis, samsonov

Subscribers: samsonov, llvm-commits

Differential Revision: http://reviews.llvm.org/D16805

llvm-svn: 259540
2016-02-02 18:36:28 +00:00
Evgeniy Stepanov dfef2cf502 [cfi] Simplify the code in CfiSlowPathCommon.
llvm-svn: 259085
2016-01-28 19:58:26 +00:00
Evgeniy Stepanov 4a09234cb7 [cfi] Fix recovery from out-of-bounds vtable error.
llvm-svn: 259007
2016-01-28 00:37:54 +00:00
Evgeniy Stepanov ecfa524ee3 [cfi] Fix gcc build.
llvm-svn: 258977
2016-01-27 19:33:00 +00:00
Evgeniy Stepanov a25dde68d9 [cfi] Exclude __cfi_slowpath_diag from the non-diag rtl.
Calls to __cfi_slowpath_diag are only emitted when building with
diagnostics, and linking the diag rtl.

llvm-svn: 258881
2016-01-26 23:42:41 +00:00
Evgeniy Stepanov 40d7d02d3d [cfi] Better handling of wild target address.
This change enables diagnostics when the target address for a CFI
check is out of bounds of any known library, or even not in the
limits of the address space. This happens when casting pointers to
uninitialized memory.

Ubsan code does not yet handle some of these situations correctly,
so it is still possible to see a segmentation fault instead of a
proper diagnostic message once in a while.

llvm-svn: 258879
2016-01-26 23:36:28 +00:00
Evgeniy Stepanov 79685810f1 [cfi] Hide runtime implementation in a namespace.
Move all internal stuff into namespace __cfi.
Remove the double underscore prefix from anything that's now inside
the namespace.

llvm-svn: 258859
2016-01-26 21:06:26 +00:00
Evgeniy Stepanov a9e0584cce [cfi] Support for dlopen and dlclose.
Add dlopen/dlclose interceptors to update CFI shadow for loaded/unloaded libraries.

llvm-svn: 258857
2016-01-26 20:53:09 +00:00
Evgeniy Stepanov 226965259d [cfi] Cross-DSO CFI diagnostic mode (compiler-rt part)
* add __cfi_slowpath_diag with a 3rd parameter which is a pointer to
  the diagnostic info for the ubsan handlers.
*__cfi_check gets a 3rd parameter as well.
* unify vcall/cast/etc and icall diagnostic info format, and merge
  the handlers to have a single entry point (actually two points due
  to abort/noabort variants).
* tests

Note that this comes with a tiny overhead in the non-diag mode:
cfi_slowpath must pass 0 as the 3rd argument to cfi_check.

llvm-svn: 258744
2016-01-25 23:34:38 +00:00
Evgeniy Stepanov 6742d75952 [cfi] Fix __cfi_slowpath and __cfi_check signature.
The first argument is uint64_t, not uintptr_t.

llvm-svn: 257233
2016-01-08 23:42:30 +00:00
Evgeniy Stepanov f02b782aa7 [cfi] Fix handling of uninstrumented libraries.
CFI shadow for non-CFI libraries should be "unchecked", not "invalid".

llvm-svn: 256285
2015-12-22 21:40:09 +00:00
Evgeniy Stepanov 72b0111ce6 [cfi] Exclude ubsan runtime library from non-diag CFI builds.
Split the CFI runtime in two: cfi and cfi_diag. The latter includes
UBSan runtime to allow printing diagnostics.

llvm-svn: 255735
2015-12-16 00:38:41 +00:00
Evgeniy Stepanov 702a773988 [cfi] Fix GCC build.
llvm-svn: 255733
2015-12-16 00:34:30 +00:00
Evgeniy Stepanov b99d6c8b2a [cfi] Fix shadow sanity check.
The current check may break if the starting address in fill_shadow is
not page-aligned.

llvm-svn: 255725
2015-12-16 00:18:04 +00:00
Evgeniy Stepanov da1cf9287c Cross-DSO control flow integrity (compiler-rt part).
This is an initial version of the runtime cross-DSO CFI support
library.

It contains a number of FIXMEs, ex. it does not support the
diagnostic mode nor dlopen/dlclose, but it works and can be tested.
Diagnostic mode, in particular, would require some refactoring (we'd
like to gather all CFI hooks in the UBSan library into one function
so that we could easier pass the diagnostic information down to
__cfi_check). It will be implemented later.

Once the diagnostic mode is in, I plan to create a second test
configuration to run all existing tests in both modes. For now, this
patch includes only a few new cross-DSO tests.

llvm-svn: 255695
2015-12-15 23:00:33 +00:00
Peter Collingbourne cd5d761c3e CFI: Make the cfi target a dependency of compiler-rt.
This causes the blacklist to be copied into place as a default build step.

llvm-svn: 246617
2015-09-02 02:18:46 +00:00
Peter Collingbourne 4c5b0a3d58 CFI: Add blacklist entries for various standard library functions.
llvm-svn: 246602
2015-09-01 23:00:56 +00:00
Peter Collingbourne 1d14b0757d CFI: Add a default blacklist.
Differential Revision: http://reviews.llvm.org/D11095

llvm-svn: 242287
2015-07-15 12:16:25 +00:00