Commit Graph

11138 Commits

Author SHA1 Message Date
Evgeniy Stepanov d398471a63 [hwasan] Switch to 64 allocator with a dense size class map.
Summary:
Replace the 32-bit allocator with a 64-bit one with a non-constant
base address, and reduce both the number of size classes and the maximum
size of per-thread caches.

As measured on [1], this reduces average weighted memory overhead
(MaxRSS) from 26% to 12% over stock android allocator. These numbers
include overhead from code instrumentation and hwasan shadow (i.e. not a
pure allocator benchmark).

This switch also enables release-to-OS functionality, which is not
implemented in the 32-bit allocator. I have not seen any effect from
that on the benchmark.

[1] https://android.googlesource.com/platform/system/extras/+/master/memory_replay/

Reviewers: vitalybuka, kcc

Subscribers: kubamracek, cryptoad, llvm-commits

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

llvm-svn: 350370
2019-01-03 23:19:02 +00:00
Kuba Mracek 66d5d4a3d6 Re-disable the sanitizer_common/TestCases/Posix/getfsent.cc test. Recent macOS versions don't have the /etc/fstab file any more so we cannot test getfsent/setfsent APIs on Darwin.
llvm-svn: 350331
2019-01-03 17:26:29 +00:00
David Carlier 28dab60859 [Sanitizer] Fix typo in funopen unit test.
llvm-svn: 350259
2019-01-02 20:23:47 +00:00
Julian Lettner ff43aa7e43 [TSan] Enable detection of lock-order-inversions for Objective-C @synchronized
Summary:
@synchronized semantics can be synthesized by using existing mutex_[un]lock operations.

```
@synchronized(obj) {
  // ...
}

=> 
{
  mutex_lock(obj);
  // ...
  mutex_unlock(obj);
}
```
Let me know whether you think this a good idea.

Reviewers: dcoughlin, dvyukov, kubamracek, delcypher

Reviewed By: dvyukov

Subscribers: llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 350258
2019-01-02 20:10:30 +00:00
David Carlier 5e164b53db [Sanitizer] Disable arc4random seeding apis on for Non NetBSD platforms.
- arc4random_stir / arc4random_addrandom had been made obsolete (and removed) from FreeBSD 12.

Reviewers: krytarowski

Reviewed By: krytarowski

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

llvm-svn: 350249
2019-01-02 19:11:44 +00:00
David Carlier 205b709366 [Sanitizer] Enable funopen on FreeBSD
Reviewers: krytarowski

Reviewed By: krytarowski

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

llvm-svn: 350248
2019-01-02 19:07:27 +00:00
Evgeniy Stepanov f5f1fb594b [sanitizer] Android does not provide <fstab.h>
llvm-svn: 350246
2019-01-02 19:05:26 +00:00
Michal Gorny 3d25e8d9f8 [sanitizer_common] Implement funopen*() interceptors for NetBSD
Differential Revision: https://reviews.llvm.org/D56158

llvm-svn: 350233
2019-01-02 17:37:14 +00:00
Michal Gorny 71a75307ae [sanitizer_common] Implement popen, popenve, pclose interceptors
Implement the interceptors for popen(), pclose() and popenve()
functions.  The first two are POSIX, the third one is specific
to NetBSD.  popen() spawns a process and creates a FILE object piping
data from/to that process.  pclose() closes the pipe and waits for
the process to terminate appropriately.

For the purpose of popen(), the COMMON_INTERCEPTOR_FILE_OPEN macro is
modified to allow null path parameter.

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

llvm-svn: 350232
2019-01-02 17:37:09 +00:00
Michal Gorny 7cab4722d3 [sanitizer_common] Add tests for NetBSD funopen*() functions
Differential Revision: https://reviews.llvm.org/D56154

llvm-svn: 350231
2019-01-02 17:37:04 +00:00
Michal Gorny f2208068dc [sanitizer_common] Add test for popen()
Differential Revision: https://reviews.llvm.org/D56153

llvm-svn: 350230
2019-01-02 17:37:00 +00:00
Michal Gorny eebec78b05 [sanitizer_common] Add tests for more *putc and *getc variants
Add tests for the more character-oriented functions, that is:
- fputc(), putc() and putchar()
- getc_unlocked()
- putc_unlocked() and putchar_unlocked()

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

llvm-svn: 350229
2019-01-02 17:36:55 +00:00
Michal Gorny bb1137da12 [sanitizer_common] Fix devname_r() return type on !NetBSD
Update the interceptor for devname_r() to account for correct return
types on different platforms.  This function returns int on NetBSD
but char* on FreeBSD/OSX.  Noticed by @krytarowski.

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

llvm-svn: 350228
2019-01-02 17:36:50 +00:00
Michal Gorny 7341d0a92d [sanitizer_common] Rewrite more Posix tests to use asserts
Rewrite the tests for Posix functions that silently 'return 1'
or 'exit(1)' on error, to instead verbosely report the error using
assert.  This is based on requests made in review of D56136.

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

llvm-svn: 350227
2019-01-02 17:36:46 +00:00
Michal Gorny d963eea188 [sanitizer_common] Add tests for more stdio.h functions
Add two new test cases that test the following stdio.h functions:
- clearerr()
- feof()
- ferror()
- fileno()
- fgetc()
- getc()
- ungetc()

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

llvm-svn: 350225
2019-01-02 17:36:37 +00:00
Kamil Rytarowski 48615c1786 Reenable hard_rss_limit_mb_test.cc for android-26
Noted by eugenis@ in D55887.

llvm-svn: 350140
2018-12-29 00:35:49 +00:00
Kamil Rytarowski 646c130a18 Add support for background thread on NetBSD in ASan
Summary:
Change the point of calling MaybeStartBackgroudThread() from AsanInitInternal()
that is too early on NetBSD to a constructor (with aid of C++11 lambda construct).

Enable the code for background thread as is for NetBSD.

Rename test/sanitizer_common/TestCases/Linux/hard_rss_limit_mb_test.cc
to test/sanitizer_common/TestCases/hard_rss_limit_mb_test.cc and allow runs
on NetBSD. This tests passes correctly.

Reviewers: vitalybuka, joerg, eugenis

Reviewed By: eugenis

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

Tags: #sanitizers

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

llvm-svn: 350139
2018-12-29 00:32:07 +00:00
David Carlier adb5f1e3b5 [Sanitizer] Enable getfsent api for Darwin
Reviewers: vitalybuka, kubamracek

Reviewed By: vitalybuka

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

llvm-svn: 350138
2018-12-29 00:17:21 +00:00
Dan Liew 8c11fb3ed4 Introduce `LocalAddressSpaceView::LoadWritable(...)` and make the `Load(...)` method return a const pointer.
Summary:
This is a follow-up to r346956 (https://reviews.llvm.org/D53975).

The purpose of this change to allow implementers of the
`AddressSpaceView` to be able to distinguish between when a caller wants
read-only memory and when a caller wants writable memory. Being able
distinguish these cases allows implementations to optimize for the
different cases and also provides a way to workaround possible platform
restrictions (e.g. the low level platform interface for reading
out-of-process memory may place memory in read-only pages).

For allocator enumeration in almost all cases read-only is sufficient so
we make `Load(...)` take on this new requirement and introduce the
`LoadWritable(...)` variants for cases where memory needs to be
writable.

The behaviour of `LoadWritable(...)` documented in comments are
deliberately very restrictive so that it will be possible in the future
to implement a simple write-cache (i.e. just a map from target address
to a writable region of memory). These restrictions can be loosened in
the future if necessary by implementing a more sophisticated
write-cache.

rdar://problem/45284065

Reviewers: kcc, cryptoad, eugenis, kubamracek, george.karpenkov

Subscribers: #sanitizers, llvm-commits

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

llvm-svn: 350136
2018-12-28 19:30:51 +00:00
Reid Kleckner 1c6dbd6921 Speculative fix for xray assembler error on MachO since r349976
This .file directive wasn't doing anything on MachO, and now that's
diagnosed as an error.

llvm-svn: 350132
2018-12-28 18:53:00 +00:00
David Carlier d1ca603770 [Sanitizer] arc4random unit test missing case.
llvm-svn: 350124
2018-12-28 16:36:05 +00:00
David Carlier f11fcc046e [Sanitizer] Intercept arc4random_buf / arc4random_addrandom on FreeBSD/NetBSD
- Disabled on purpose on Android and Darwin platform (for now).
- Darwin supports it, would need interception in its specific code before enabling it.
- Linux does not support it but only via third party library.
- Android supports it via bionic however it is known to have issue with older versions of the implementations. Can be enabled by an Android committer later on if necessary once there is more 'certainity'/been more tested.

Reviewers: krytarowski, vitalybuka

Reviewed By: krytarowski

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

llvm-svn: 350123
2018-12-28 16:04:28 +00:00
Evgeniy Stepanov 3408b497f9 Revert "[asan] Support running without /proc.", +1
Revert r350104 "[asan] Fix build on windows."
Revert r350101 "[asan] Support running without /proc."

These changes break Mac build, too.

llvm-svn: 350112
2018-12-28 01:27:18 +00:00
Kamil Rytarowski 10828c39cb Fix a mistake in previous
Assign correct ioctl(2) operation number.

llvm-svn: 350110
2018-12-28 00:17:37 +00:00
Kamil Rytarowski 8e56064542 Update NetBSD ioctl(2) entries with 8.99.28
Add SIOCSETHERCAP.

Add commented out NVMM (NetBSD Virtual Machine Monitor) operations
as this interface is still WIP and a subject to change.

llvm-svn: 350107
2018-12-27 23:35:28 +00:00
Kamil Rytarowski 636269526d Enable asan_and_llvm_coverage_test.cc for NetBSD
LLVM profile is now enabled for this target.

llvm-svn: 350106
2018-12-27 22:55:13 +00:00
Evgeniy Stepanov 1ce7fccbc9 [asan] Fix build on windows.
Reviewers: vitalybuka

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 350104
2018-12-27 22:16:28 +00:00
Evgeniy Stepanov e9d00896bd Enable posix regex interceptors on linux.
Summary: They happen to work out of the box.

Reviewers: rtrieu, vitalybuka

Subscribers: kubamracek, fedor.sergeev, krytarowski, llvm-commits

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

llvm-svn: 350103
2018-12-27 21:47:26 +00:00
Kamil Rytarowski 93e3b34ceb Reimplement Thread Static Data MSan routines with TLS
Summary:
Thread Static Data cannot be used in early init on NetBSD
and FreeBSD. Reuse the MSan TSD API for compatibility with
existing code with an alternative implementation using Thread
Local Storage.

New version uses Thread Local Storage to store a pointer
with thread specific data. The destructor from TSD has been
replaced with a TLS destrucutor that is called upon thread
exit.

Reviewers: joerg, vitalybuka, jfb

Reviewed By: vitalybuka

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

Tags: #sanitizers

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

llvm-svn: 350102
2018-12-27 21:43:46 +00:00
Evgeniy Stepanov d9df65fd0d [asan] Support running without /proc.
Summary:
This patch lets ASan run when /proc is not accessible (ex. not mounted
yet). It includes a special test-only flag that emulates this condition
in an unpriviledged process.

This only matters on Linux, where /proc is necessary to enumerate
virtual memory mappings.

Reviewers: pcc, vitalybuka

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 350101
2018-12-27 21:31:52 +00:00
David Carlier 04b7be08d2 getfsent, unit test.
llvm-svn: 350100
2018-12-27 21:26:03 +00:00
David Carlier 774f7e83c3 [Sanitizer] Add fstab api to FreeBSD/Linux
Interception of /etc/fstab function parsers.

Reviewers: krytarowski, vitalybuka

Reviewed By: krytarowski

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

llvm-svn: 350099
2018-12-27 21:25:24 +00:00
Jordan Rupprecht 4009724151 [sanitizer] Avoid memset call in tsan
Summary: Assigning an array of bools to {false, false, false} can, in certain build configurations, lead to a memset call. Use internal_memset to avoid this.

Reviewers: eugenis

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

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

llvm-svn: 350098
2018-12-27 20:29:10 +00:00
Kamil Rytarowski 7c276c141b Adjust NetBSD/sha2.cc to be portable to more environments
Summary:
By an accident part of the tests contained hardcoded checksums
for external files that will differ between setups.

Reviewers: mgorny

Subscribers: kubamracek, llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 350097
2018-12-27 17:04:00 +00:00
Kamil Rytarowski e4693c2c20 Adjust NetBSD/md2.cc to be portable to more environments
Summary:
By an accident part of the tests contained hardcoded checksums
for external files that will differ between setups.

Reviewers: mgorny

Subscribers: kubamracek, llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 350096
2018-12-27 17:03:21 +00:00
Kamil Rytarowski 001df4fb5a Adjust NetBSD/md[45].cc to be portable to more environments
Summary:
By an accident part of the tests contained hardcoded checksums
for external files that will differ between setups.

Reviewers: mgorny

Subscribers: kubamracek, llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 350095
2018-12-27 17:02:16 +00:00
David Carlier 018f505c9e [Sanitizer] Enable FTS api on FreeBSD
Reviewers: krytarowski, vitalybuka

Reviewed By: krytarowski

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

llvm-svn: 350090
2018-12-27 12:56:54 +00:00
Martin Liska 7240eb3ba9 Do not rely on that subject of ErrorAllocTypeMismatch is a heap address.
Differential Revision: https://reviews.llvm.org/D54856.

llvm-svn: 350085
2018-12-27 08:39:13 +00:00
Evgeniy Stepanov 772bf988cf Revert "[msan] Disable tail call optimization in msan rtl."
This reverts commit r350080, which breaks
* gcc as the host compiler
* some tests on ppc64

llvm-svn: 350083
2018-12-27 03:30:42 +00:00
Evgeniy Stepanov faef9b77de [msan] Disable tail call optimization in msan rtl.
This should give us better error stack traces on the bots, in
particular, for https://bugs.llvm.org/show_bug.cgi?id=40162

llvm-svn: 350080
2018-12-27 00:21:20 +00:00
Michal Gorny a939b40eae [xray] Detect MPROTECT and error out when it's enabled (on NetBSD)
Add a CheckMPROTECT() routine to detect when pax MPROTECT is enabled
on NetBSD, and error xray out when it is.  The solution is adapted
from existing CheckASLR().

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

llvm-svn: 350030
2018-12-23 15:09:28 +00:00
Michal Gorny 470ce63251 [xray] Disable alignas() for thread_local objects on NetBSD
Disable enforcing alignas() for structs that are used as thread_local
data on NetBSD.  The NetBSD ld.so implementation is buggy and does
not enforce correct alignment; however, clang seems to take it for
granted and generates instructions that segv on wrongly aligned objects.
Therefore, disable those alignas() statements on NetBSD until we can
establish a better fix.

Apparently, std::aligned_storage<> does not have any real effect
at the moment, so we can leave it as-is.

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

llvm-svn: 350029
2018-12-23 15:09:20 +00:00
Dimitry Andric a5afbce82b Set the default SANITIZER_CXX_ABI library to libc++ for FreeBSD, and
also mark it as a system library, like on macOS.

llvm-svn: 350020
2018-12-23 11:49:47 +00:00
David Carlier 58d3823086 [Sanitizer] Enable POSIX regex api on FreeBSD.
Reviewers: krytarowski

Reviewed By: krytarowski

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

M    lib/sanitizer_common/sanitizer_common_interceptors.inc
M    lib/sanitizer_common/sanitizer_platform_interceptors.h
M    lib/sanitizer_common/sanitizer_platform_limits_freebsd.cc
M    lib/sanitizer_common/sanitizer_platform_limits_freebsd.h
D    test/sanitizer_common/TestCases/NetBSD/regex.cc
A  + test/sanitizer_common/TestCases/Posix/regex.cc

llvm-svn: 350002
2018-12-22 11:17:27 +00:00
Kamil Rytarowski edbe2b3f02 Add support for LLVM profile for NetBSD
Summary:
NetBSD uses typical UNIX interfaces.

All tests pass except instrprof-dlopen-dlclose-gcov.test, as there
is not supported semantics of atexit(3) in dlopen(3)ed+dlclose(3)d
DSO.

NetBSD also ships an older version of LLVM profile (ABI v.2 predating
ABI v.4 in upstream version) inside libc. That copy has been manually
removed during the porting and testing process of the upstream version
to NetBSD. Otherwise there were conflicts between them two.

Reviewers: joerg, vitalybuka, vsk

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

Tags: #sanitizers

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

llvm-svn: 349994
2018-12-22 06:56:19 +00:00
Dan Liew c6027e20d4 Fix comment typo.
llvm-svn: 349961
2018-12-21 21:41:43 +00:00
Dan Liew a8334ed571 Fix `static_assert()` scope in `CombinedAllocator`.
It should be at the class scope and not inside the `Init(...)` function
because we want to error out as soon as the wrong type is constructed.
At the function scope the `static_assert` is only checked if the
function might be called.

This is a follow up to r349957.

rdar://problem/45284065

llvm-svn: 349960
2018-12-21 21:41:37 +00:00
Dan Liew 09f6d77840 Fix `static_assert()` scope in `SizeClassAllocator32`.
It should be at the class scope and not inside the `Init(...)` function
because we want to error out as soon as the wrong type is constructed.
At the function scope the `static_assert` is only checked if the
function might be called.

This is a follow up to r349138.

rdar://problem/45284065

llvm-svn: 349959
2018-12-21 21:41:31 +00:00
Dan Liew 14e0d9ed89 Introduce `AddressSpaceView` template parameter to `CombinedAllocator`.
Summary:
This is a follow up to https://reviews.llvm.org/D55764 .

For the ASan and LSan allocatorsthe type declarations have been modified
so that it's possible to create a combined allocator type that
consistently uses a different type of `AddressSpaceView`. We intend to
use this in future patches. For the other sanitizers they just use
`LocalAddressSpaceView` by default because we have no plans to use these
allocators in an out-of-process manner.

rdar://problem/45284065

Reviewers: kcc, dvyukov, vitalybuka, cryptoad, eugenis, kubamracek, george.karpenkov, yln

Subscribers: #sanitizers, llvm-commits

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

llvm-svn: 349957
2018-12-21 21:22:27 +00:00
Dan Liew d2c6af7358 Introduce `AddressSpaceView` template parameter to `SizeClassAllocator64`.
Summary:
This is a follow up patch to r349138.

This patch makes a `AddressSpaceView` a type declaration in the
allocator parameters used by `SizeClassAllocator64`. For ASan, LSan, and
the unit tests the AP64 declarations have been made templated so that
`AddressSpaceView` can be changed at compile time. For the other
sanitizers we just hard-code `LocalAddressSpaceView` because we have no
plans to use these allocators in an out-of-process manner.

rdar://problem/45284065

Reviewers: kcc, dvyukov, vitalybuka, cryptoad, eugenis, kubamracek, george.karpenkov

Subscribers: #sanitizers, llvm-commits

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

llvm-svn: 349954
2018-12-21 21:09:31 +00:00