Commit Graph

684 Commits

Author SHA1 Message Date
Kamil Rytarowski 9ecd493129 Add NetBSD/x86_64 mapping in MSan
Summary:
Reuse the Linux new mapping as it is.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, vitalybuka, eugenis

Reviewed By: vitalybuka

Subscribers: llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 320218
2017-12-09 00:27:52 +00:00
Kamil Rytarowski 0f5cb013d0 Revert SVN r, 319967
"Correct atexit(3) support in MSan/NetBSD"

This causes failures on Linux.

llvm-svn: 319981
2017-12-06 22:50:12 +00:00
Kamil Rytarowski 0192818ffe Correct atexit(3) support in MSan/NetBSD
Summary:
The NetBSD specific implementation of cxa_atexit() does not
preserve the 2nd argument if dso is equal to NULL.

Changes:

 - Split paths of handling intercepted __cxa_atexit() and atexit(3).
   This affects all supported Operating Systems.
 - Add a local stack-like structure to hold the __cxa_atexit() context.
   atexit(3) is documented in the C standard as calling callback from the
   earliest to the oldest entry. This path also fixes potential ABI
   problem of passing an argument to a function from the atexit(3)
   callback mechanism.
 - Allow usage of global vars with ctors in interceptors.
   This allows to use Vector without automatic cleaning up the structures.

This code has been modeled after TSan implementation for the same functions.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, dvyukov, eugenis, vitalybuka, kcc

Reviewed By: vitalybuka

Subscribers: llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 319967
2017-12-06 21:57:39 +00:00
Kamil Rytarowski bf228b9200 Handle NetBSD symbol renaming in msan_interceptors.cc
Summary:
NetBSD renames symbols for historical and compat reasons.

Add required symbol renames in sanitizer_common_interceptors.inc:

 - gettimeofday -> __gettimeofday50
 - getrusage -> __getrusage50
 - shmctl -> __shmctl50

Additionally handle sigaction symbol mangling.
Rename the function symbol in the file to SIGACTION_SYMNAME and define
it as __sigaction14 for NetBSD and sigaction for !NetBSD. We cannot use
simple renaming with the proprocessor, as there are valid fields named
sigaction and they must be left intact.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, eugenis, vitalybuka, dvyukov

Reviewed By: vitalybuka

Subscribers: kubamracek, llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 319966
2017-12-06 21:32:57 +00:00
Kamil Rytarowski a149c1a517 Fix typo fcvr -> fcvt and attempt to unbreak MSan/!NetBSD
llvm-svn: 319872
2017-12-06 01:44:41 +00:00
Kamil Rytarowski b6778ff9d2 Fix typo gcvr -> gcvt and attempt to unbreak MSan/!NetBSD
llvm-svn: 319871
2017-12-06 01:43:38 +00:00
Kamil Rytarowski 8cec32cc5f Support pthread_key_create symbol alias in MSan/NetBSD
Summary:
NetBSD uses indirection symbol for a set of threading functions.

Add alias to handle __libc_thr_keycreate the same way as pthread_key_create.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, dvyukov, eugenis, vitalybuka

Reviewed By: vitalybuka

Subscribers: llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 319868
2017-12-06 01:16:49 +00:00
Kamil Rytarowski 993447c830 Disable absent functions in MSan/NetBSD interceptors
Summary:
Disable for NetBSD missing functions missing in this OS:

 - mempcpy,
 - __libc_memalign,
 - malloc_usable_size,
 - stpcpy,
 - gcvt,
 - wmempcpy,
 - fcvt.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, dvyukov, eugenis, vitalybuka, kcc

Reviewed By: vitalybuka

Subscribers: llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 319866
2017-12-06 01:03:11 +00:00
Vitaly Buka b791cf3e46 [msan] Fix formatting
llvm-svn: 319844
2017-12-05 22:10:01 +00:00
Vitaly Buka f7b63c5f2b [msan] add strtouq msan interceptor
Summary: Fixes https://github.com/google/sanitizers/issues/892

Reviewers: eugenis

Subscribers: llvm-commits

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

llvm-svn: 319843
2017-12-05 22:07:26 +00:00
Vitaly Buka fbb4bace66 [msan] Fix return type of mbrtowc
Summary: Fixes https://github.com/google/oss-fuzz/issues/1009

Reviewers: eugenis

Subscribers: llvm-commits

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

llvm-svn: 319484
2017-11-30 22:15:39 +00:00
Stephan Bergmann 1c14e86a26 Linux needs to include sys/uio.h for readv, preadv
...at least when building against glibc-2.26-16.fc27.x86_64

llvm-svn: 319412
2017-11-30 09:22:12 +00:00
Evgeniy Stepanov c181d2e773 [msan] Avoid shadowing a variable in common interceptors.
"offset" declared in a macro may shadow a variable with the same name
in the caller which is used in a macro argument. We are quite lucky
that it does not actually happen, but rename the variable anyway to
be on the safe side.

llvm-svn: 319115
2017-11-27 23:25:38 +00:00
Vitaly Buka 5f767113c5 [msan] Fix signal chaining
Return internally stored handlers only if handlers is set to wrapper

llvm-svn: 317970
2017-11-11 03:03:34 +00:00
Vitaly Buka db5757e68b [msan] Remove INTERCEPT_FUNCTION for sigaction and signal
Already done in InitializeSignalInterceptors()

llvm-svn: 317906
2017-11-10 18:58:59 +00:00
Vitaly Buka 8b689f4092 [tsan] Use __sanitizer_siginfo from sanitizer_common
llvm-svn: 317872
2017-11-10 04:27:47 +00:00
Vitaly Buka bec32e9ac4 [msan] Deadly signal handler for msan
Summary: Part of https://github.com/google/sanitizers/issues/637

Reviewers: eugenis, alekseyshl

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 317864
2017-11-10 02:06:59 +00:00
Vitaly Buka a452f9cc37 [msan] Move sigaction_impl and signal_impl
llvm-svn: 317863
2017-11-10 02:06:50 +00:00
Vitaly Buka 8e92025718 [msan] Extract signal_impl and sigaction_impl
Summary: Preparation for using interceptor from sanitizer_common.

Reviewers: eugenis

Subscribers: llvm-commits

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

llvm-svn: 317844
2017-11-09 22:52:15 +00:00
Vitaly Buka 771e3995a4 [msan] Replace CommonSanitizerReportMutex with ScopedErrorReportLock
llvm-svn: 317842
2017-11-09 22:48:45 +00:00
Bill Seurer 823338d1fe [PowerPC][msan] Update msan to handle changed memory layouts in newer kernels
In more recent Linux kernels (including those with 47 bit VMAs) the layout of
virtual memory for powerpc64 changed causing the memory sanitizer to not
work properly.  This patch adjusts the memory ranges in the tables for the
memory sanitizer to work on the newer kernels while continuing to work on the
older ones as well.

Tested on several 4.x and 3.x kernel releases.

llvm-svn: 317802
2017-11-09 16:14:57 +00:00
Vitaly Buka 2b2d3aaa04 [msan] Add context argument into GetStackTrace
llvm-svn: 317773
2017-11-09 07:48:53 +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
Evgeniy Stepanov 0b8602791b [msan] Intercept __strxfrm_l.
llvm-svn: 316613
2017-10-25 21:40:17 +00:00
Kamil Rytarowski 9c1eeaca80 Add NetBSD improvements in sanitizers
Summary:
Changes:

 * Add initial msan stub support.
 * Handle NetBSD specific pthread_setname_np(3).
 * NetBSD supports __attribute__((tls_model("initial-exec"))),
   define it in SANITIZER_TLS_INITIAL_EXEC_ATTRIBUTE.
 * Add ReExec() specific bits for NetBSD.
 * Simplify code and add syscall64 and syscall_ptr for !NetBSD.
 * Correct bunch of syscall wrappers for NetBSD.
 * Disable test/tsan/map32bit on NetBSD as not applicable.
 * Port test/tsan/strerror_r to a POSIX-compliant OSes.
 * Disable __libc_stack_end on NetBSD.
 * Disable ReadNullSepFileToArray() on NetBSD.
 * Define struct_ElfW_Phdr_sz, detected missing symbol by msan.
 * Change type of __sanitizer_FILE from void to char. This helps
   to reuse this type as an array. Long term it will be properly
   implemented along with SANITIZER_HAS_STRUCT_FILE setting to 1.
 * Add initial NetBSD support in lib/tsan/go/buildgo.sh.
 * Correct referencing stdout and stderr in tsan_interceptors.cc
   on NetBSD.
 * Document NetBSD x86_64 specific virtual memory layout in
   tsan_platform.h.
 * Port tests/rtl/tsan_test_util_posix.cc to NetBSD.
 * Enable NetBSD tests in test/msan/lit.cfg.
 * Enable NetBSD tests in test/tsan/lit.cfg.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, vitalybuka, eugenis, kcc, dvyukov

Reviewed By: dvyukov

Subscribers: #sanitizers, llvm-commits, kubamracek

Tags: #sanitizers

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

llvm-svn: 316591
2017-10-25 17:09:05 +00:00
Vitaly Buka 36266b6b0d [compiler-rt] Cleanup decorators
Summary:
Removed redundant End*() methods which defined same way.
Removed redundant Warning() methods.

Reviewers: eugenis

Subscribers: kubamracek, llvm-commits, dberris

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

llvm-svn: 312950
2017-09-11 20:55:49 +00:00
Evgeniy Stepanov 9566d28997 [msan] Remove a stale fixme (NFC).
It was fixed in 312576.

llvm-svn: 312597
2017-09-06 00:28:52 +00:00
Evgeniy Stepanov 8b80b328d1 [msan] Check sigset_t and sigaction arguments.
Summary:
Check sigset_t arguments in ppoll, sig*wait*, sigprocmask
interceptors, and the entire "struct sigaction" in sigaction. This
can be done because sigemptyset/sigfullset are intercepted and
signal masks should be correctly marked as initialized.

Reviewers: vitalybuka

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 312576
2017-09-05 21:08:56 +00:00
Evgeniy Stepanov 00dedc208f (NFC) Fix the use of do{}while(0) in a macro.
llvm-svn: 312396
2017-09-02 00:09:57 +00:00
Benjamin Kramer 7fba72e97b [msan] Switch the pvalloc overflow test to a lit test
The test was not passing on targets where allocator_may_return_null
defaults to true. Change the test to a lit test so that we can test both
situations.

Patch by Kostya Kortchinsky!

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

llvm-svn: 310033
2017-08-04 07:32:10 +00:00
Kostya Kortchinsky 94380ed406 [msan] Check for pvalloc overflow
Summary:
CheckForPvallocOverflow was introduced with D35818 to detect when pvalloc
would wrap when rounding up to the next multiple of the page size.

Add this check to MSan's pvalloc implementation.

This time I made sure I was actually running (and writing) the correct tests,
and that they are passing...

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 309883
2017-08-02 20:32:12 +00:00
Kostya Kortchinsky 9d52cedb24 [msan] Reverting D36093
Summary:
Reverting D36093 until I can figure out how to launch the correct tests :/
My apologies.

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 309637
2017-07-31 22:46:01 +00:00
Kostya Kortchinsky 56f5f17349 [msan] Check for pvalloc overflow
Summary:
`CheckForPvallocOverflow` was introduced with D35818 to detect when pvalloc
would wrap when rounding up to the next multiple of the page size.

Add this check to MSan's pvalloc implementation.

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 309601
2017-07-31 18:45:17 +00:00
Krzysztof Parzyszek 48a34c684b [compiler-rt] Add missing quotation marks to msan_compile invocation
llvm-svn: 309430
2017-07-28 20:29:29 +00:00
George Karpenkov 831875b4bf [sanitizer tests CMake] Factor out CMake logic for compiling sanitizer tests
Currently there's a large amount of CMake logic duplication for
compiling sanitizer tests.
If we add more sanitizers, the duplication will get even worse.

This change factors out common compilation commands into a macro
available to all sanitizers.

llvm-svn: 309405
2017-07-28 17:32:37 +00:00
Alex Shlyapnikov 42bea018af [Sanitizers] ASan/MSan/LSan allocators set errno on failure.
Summary:
ASan/MSan/LSan allocators set errno on allocation failures according to
malloc/calloc/etc. expected behavior.

MSan allocator was refactored a bit to make its structure more similar
with other allocators.

Also switch Scudo allocator to the internal errno definitions.

TSan allocator changes will follow.

Reviewers: eugenis

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 308344
2017-07-18 19:11:04 +00:00
Alex Shlyapnikov 35adb43950 [Sanitizers] Consolidate internal errno definitions.
Move internal errno definitions to common to be shared by all sanitizers
and to be used by allocators.

llvm-svn: 307233
2017-07-06 00:50:57 +00:00
Alex Shlyapnikov 93c1a8c7c7 Merge
llvm-svn: 306746
2017-06-29 21:54:36 +00:00
Alex Shlyapnikov 4b450685d3 [Sanitizers] Operator new() interceptors always die on allocation error
Summary:
Operator new interceptors behavior is now controlled by their nothrow
property as well as by allocator_may_return_null flag value:

- allocator_may_return_null=* + new()        - die on allocation error
- allocator_may_return_null=0 + new(nothrow) - die on allocation error
- allocator_may_return_null=1 + new(nothrow) - return null

Ideally new() should throw std::bad_alloc exception, but that is not
trivial to achieve, hence TODO.

Reviewers: eugenis

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 306604
2017-06-28 21:58:57 +00:00
Evgeniy Stepanov 6f75e2dd48 [msan] Intercept wcscat, wcsncat.
Also move wcslen, wscnlen to common interceptors.

Reviewers: vitalybuka

Reviewed By: vitalybuka

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 306482
2017-06-27 22:52:38 +00:00
Alex Shlyapnikov ccab11b0e8 [Sanitizers] Move cached allocator_may_return_null flag to sanitizer_allocator
Summary:
Move cached allocator_may_return_null flag to sanitizer_allocator.cc and
provide API to consolidate and unify the behavior of all specific allocators.

Make all sanitizers using CombinedAllocator to follow
AllocatorReturnNullOrDieOnOOM() rules to behave the same way when OOM
happens.

When OOM happens, turn allocator_out_of_memory flag on regardless of
allocator_may_return_null flag value (it used to not to be set when
allocator_may_return_null == true).

release_to_os_interval_ms and rss_limit_exceeded will likely be moved to
sanitizer_allocator.cc too (later).

Reviewers: eugenis

Subscribers: srhines, kubamracek, llvm-commits

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

llvm-svn: 305858
2017-06-20 21:23:02 +00:00
Alex Shlyapnikov 5a308f24c3 [Sanitizer] Remove CombinedAllocator::Allocate's 'cleared' parameter
Summary:
CombinedAllocator::Allocate cleared parameter is not used anywhere and
seem to be obsolete.

Reviewers: eugenis

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 305590
2017-06-16 21:00:03 +00:00
Evgeniy Stepanov 790838110f Revert r304285, r304297.
r304285 - [sanitizer] Avoid possible deadlock in child process after fork
r304297 - [sanitizer] Trying to fix MAC buildbots after r304285

These changes create deadlock when Tcl calls pthread_create from a
pthread_atfork child handler. More info in the original review at
https://reviews.llvm.org/D33325

llvm-svn: 304735
2017-06-05 21:20:55 +00:00
Pierre Gousseau 183d1368f3 [asan] Add strndup/__strndup interceptors.
Recommit of r302781 with Vitaly Buka's fix for non zero terminated strings.

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

llvm-svn: 304399
2017-06-01 09:37:22 +00:00
Maxim Ostapenko 62a0f55930 [sanitizer] Avoid possible deadlock in child process after fork
This patch addresses https://github.com/google/sanitizers/issues/774. When we
fork a multi-threaded process it's possible to deadlock if some thread acquired
StackDepot or allocator internal lock just before fork. In this case the lock
will never be released in child process causing deadlock on following memory alloc/dealloc
routine. While calling alloc/dealloc routines after multi-threaded fork is not allowed,
most of modern allocators (Glibc, tcmalloc, jemalloc) are actually fork safe. Let's do the same
for sanitizers except TSan that has complex locking rules.

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

llvm-svn: 304285
2017-05-31 07:28:09 +00:00
Daniel Jasper f97310fb7a Revert r302781 and subsequent attempts to disable part of it.
The Msan unit tests are still broken and by this point, I think we
should start over.

llvm-svn: 303339
2017-05-18 09:31:37 +00:00
Kostya Kortchinsky dc646a0889 [sanitizer] Change SizeClassAllocator32 to accept just one template
Summary:
With rL279771, SizeClassAllocator64 was changed to accept only one template
instead of 5, for the following reasons: "First, this will make the mangled
names shorter. Second, this will make adding more parameters simpler". This
patch mirrors that work for SizeClassAllocator32.

This is in preparation for introducing the randomization of chunks in the
32-bit SizeClassAllocator in a later patch.

Reviewers: kcc, alekseyshl, dvyukov

Reviewed By: alekseyshl

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 303071
2017-05-15 14:47:19 +00:00
Alexander Potapenko f06fbd4794 [msan] Remove a failing test from MemorySanitizer.ICmpRelational
This is a follow-up to r302787, which broke MemorySanitizer.ICmpRelational.

MSan is now reporting a false positive on the following test case:
  TestForNotPoisoned((poisoned(-1, 0x80000000U) >= poisoned(-1, 0U)))
, which is sort of anticipated, because we're approximating the comparison
with an OR of the arguments' shadow values.

llvm-svn: 302887
2017-05-12 09:39:32 +00:00
Pierre Gousseau 0550581070 [asan] Recommit of r301904: Add strndup/__strndup interceptors
Fix undeclared __interceptor_malloc in esan_interceptors.cc
Fix undeclared strnlen on OSX

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

llvm-svn: 302781
2017-05-11 08:53:24 +00:00
Adhemerval Zanella 6b989288ab [msan] Fix getmntent{_r} for empty /etc/fstab
Some configuration (for instance default docker ubuntu images) uses
a default empty and invalid /etc/fstab configuration file.  It makes
any call to getmntent return NULL and it leads to failures on
Msan-aarch64{-with-call}-Test/MemorySanitizer.getmntent{_r}.

This patch fixes it by creating a temporary file with some valid
entries (although not valid for the system) to use along with
setmntent/getmntent.

llvm-svn: 302639
2017-05-10 12:18:25 +00:00