Commit Graph

12188 Commits

Author SHA1 Message Date
Jake Ehrlich cde860a1c9 [libFuzzer] Don't prefix absolute paths in fuchsia.
The ExecuteCommand function in fuchsia used to prefix the
getOutputFile for each command run with the artifact_prefix flag if
it was available, because fuchsia components don't have a writable working
directory. However, if a file with a global path is provided, fuchsia
should honor that.

An example of this is using the global /tmp directory to store stuff.
In fuchsia it ended up being translated to data///tmp, whereas we want
to make sure it is using /tmp (which is available to components using the
isolated-temp feature).

To test this I made the change, compiled fuchsia with this toolchain and
ran a fuzzer with the -fork=1 flag (that mode makes use of the /tmp
directory). I also tested that normal fuzzing workflow was not affected
by this.

Author: charco (Marco Vanotti)
Differential Revision: https://reviews.llvm.org/D68774

llvm-svn: 374612
2019-10-11 23:35:13 +00:00
Reid Kleckner 9280d6c178 Fix check-interception link error in compiler-rt debug mode
llvm-svn: 374472
2019-10-10 23:30:54 +00:00
Evgeniy Stepanov 53a53e63c8 Add a missing include in test.
A fix for r373993.

llvm-svn: 374448
2019-10-10 20:47:22 +00:00
Julian Lettner 99c9d7bd63 Reland "[ASan] Do not misrepresent high value address dereferences as null dereferences"
Updated: Removed offending TODO comment.

Dereferences with addresses above the 48-bit hardware addressable range
produce "invalid instruction" (instead of "invalid access") hardware
exceptions (there is no hardware address decoding logic for those bits),
and the address provided by this exception is the address of the
instruction (not the faulting address).  The kernel maps the "invalid
instruction" to SEGV, but fails to provide the real fault address.

Because of this ASan lies and says that those cases are null
dereferences.  This downgrades the severity of a found bug in terms of
security.  In the ASan signal handler, we can not provide the real
faulting address, but at least we can try not to lie.

rdar://50366151

Reviewed By: vitalybuka

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

> llvm-svn: 374265

llvm-svn: 374384
2019-10-10 17:19:58 +00:00
David Carlier 69c9c223a0 [Sanitizers] Fix getrandom test
llvm-svn: 374333
2019-10-10 12:48:18 +00:00
Russell Gallop 38ac46b4bc Fix sanitizer lint check after r374315
llvm-svn: 374321
2019-10-10 12:02:31 +00:00
Roman Lebedev 6430adbe64 [UBSan] Appease linter
llvm-svn: 374316
2019-10-10 11:32:06 +00:00
David Carlier 90c8b59cfc [Sanitizers] Porting getrandom/getentropy interceptors to FreeBSD
- Available from 12.x branch, by the time it lands next year in FreeBSD tree, the 11.x's might be EOL.
- Intentionally changed the getrandom test to C code as with 12.0 (might be fixed in CURRENT since), there is a linkage issue in C++ context.

Reviewers: emaste, dim, vitalybuka

Reviewed-By: vitalybuka

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

llvm-svn: 374315
2019-10-10 11:31:37 +00:00
Roman Lebedev eb8b6fe745 [UBSan] Split nullptr-and-nonzero-offset-variable.c in another direction
llvm-svn: 374309
2019-10-10 11:03:41 +00:00
Russell Gallop c48e0873af Revert "[ASan] Do not misrepresent high value address dereferences as null dereferences"
As it was breaking bots running sanitizer lint check

This reverts r374265 (git b577efe456)

llvm-svn: 374308
2019-10-10 10:56:52 +00:00
Roman Lebedev 5d59f20cc0 [UBSan] Split nullptr-and-nonzero-offset-variable.cpp into C and C++ variants
I do not understand the BB failire, it fully passes locally.

llvm-svn: 374306
2019-10-10 10:41:42 +00:00
Roman Lebedev 3de28b83c2 [UBSan] Revisit nullptr-and-nonzero-offset-variable.cpp test to hopefully make it pass on sanitizer-windows BB
llvm-svn: 374298
2019-10-10 09:51:13 +00:00
Roman Lebedev 536b0ee40a [UBSan][clang][compiler-rt] Applying non-zero offset to nullptr is undefined behaviour
Summary:
Quote from http://eel.is/c++draft/expr.add#4:
```
4     When an expression J that has integral type is added to or subtracted
      from an expression P of pointer type, the result has the type of P.
(4.1) If P evaluates to a null pointer value and J evaluates to 0,
      the result is a null pointer value.
(4.2) Otherwise, if P points to an array element i of an array object x with n
      elements ([dcl.array]), the expressions P + J and J + P
      (where J has the value j) point to the (possibly-hypothetical) array
      element i+j of x if 0≤i+j≤n and the expression P - J points to the
      (possibly-hypothetical) array element i−j of x if 0≤i−j≤n.
(4.3) Otherwise, the behavior is undefined.
```

Therefore, as per the standard, applying non-zero offset to `nullptr`
(or making non-`nullptr` a `nullptr`, by subtracting pointer's integral value
from the pointer itself) is undefined behavior. (*if* `nullptr` is not defined,
i.e. e.g. `-fno-delete-null-pointer-checks` was *not* specified.)

To make things more fun, in C (6.5.6p8), applying *any* offset to null pointer
is undefined, although Clang front-end pessimizes the code by not lowering
that info, so this UB is "harmless".

Since rL369789 (D66608 `[InstCombine] icmp eq/ne (gep inbounds P, Idx..), null -> icmp eq/ne P, null`)
LLVM middle-end uses those guarantees for transformations.
If the source contains such UB's, said code may now be miscompiled.
Such miscompilations were already observed:
* https://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20190826/687838.html
* https://github.com/google/filament/pull/1566

Surprisingly, UBSan does not catch those issues
... until now. This diff teaches UBSan about these UB's.

`getelementpointer inbounds` is a pretty frequent instruction,
so this does have a measurable impact on performance;
I've addressed most of the obvious missing folds (and thus decreased the performance impact by ~5%),
and then re-performed some performance measurements using my [[ https://github.com/darktable-org/rawspeed | RawSpeed ]] benchmark:
(all measurements done with LLVM ToT, the sanitizer never fired.)
* no sanitization vs. existing check: average `+21.62%` slowdown
* existing check vs. check after this patch: average `22.04%` slowdown
* no sanitization vs. this patch: average `48.42%` slowdown

Reviewers: vsk, filcab, rsmith, aaron.ballman, vitalybuka, rjmccall, #sanitizers

Reviewed By: rsmith

Subscribers: kristof.beyls, nickdesaulniers, nikic, ychen, dtzWill, xbolva00, dberris, arphaman, rupprecht, reames, regehr, llvm-commits, cfe-commits

Tags: #clang, #sanitizers, #llvm

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

llvm-svn: 374293
2019-10-10 09:25:02 +00:00
Julian Lettner b577efe456 [ASan] Do not misrepresent high value address dereferences as null dereferences
Dereferences with addresses above the 48-bit hardware addressable range
produce "invalid instruction" (instead of "invalid access") hardware
exceptions (there is no hardware address decoding logic for those bits),
and the address provided by this exception is the address of the
instruction (not the faulting address).  The kernel maps the "invalid
instruction" to SEGV, but fails to provide the real fault address.

Because of this ASan lies and says that those cases are null
dereferences.  This downgrades the severity of a found bug in terms of
security.  In the ASan signal handler, we can not provide the real
faulting address, but at least we can try not to lie.

rdar://50366151

Reviewed By: vitalybuka

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

llvm-svn: 374265
2019-10-10 00:33:04 +00:00
Matt Morehouse da6cb7ba4c [sanitizer_common] Remove OnPrint from Go build.
Summary: Go now uses __sanitizer_on_print instead.

Reviewers: vitalybuka, dvyukov

Reviewed By: vitalybuka

Subscribers: llvm-commits

Tags: #llvm

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

llvm-svn: 374258
2019-10-09 22:57:07 +00:00
Jake Ehrlich e7bfce7863 [libFuzzer] Fix Alarm callback in fuchsia.
This patch adds an #if macro to skip the InFuzzingThread() comparison
for fuchsia, similar to what it is done for Windows and NetBSD.

In fuchsia, the alarm callback runs in a separate thread[0], making it fail
the comparison InFuzzingThread(), breaking the -timeout flag.

[0]:
https://github.com/llvm/llvm-project/blob/master/compiler-rt/lib/fuzzer/FuzzerUtilFuchsia.cpp#L323

Author: charco (aka Marco  Vanotti)
Differential Revision: https://reviews.llvm.org/D68166

llvm-svn: 374228
2019-10-09 21:01:50 +00:00
Vitaly Buka ff5a7c4ca6 [sanitizer, NFC] Fix grammar in comment
llvm-svn: 374223
2019-10-09 20:52:39 +00:00
Vitaly Buka 3afc77dbbc [sanitizer] Disable signal_trap_handler on s390
llvm-svn: 374220
2019-10-09 20:48:50 +00:00
Vitaly Buka 39f759189d [sanitizer] Make signal_name a C test
llvm-svn: 374213
2019-10-09 20:22:14 +00:00
Vitaly Buka c3317658cf [sanitizer] Use raise() in test and cover more signals
llvm-svn: 374211
2019-10-09 20:18:27 +00:00
Kostya Kortchinsky f7b1489ffc [scudo][standalone] Get statistics in a char buffer
Summary:
Following up on D68471, this CL introduces some `getStats` APIs to
gather statistics in char buffers (`ScopedString` really) instead of
printing them out right away. Ultimately `printStats` will just
output the buffer, but that allows us to potentially do some work
on the intermediate buffer, and can be used for a `mallocz` type
of functionality. This allows us to pretty much get rid of all the
`Printf` calls around, but I am keeping the function in for
debugging purposes.

This changes the existing tests to use the new APIs when required.

I will add new tests as suggested in D68471 in another CL.

Reviewers: morehouse, hctim, vitalybuka, eugenis, cferris

Reviewed By: morehouse

Subscribers: delcypher, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

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

llvm-svn: 374173
2019-10-09 15:09:28 +00:00
Vitaly Buka d5f92e345c [sanitizer] Fix crypt.cpp on Android again
llvm-svn: 374125
2019-10-08 22:09:51 +00:00
Vitaly Buka f3ae951c09 [sanitizer] Fix crypt.cpp test on Darwin
llvm-svn: 374115
2019-10-08 20:50:46 +00:00
Dan Liew 196eae533b Fix `compiler_rt_logbf_test.c` test failure for Builtins-i386-darwin test suite.
Summary:
It seems that compiler-rt's implementation and Darwin
libm's implementation of `logbf()` differ when given a NaN
with raised sign bit. Strangely this behaviour only happens with
i386 Darwin libm. For x86_64 and x86_64h the existing compiler-rt
implementation matched Darwin libm.

To workaround this the `compiler_rt_logbf_test.c` has been modified
to do a comparison on the `fp_t` type and if that fails check if both
values are NaN. If both values are NaN they are equivalent and no
error needs to be raised.

rdar://problem/55565503

Reviewers: rupprecht, scanon, compnerd, echristo
Subscribers: #sanitizers, llvm-commits
Tags: #llvm, #sanitizers
Differential Revision: https://reviews.llvm.org/D67999

llvm-svn: 374109
2019-10-08 20:06:01 +00:00
Vitaly Buka d8245e7a36 [sanitizer] Disable crypt*.cpp tests on Android
llvm-svn: 374088
2019-10-08 17:06:27 +00:00
David Carlier d80c2520d9 [builtins] Unbreak build on FreeBSD armv7 after D60351
headers include reordering.

Reviewers: phosek, echristo

Reviewed-By: phosek

Differential Revsion: https://reviews.llvm.org/D68045

llvm-svn: 374070
2019-10-08 15:45:35 +00:00
Vitaly Buka 54d767f508 [sanitizer] Fix signal_trap_handler.cpp on android
llvm-svn: 374010
2019-10-08 02:00:53 +00:00
Evgeniy Stepanov 2e2c934762 [msan] Add interceptors: crypt, crypt_r.
Reviewers: vitalybuka

Subscribers: srhines, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

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

llvm-svn: 373993
2019-10-08 00:00:30 +00:00
Vitaly Buka 2fdec42a16 [tsan, go] fix Go windows build
Summary:
Don't use weak exports when building tsan into a shared library for Go. gcc can't handle the pragmas used to make the weak references.

Include files that have been added since the last update to build.bat. (We should really find a better way to list all the files needed.)

Add windows version defines (WINVER and _WIN32_WINNT) to get AcquireSRWLockExclusive and ReleaseSRWLockExclusive defined.

Define GetProcessMemoryInfo to use the kernel32 version. This is kind of a hack, the windows header files should do this translation for us. I think we're not in the right family partition (we're using Desktop, but that translation only happens for App and System partitions???), but hacking the family partition seems equally gross and I have no idea what the consequences of that might be.

Patch by Keith Randall.

Reviewers: dvyukov, vitalybuka

Reviewed By: vitalybuka

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

Tags: #llvm, #sanitizers

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

llvm-svn: 373984
2019-10-07 23:11:07 +00:00
Vitaly Buka 2059105637 [tsan, go] break commands into multiple lines
Summary: Patch by Keith Randall.

Reviewers: dvyukov, vitalybuka

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

Tags: #llvm, #sanitizers

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

llvm-svn: 373983
2019-10-07 23:04:16 +00:00
Vitaly Buka 9917c76107 [sanitizer] Print SIGTRAP for corresponding signal
Reviewers: eugenis, jfb

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

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

llvm-svn: 373979
2019-10-07 22:43:19 +00:00
Vitaly Buka 87dd968849 [tsan] Don't delay SIGTRAP handler
Reviewers: eugenis, jfb

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

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

llvm-svn: 373978
2019-10-07 22:43:17 +00:00
Kostya Kortchinsky bebdab63e8 [scudo][standalone] Correct releaseToOS behavior
Summary:
There was an issue in `releaseToOSMaybe`: one of the criteria to
decide if we should proceed with the release was wrong. Namely:

```
const uptr N = Sci->Stats.PoppedBlocks - Sci->Stats.PushedBlocks;
if (N * BlockSize < PageSize)
  return; // No chance to release anything.
```

I meant to check if the amount of bytes in the free list was lower
than a page, but this actually checks if the amount of **in use** bytes
was lower than a page.

The correct code is:

```
const uptr BytesInFreeList =
  Region->AllocatedUser -
  (Region->Stats.PoppedBlocks - Region->Stats.PushedBlocks) * BlockSize;
if (BytesInFreeList < PageSize)
  return 0; // No chance to release anything.
```

Consequences of the bug:
- if a class size has less than a page worth of in-use bytes (allocated
  or in a cache), reclaiming would not occur, whatever the amount of
  blocks in the free list; in real world scenarios this is unlikely to
  happen and be impactful;
- if a class size had less than a page worth of free bytes (and enough
  in-use bytes, etc), then reclaiming would be attempted, with likely
  no result. This means the reclaiming was overzealous at times.

I didn't have a good way to test for this, so I changed the prototype
of the function to return the number of bytes released, allowing to
get the information needed. The test added fails with the initial
criteria.

Another issue is that `ReleaseToOsInterval` can actually be 0, meaning
we always try to release (side note: it's terrible for performances).
so change a `> 0` check to `>= 0`.

Additionally, decrease the `CanRelease` threshold to `PageSize / 32`.
I still have to make that configurable but I will do it at another time.

Finally, rename some variables in `printStats`: I feel like "available"
was too ambiguous, so change it to "total".

Reviewers: morehouse, hctim, eugenis, vitalybuka, cferris

Reviewed By: morehouse

Subscribers: delcypher, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

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

llvm-svn: 373930
2019-10-07 17:37:39 +00:00
Kostya Kortchinsky dc802dbef2 [scudo][standalone] Make malloc_info return a minimal XML
Summary:
Initially, our malloc_info was returning ENOTSUP, but Android would
rather have it return successfully and write a barebone XML to the
stream, so we will oblige.

Add an associated test.

Reviewers: cferris, morehouse, hctim, eugenis, vitalybuka

Reviewed By: morehouse

Subscribers: delcypher, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

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

llvm-svn: 373754
2019-10-04 15:46:34 +00:00
Vitaly Buka bb91a833c6 [compiler-rt] Remove O1 tests from signal_line.cpp
It does not work on arm

llvm-svn: 373702
2019-10-04 07:25:53 +00:00
Vitaly Buka 053391fa86 [compiler-rt] Fix signal_line.cpp test
r373682 committed wrong experimental version

llvm-svn: 373684
2019-10-04 00:43:05 +00:00
Vitaly Buka 57b6536ba1 [compiler-rt] Remove O2, O3 from signal_line test for fix android tests
llvm-svn: 373682
2019-10-04 00:38:08 +00:00
Vitaly Buka 161229eb1b compiler-rt: use __GLIBC_PREREQ for SANITIZER_INTERCEPT_GETRANDOM
Summary: Fixes https://github.com/google/oss-fuzz/issues/2836

Reviewers: eugenis

Subscribers: dberris, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

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

llvm-svn: 373681
2019-10-04 00:38:07 +00:00
Vitaly Buka 6fb03a290b [compiler-rt] More optimization levels in signal_line.cpp test
llvm-svn: 373642
2019-10-03 18:18:35 +00:00
Vitaly Buka 1fff2881a8 compiler-rt: move all __GLIBC_PREREQ into own header file
Reviewers: eugenis

Subscribers: dberris, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

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

llvm-svn: 373632
2019-10-03 17:46:07 +00:00
Matt Morehouse 629cad1266 Move SanitizerInitializeUnwinder outside anonymous namespace.
Fixes the Android build breakage introduced in r373528.

llvm-svn: 373539
2019-10-02 22:57:37 +00:00
Matt Morehouse 4d39410b1e [sanitizer_common] Declare __sanitizer_on_print in Windows interception.
Speculative fix for Windows bot.

llvm-svn: 373532
2019-10-02 22:00:29 +00:00
Matt Morehouse 38ac6bdb83 [sanitizer_common] Disable onprint.cpp on Android.
The test fails to find the written file on Android.

llvm-svn: 373531
2019-10-02 21:38:22 +00:00
Matt Morehouse 62f190ce9a [sanitizer_common] Add __sanitizer_on_print to interface list.
Should fix the current Windows buildbot failure.

llvm-svn: 373530
2019-10-02 21:21:18 +00:00
Vitaly Buka d39e7e2cf1 [compiler-rt] Use GetNextInstructionPc in signal handlers
Summary:
All other stack trace callers assume that PC contains return address.
HWAsan already use GetNextInstructionPc in similar code.

PR43339

Reviewers: eugenis, kcc, jfb

Subscribers: dexonsmith, dberris, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

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

llvm-svn: 373529
2019-10-02 21:20:37 +00:00
Vitaly Buka 59bf75caab NFC: add namespace {}
llvm-svn: 373528
2019-10-02 21:20:32 +00:00
Matt Morehouse e55c442b1b [sanitizer_common] Rename OnPrint to __sanitizer_on_print.
Summary:
https://reviews.llvm.org/D28596 exposed OnPrint in the global namespace,
which can cause collisions with user-defined OnPrint() functions.

Reviewers: vitalybuka, dvyukov

Reviewed By: vitalybuka, dvyukov

Subscribers: llvm-commits

Tags: #llvm

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

llvm-svn: 373518
2019-10-02 20:13:21 +00:00
Dan Liew bbde056b88 [CMake] Fix the value of `config.target_cflags` for non-macOS Apple platforms. Attempt #3.
The main problem here is that `-*-version_min=` was not being passed to
the compiler when building test cases. This can cause problems when
testing on devices running older OSs because Clang would previously
assume the minimum deployment target is the the latest OS in the SDK
which could be much newer than what the device is running.

Previously the generated value looked like this:

`-arch arm64 -isysroot
<path_to_xcode>/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk`

With this change it now looks like:

`-arch arm64 -stdlib=libc++ -miphoneos-version-min=8.0 -isysroot
<path_to_xcode>/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk`

This mirrors the setting of config.target_cflags on macOS.

This change is made for ASan, LibFuzzer, TSan, and UBSan.

To implement this a new `get_test_cflags_for_apple_platform()` function
has been added that when given an Apple platform name and architecture
returns a string containing the C compiler flags to use when building
tests. This also calls a new helper function `is_valid_apple_platform()`
that validates Apple platform names.

This is the third attempt at landing the patch.

The first attempt (r359305) had to be reverted (r359327) due to a buildbot
failure. The problem was that calling `get_test_cflags_for_apple_platform()`
can trigger a CMake error if the provided architecture is not supported by the
current CMake configuration. Previously, this could be triggered by passing
`-DCOMPILER_RT_ENABLE_IOS=OFF` to CMake. The root cause is that we were
generating test configurations for a list of architectures without checking if
the relevant Sanitizer actually supported that architecture. We now intersect
the list of architectures for an Apple platform with
`<SANITIZER>_SUPPORTED_ARCH` (where `<SANITIZER>` is a Sanitizer name) to
iterate through the correct list of architectures.

The second attempt (r363633) had to be reverted (r363779) due to a build
failure. The failed build was using a modified Apple toolchain where the iOS
simulator SDK was missing. This exposed a bug in the existing UBSan test
generation code where it was assumed that `COMPILER_RT_ENABLE_IOS` implied that
the toolchain supported both iOS and the iOS simulator. This is not true. This
has been fixed by using the list `SANITIZER_COMMON_SUPPORTED_OS` for the list
of supported Apple platforms for UBSan. For consistency with the other
Sanitizers we also now intersect the list of architectures with
UBSAN_SUPPORTED_ARCH.

rdar://problem/50124489

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

llvm-svn: 373405
2019-10-01 23:08:18 +00:00
Matt Morehouse 1c8e05110c [libFuzzer] Remove lazy counters.
Summary: Lazy counters haven't improved performance for large fuzz targets.

Reviewers: kcc

Reviewed By: kcc

Subscribers: llvm-commits

Tags: #llvm

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

llvm-svn: 373403
2019-10-01 22:49:06 +00:00
Vitaly Buka 3ee619c112 Revert "compiler-rt: use __GLIBC_PREREQ for SANITIZER_INTERCEPT_GETRANDOM"
Revert "compiler-rt: move all __GLIBC_PREREQ into own header file"

"move all __GLIBC_PREREQ" breaks build on some bots

This reverts commit 2d75ee9373.
This reverts commit 7a6461fcc2.

llvm-svn: 373367
2019-10-01 18:03:11 +00:00