Commit Graph

9824 Commits

Author SHA1 Message Date
Kamil Rytarowski ccb970ee03 Correct a bug in GetArgsAndEnv() for NetBSD
Fix setting envp.

llvm-svn: 324481
2018-02-07 14:05:57 +00:00
Petr Hosek 2f70693e08 [Fuzzer] Use Zircon's public API on Fuchsia
The original libFuzzer Fuchsia port relied on convenience libraries,
but these are not exported as part of Fuchsia sysroot. This change
eliminates the use of these libraries and relies on public API only.

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

llvm-svn: 324454
2018-02-07 08:22:58 +00:00
Vitaly Buka ca8d201070 [Sanitizers, Darwin] Disable SANITIZER_SUPPORTS_WEAK_HOOKS before Mac OS X 10.9
Summary:
Before Xcode 4.5, undefined weak symbols don't work reliably on Darwin:
https://stackoverflow.com/questions/6009321/weak-symbol-link-on-mac-os-x
Therefore this patch disables their use before Mac OS X 10.9 which is the first version
only supported by Xcode 4.5 and above.

Reviewers: glider, kcc, vitalybuka

Reviewed By: vitalybuka

Subscribers: llvm-commits

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

llvm-svn: 324284
2018-02-05 23:02:09 +00:00
Kostya Kortchinsky 02f6845095 [sanitizer] Revert rL324263
Summary:
The 32-bit division  breaks SizeClassAllocator64PopulateFreeListOOM which uses
Primary that has a maximum size > 32-bit.

Reviewers: alekseyshl

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

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

llvm-svn: 324268
2018-02-05 20:17:24 +00:00
Kostya Kortchinsky d6f7a65197 [sanitizer] SizeClassMap minor improvement/correctness changes
Summary:
In `ClassID`, make sure we use an unsigned as based for the `lbits` shift.
The previous code resulted in spurious sign extensions like for x64:
```
add     esi, 0FFFFFFFFh
movsxd  rcx, esi
and     rcx, r15
```
The code with the `U` added is:
```
add     esi, 0FFFFFFFFh
and     rsi, r15
```
And for `MaxCachedHint`, use a 32-bit division instead of `64-bit`, which is
faster (https://lemire.me/blog/2017/11/16/fast-exact-integer-divisions-using-floating-point-operations/)
and already used in other parts of the code (64-bit `GetChunkIdx`, 32-bit
`GetMetaData` enforce 32-bit divisions)

Not major performance gains by any mean, but they don't hurt.

Reviewers: alekseyshl

Reviewed By: alekseyshl

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

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

llvm-svn: 324263
2018-02-05 19:22:56 +00:00
Kostya Kortchinsky 5c6e6c28c4 [sanitizer] Allocator local cache improvements
Summary:
Here are a few improvements proposed for the local cache:
- `InitCache` always read from `per_class_[1]` in the fast path. This was not
  ideal as we are working with `per_class_[class_id]`. The latter offers the
  same property we are looking for (eg: `max_count != 0` means initialized),
  so we might as well use it and keep our memory accesses local to the same
  `per_class_` element. So change `InitCache` to take the current `PerClass`
  as an argument. This also makes the fast-path assembly of `Deallocate` a lot
  more compact;
- Change the 32-bit `Refill` & `Drain` functions to mimic their 64-bit
  counterparts, by passing the current `PerClass` as an argument. This saves
  some array computations;
- As far as I can tell, `InitCache` has no place in `Drain`: it's either called
  from `Deallocate` which calls `InitCache`, or from the "upper" `Drain` which
  checks for `c->count` to be greater than 0 (strictly). So remove it there.
- Move the `stats_` updates to after we are done with the `per_class_` accesses
  in an attempt to preserve locality once more;
- Change some `CHECK` to `DCHECK`: I don't think the ones changed belonged in
  the fast path and seemed to be overly cautious failsafes;
- Mark some variables as `const`.

The overall result is cleaner more compact fast path generated code, and some
performance gains with Scudo (and likely other Sanitizers).

Reviewers: alekseyshl

Reviewed By: alekseyshl

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

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

llvm-svn: 324257
2018-02-05 18:06:45 +00:00
Kamil Rytarowski c0dc9bb93e Handle NetBSD symbol mangling devname -> __devname50
llvm-svn: 324240
2018-02-05 14:50:01 +00:00
Kuba Mracek f1ddefb55f Use NULL instead of nullptr in invalid-pointer-pairs-compare-null.cc; nullptr is not available on older Darwin systems.
llvm-svn: 324136
2018-02-02 20:42:29 +00:00
Kuba Mracek 66ce45150f [asan] Make concurrent_overflow.cc less flaky
The "sleep(5)" sometimes times out on our bots, causing the test to fail. Let's use pthread_join.

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

llvm-svn: 324126
2018-02-02 19:49:24 +00:00
Kamil Rytarowski 78c9ac4dc5 Correct FileCheck usage in two newly added tests
llvm-svn: 324121
2018-02-02 18:48:15 +00:00
Kamil Rytarowski e6bba9bc6f Add new NetBSD interceptors: devname(3), devname_r(3)
Summary:
devname, devname_r - get device name

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, vitalybuka

Reviewed By: vitalybuka

Subscribers: kubamracek, llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 324120
2018-02-02 18:45:33 +00:00
Kamil Rytarowski 42983551bd Correct the return value of strlcat(3) in the interceptor
Late fix for SVN r. 324034
Add new interceptors: strlcpy(3) and strlcat(3)

There was forgotten an addition of len to the return value.

llvm-svn: 324091
2018-02-02 13:56:52 +00:00
Kamil Rytarowski e2f8718b50 Add new interceptors: strlcpy(3) and strlcat(3)
Summary:
NetBSD ships with strlcpy(3) and strlcat(3), a safe
replacement of strcpy(3) and strcat(3).

Hide both functions under SANITIZER_INTERCEPT_STRLCPY.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, vitalybuka

Reviewed By: vitalybuka

Subscribers: llvm-commits, kubamracek, #sanitizers

Tags: #sanitizers

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

llvm-svn: 324034
2018-02-01 23:34:30 +00:00
Vitaly Buka b2a27efdc0 [sanitizer] Fix array sizes used for path in tests
llvm-svn: 324022
2018-02-01 22:26:18 +00:00
Kuba Mracek 11ee02fd39 Update readlink.c and readlinkat.c to use larger buffers on Darwin.
llvm-svn: 324016
2018-02-01 21:59:51 +00:00
Kostya Kortchinsky 298f224194 [sanitizer] Implement NanoTime & MonotonicNanoTime for Windows
Summary:
Implement `MonotonicNanoTime` using `QueryPerformanceCounter`.

This function is used by Scudo & the 64-bit Primary allocator. Implementing it
now means that the release-to-OS mechanism of the Primary will kick in (it
never did since the function returned 0 always), but `ReleaseMemoryPagesToOS` is
still not currently implemented for Windows.

Performance wise, this adds a syscall & a 64-bit division per call to
`MonotonicNanoTime` so the impact might not be negligible, but I don't think
there is a way around it.

Reviewers: rnk, alekseyshl, amccarth

Reviewed By: alekseyshl, amccarth

Subscribers: amccarth, flowerhack, kubamracek, delcypher, llvm-commits, #sanitizers

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

llvm-svn: 324011
2018-02-01 21:38:14 +00:00
Kostya Kortchinsky 8c4ca0bbea [scudo] Minor Secondary changes
Summary:
Few changes to the secondary:
- mark `const` variables as such;
- change some `CHECK` to `DCHECK`: I don't feel we need to be as conservative as
  we were with out checks, as they are the results of our own computation.
- mark a condition as `UNLIKELY`.

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: delcypher, #sanitizers, llvm-commits

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

llvm-svn: 323997
2018-02-01 20:00:42 +00:00
Alex Shlyapnikov 3c80f4d941 Make detect_invalid_pointer_pairs option to be tristate.
Summary:
With the change, one can choose not to report comparison (or subtraction)
of a pointer with nullptr pointer.

Reviewers: kcc, jakubjelinek, alekseyshl

Reviewed By: alekseyshl

Subscribers: kubamracek

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

llvm-svn: 323995
2018-02-01 19:52:56 +00:00
Jonas Hahnfeld 44ef345c50 [CMake] Remove -stdlib= which is unused when passing -nostdinc++
This avoids the warnings when building with LLVM_ENABLE_LIBCXX
which automatically adds -stdlib=libc++ to CMAKE_CXX_FLAGS.

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

llvm-svn: 323969
2018-02-01 13:57:24 +00:00
Dean Michael Berris cdca0730be [XRay][compiler-rt+llvm] Update XRay register stashing semantics
Summary:
This change expands the amount of registers stashed by the entry and
`__xray_CustomEvent` trampolines.

We've found that since the `__xray_CustomEvent` trampoline calls can show up in
situations where the scratch registers are being used, and since we don't
typically want to affect the code-gen around the disabled
`__xray_customevent(...)` intrinsic calls, that we need to save and restore the
state of even the scratch registers in the handling of these custom events.

Reviewers: pcc, pelikan, dblaikie, eizan, kpw, echristo, chandlerc

Reviewed By: echristo

Subscribers: chandlerc, echristo, hiraditya, davide, dblaikie, llvm-commits

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

llvm-svn: 323940
2018-02-01 02:21:54 +00:00
Vitaly Buka d3fad26588 [sanitizer] Move readlinkat.c test from Linux to Posix
llvm-svn: 323837
2018-01-31 00:04:10 +00:00
Vitaly Buka eca881fc7a [sanitizer] Fix tests on Android and Darwin
llvm-svn: 323834
2018-01-30 23:51:44 +00:00
Petr Hosek b1eaa56704 [fuzzer] Update and enable libFuzzer on Fuchsia
This change updates the Fuchsia-specific code to use the C++ friendly
duration expressions and flips on the building of
libclang_rt.fuzzer-x86_64.a and similar for Fuchsia. Given that
compiler-rt doesn't build on Fuchsia, test have been run by explicitly
building the library and linking it against
lib/fuzzer/tests/FuzzerUnittest.cpp.

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

llvm-svn: 323828
2018-01-30 22:59:48 +00:00
Vitaly Buka 4ec0d9c1b7 [sanitizer] Add interceptors for readlinkat, name_to_handle_at, open_by_handle_at
Summary:
Also move existing readlink msan interceptor to sanitizer_common.

Fixes google/sanitizers#908

Patch by Oliver Chang

Reviewers: vitalybuka, eugenis

Reviewed By: vitalybuka

Subscribers: llvm-commits

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

llvm-svn: 323825
2018-01-30 22:22:12 +00:00
Matt Morehouse 1d8e5ea250 [libFuzzer] Fix sizeof(ptr) bug.
sizeof(const char *) returns 4 or 8 when what we really want is the size
of the array.

llvm-svn: 323802
2018-01-30 18:25:55 +00:00
Kostya Kortchinsky 4223af42b8 [scudo] Add default implementations for weak functions
Summary:
This is in preparation for platforms where `SANITIZER_SUPPORTS_WEAK_HOOKS` is 0.
They require a default implementation.

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: delcypher, llvm-commits, #sanitizers

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

llvm-svn: 323795
2018-01-30 17:59:49 +00:00
Martin Pelikan 1e0d3b43ea [XRay] [compiler-rt] stop writing garbage in naive log records
Summary:
Turns out sizeof(packed) isn't as strong as we'd hoped.  This makes sure
that when we initialize the padding, all 12 bytes will be zero.

Reviewers: dberris, kpw, eizan

Subscribers: delcypher, llvm-commits, #sanitizers

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

llvm-svn: 323755
2018-01-30 13:25:25 +00:00
Kostya Kortchinsky c15da10101 [scudo] Add support for Fuchsia OS.
Summary: Built & tested in Fuchsia's build system.

Reviewers: alekseyshl, cryptoad, aarongreen

Reviewed By: cryptoad

Subscribers: srhines, mgorny

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

llvm-svn: 323685
2018-01-29 20:17:29 +00:00
Dmitry Vyukov e64c4f418c tsan: deflake a test
There was a failure on a bot:
http://lab.llvm.org:8011/builders/clang-cmake-mipsel/builds/1283

strerror test is indeed flaky. We protect all races by a barrier in other tests
to eliminate flakiness. Do the same here.

No idea why tls_race2.cc failed. Add output at the end of the test
as we do in other tests. Sometimes test process crashes somewhere
in the middle (e.g. during race reporting) and it looks like empty output.
Output at the end of test allows to understand if the process has crashed,
or it has finished but produced no race reports.

Reviewed in https://reviews.llvm.org/D42633

llvm-svn: 323657
2018-01-29 15:10:22 +00:00
Don Hinton 23743f48fa Revert: [compiler-rt] r323626 - [cmake] [compiler-rt] Remove duplicate CMAKE_CXX_FLAGS.
Looks like it broke a bot: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-android/builds/7195
Reverting until I have a chance to investigate.

llvm-svn: 323629
2018-01-29 05:32:21 +00:00
Don Hinton 448ef74698 [cmake] [compiler-rt] Remove duplicate CMAKE_CXX_FLAGS.
`set_target_compile_flags()` ultimately sets COMPILE_FLAGS which is
added to CMAKE_CXX_FLAGS in the compile rule, so passing
CMAKE_CXX_FLAGS causes them to be duplicated.

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

llvm-svn: 323626
2018-01-29 05:07:20 +00:00
Kuba Mracek 07d85e46fc [xray] Don't try to run XRay unit tests on Darwin
This gets rid of a lit warning (input './projects/compiler-rt/test/xray/Unit' contained no tests).

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

llvm-svn: 323613
2018-01-28 03:11:25 +00:00
Petr Hosek 9945c44ea6 [sanitizer] Update from zx_time_get to zx_clock_get
This Zircon syscall was renamed.

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

llvm-svn: 323611
2018-01-27 23:58:23 +00:00
Don Hinton 78fd93e039 [cmake] [compiler-rt] Call llvm_setup_rpath() when adding shared libraries.
Clang and llvm already use llvm_setup_rpath(), so this change will
help standarize rpath usage across all projects.

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

llvm-svn: 323606
2018-01-27 21:14:17 +00:00
Hiroshi Inoue d1a6646e59 [NFC] fix trivial typos in comments and documents
"in in" -> "in", "on on" -> "on" etc.

llvm-svn: 323510
2018-01-26 08:16:08 +00:00
Kostya Kortchinsky 4b4db0057f [scudo] Overhaul malloc related interceptors
Summary:
This is a follow-up to D42506.

There are a few of things that bothered me about `scudo_interceptors.cpp`:
- the filename is a misnomer: it intercepts some functions, but the rest (C++)
  is actually in `scudo_new_delete.cpp`. I feel like `scudo_malloc.cpp` is more
  appropriate (ASan uses the same naming scheme);
- we do not need "full" interceptors, since we are never accessing the
  unsanitized version of the functions, we just need the
  `extern "C" INTERCEPTOR_ATTRIBUTE` part of it to just call our functions;
- a couple of functions where duplicated while they could just be `ALIAS`'d;
- use the `SANITIZER_INTERCEPT_*` defines to hide the unneeded interceptors;
- use `SIZE_T` instead of `uptr`: while it's the same behind the curtain,
  the former is meant for this use case.

In the end there is no functional change on the currently supported platforms
(Linux, Android).

Reviewers: alekseyshl

Reviewed By: alekseyshl

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

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

llvm-svn: 323464
2018-01-25 20:42:44 +00:00
Kostya Kortchinsky 896c1c0746 [sanitizer] Implement GetNumberOfCPUs for Windows
Summary:
Implement `GetNumberOfCPUs` using `GetNativeSystemInfo`.
The only consummer of this function is Scudo which is not functional on
Windows yet.

Reviewers: rnk, zturner

Reviewed By: zturner

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

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

llvm-svn: 323462
2018-01-25 20:14:35 +00:00
Kamil Rytarowski 3417a78781 Correct typo in TSan code
We wrongly enabled additional (unwanted) branch for NetBSD.

Noted by Vlad Tsyrklevich

llvm-svn: 323413
2018-01-25 11:07:42 +00:00
Kostya Kortchinsky fc45e4a3f1 [scudo] Remove SANITIZER_LINUX requirement for the malloc interceptors
Summary:
Currently all platforms are using the `scudo_interceptors.cpp` interceptors.

We might to come up with platform specific interceptors when/if we get Apple &
Windows, but as of now, that allows for Fuchsia to use them.

`scudo_new_delete.cpp` didn't have the `#if SANITIZER_LINUX` so it's good to go.

Reviewers: alekseyshl, flowerhack

Reviewed By: flowerhack

Subscribers: delcypher, #sanitizers, llvm-commits

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

llvm-svn: 323386
2018-01-24 22:46:34 +00:00
Martin Storsjo 09bc73d11f [builtins] Align addresses to cache lines in __clear_cache for aarch64
This makes sure that the last cache line gets invalidated properly.

This matches the example code at
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.den0024a/BABJDBHI.html,
and also matches what libgcc does.

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

llvm-svn: 323315
2018-01-24 10:14:52 +00:00
Kamil Rytarowski dfcbdda1e0 Break a line into <= 80 characters
llvm-svn: 323279
2018-01-23 23:14:32 +00:00
Kostya Kortchinsky 1ebebde8b7 [scudo] Allow for weak hooks, gated by a define
Summary:
Hooks in the allocation & deallocation paths can be a security risk (see for an
example https://scarybeastsecurity.blogspot.com/2016/11/0day-exploit-advancing-exploitation.html
which used the glibc's __free_hook to complete exploitation).

But some users have expressed a need for them, even if only for tests and
memory benchmarks. So allow for `__sanitizer_malloc_hook` &
`__sanitizer_free_hook` to be called if defined, and gate them behind a global
define `SCUDO_CAN_USE_HOOKS` defaulting to 0.

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: #sanitizers, llvm-commits

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

llvm-svn: 323278
2018-01-23 23:07:42 +00:00
Kamil Rytarowski 70552c6f53 Add a new interceptor: paccept(2)
Summary:
paccept(2) is a NetBSD-specific variation of accept(2).

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, vitalybuka, eugenis

Reviewed By: vitalybuka

Subscribers: llvm-commits, kubamracek, #sanitizers

Tags: #sanitizers

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

llvm-svn: 323273
2018-01-23 22:41:47 +00:00
Francis Ricci 564f845b74 [ubsan] Add preinit initializer for ubsan
Summary:
Now that ubsan does function interception (for signals), we
need to ensure that ubsan is initialized before any library
constructors are called. Otherwise, if a constructor calls
sigaction, ubsan will intercept in an unitialized state, which
will cause a crash.

This patch is a partial revert of r317757, which removed
preinit arrays for ubsan.

Reviewers: vitalybuka, eugenis, pcc

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

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

llvm-svn: 323249
2018-01-23 19:54:02 +00:00
Bill Seurer e76f2171f9 [PowerPC][asan] Fix asan tests to handle changed memory layouts
In more recent Linux kernels with 47 bit VMAs the layout of virtual memory
for powerpc64 changed causing the address sanitizer to not work properly. This
patch fixes up a test case that was found to fail on some newer Fedora
releases that use different address ranges.

ref: https://reviews.llvm.org/D40907
llvm-svn: 323217
2018-01-23 16:28:17 +00:00
Alex Shlyapnikov ac8217de83 Small fixes for detect_invalid_pointer_pairs.
Summary:
One test-case uses a wrong operation (should be subtraction).
Second test-case should declare a global variables before a tested one
in order to guarantee we will find a red-zone.

Reviewers: kcc, jakubjelinek, alekseyshl

Reviewed By: alekseyshl

Subscribers: kubamracek

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

llvm-svn: 323162
2018-01-22 23:28:52 +00:00
Evgeniy Stepanov 7c70d9d0be [ubsan] Disable signal handling on Android.
Summary: See rationale in the comments.

Reviewers: vitalybuka

Subscribers: srhines, llvm-commits, kubamracek

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

llvm-svn: 323142
2018-01-22 19:26:01 +00:00
Maxim Ostapenko b0d49a604b [lsan] Respect log_path option in standalone LSan
Differential Revision: https://reviews.llvm.org/D42303

llvm-svn: 323083
2018-01-22 09:30:27 +00:00
Hiroshi Inoue 93eaad7dac [NFC] fix trivial typos in comments
"the the" -> "the"

llvm-svn: 323080
2018-01-22 07:51:37 +00:00
Petr Hosek 4dd524ed6a [sanitizer] Pass the CMake compiler to custom libc++ build
This addresses the error introduced in r323054 on some bots.

llvm-svn: 323061
2018-01-21 03:22:22 +00:00