Commit Graph

2102 Commits

Author SHA1 Message Date
Kostya Serebryany d55d0875d2 [sanitizer] Allow the sanitizer allocator to use a non-fixed address range. An allocator with a non-fixed address range will be attack-resistan. NFC for the sanitizers at this point.
llvm-svn: 267094
2016-04-22 01:08:54 +00:00
Kuba Brecka 586d93bd8b [sanitizer] Use pthread_threadid_np as thread ID on OS X
Let's use pthread_threadid_np which returns a more reasonable ID than pthread_self (which is actually a stack pointer). The numbers from pthread_threadid_np are already used in other tools, e.g. in LLDB, and often appear in logs, so it's much more useful than pthread_self.

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

llvm-svn: 266991
2016-04-21 14:38:41 +00:00
Kostya Serebryany e63db09bea [sanitizer] update the sanitizer_allocator_testlib
llvm-svn: 266934
2016-04-20 23:28:06 +00:00
Evgeniy Stepanov 033c5d55c1 [asan] Increase LocatePcInTrace threshold.
Not sure what changed, but on my machine this is literally one byte
short. Only happens when malloc_context_size <= 2 due to the special
case in GET_STACK_TRACE definition (see asan_stack.h):
StackTrace::GetCurrentPc() on the right (context size > 2) branch
returns the address that is 200-something bytes from the return
address it is later matched to, while the same call on the left
branch is 321 bytes away from it.

This fixes the double-free test on my machine.

llvm-svn: 266932
2016-04-20 22:45:25 +00:00
Maxim Ostapenko 71630b9ea7 [sanitizer] Fix 'dyld: Symbol not found: _dyldVersionNumber' link error on old Darwin systems.
This patch fixes https://github.com/google/sanitizers/issues/669. On older Darwin systems (in particular, Darwin 10),
dyld doesn't export '_dyldVersionNumber' symbol so we would have 'undefined reference' error in sanitzer library. Although
sanitizers support was added to LLVM on OS X 10.7+ where '_dyldVersionNumber' symbol is already exported, GCC users still
may want use them on older systems.

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

llvm-svn: 266868
2016-04-20 10:22:37 +00:00
Sagar Thakur 2e17dd5882 [LSAN] Fix test swapcontext.cc on MIPS
Summary: There is no frame validity check in the slow unwinder like there is in the fast unwinder due to which lsan reports a leak even for heap allocated coroutine in the test swapcontext.cc. Since mips/linux uses slow unwindwer instead of fast unwinder, the test fails for mips/linux. Therefore adding the checks before unwinding fixes the test for mips/linux.

Reviewers: samsonov, earthdok, kcc
Subscribers: llvm-commits, mohit.bhakkad, jaydeep
Differential: http://reviews.llvm.org/D18690
llvm-svn: 266716
2016-04-19 06:00:35 +00:00
Anna Zaks 8f8d3db940 [sanitizers] Fixup to r266494; the Unit test should not run on Windows
The test is failing on Windows because we do not have a definition for
DemangleSwiftAndCXX nor DemangleCXXABI, which I am replacing, on Windows.

llvm-svn: 266499
2016-04-16 00:32:16 +00:00
Anna Zaks 50154d4ec4 [sanitizers] Fixup r266494; make it build on Linux.
llvm-svn: 266497
2016-04-16 00:12:46 +00:00
Anna Zaks 60469e2ac0 [sanitizers] Teach the internal demangler about Swift names
Add support for Swift names when symbolicating sanitizer traces. This is
now relevant since TSan and ASan support have been added to Swift on OS X.

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

llvm-svn: 266494
2016-04-15 23:51:00 +00:00
Marcin Koscielnicki 604d873aa1 [sanitizers] [SystemZ] Introduce sanitizer_linux_s390.cc.
This file will contain s390-specific code.  For now, let's move the s390
version of internal_mmap here.

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

llvm-svn: 266482
2016-04-15 22:11:10 +00:00
Marcin Koscielnicki 0a91cf8a84 Revert "[sanitizer] [SystemZ] Abort if the kernel might be vulnerable to CVE-2016-2143."
This reverts commit r266297.

llvm-svn: 266470
2016-04-15 20:00:12 +00:00
Marcin Koscielnicki 9e09355477 [sanitizer] [SystemZ] Fix stack traces.
On s390, the return address is in %r14, which is saved 14 words from
the frame pointer.

Unfortunately, there's no way to do a proper fast backtrace on SystemZ
with current LLVM - the saved %r15 in fixed-layout register save
area points to the containing frame itself, and not to the next one.
Likewise for %r11 - it's identical to %r15, unless alloca is used
(and even if it is, it's still useless).  There's just no way to
determine frame size / next frame pointer.  -mbackchain would fix that
(and make the current code just work), but that's not yet supported
in LLVM.  We will thus need to XFAIL some asan tests
(Linux/stack-trace-dlclose.cc, deep_stack_uaf.cc).

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

llvm-svn: 266371
2016-04-14 21:19:27 +00:00
Marcin Koscielnicki 20bf94209e [sanitizer] [SystemZ] Add/fix kernel and libc type definitions.
This is the first part of upcoming asan support for s390 and s390x.
Note that there are bits for 31-bit support in this and subsequent
patches - while LLVM itself doesn't support it, gcc should be able
to make use of it just fine.

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

llvm-svn: 266370
2016-04-14 21:17:19 +00:00
Ed Maste fe2b70637c [sanitizer] remove FreeBSD PS_STRINGS fallback
The PS_STRINGS constant can easily be incorrect with mismatched
kernel/userland - e.g. when building i386 sanitizers on FreeBSD/amd64
with -m32. The kern.ps_strings sysctl was introduced over 20 years ago
as the supported way to fetch the environment and argument string
addresses from the kernel, so the fallback is never used.

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

llvm-svn: 266305
2016-04-14 14:17:42 +00:00
Marcin Koscielnicki c8dda336bb [sanitizer] [SystemZ] Abort if the kernel might be vulnerable to CVE-2016-2143.
In short, CVE-2016-2143 will crash the machine if a process uses both >4TB
virtual addresses and fork().  ASan, TSan, and MSan will, by necessity, map
a sizable chunk of virtual address space, which is much larger than 4TB.
Even worse, sanitizers will always use fork() for llvm-symbolizer when a bug
is detected.  Disable all three by aborting on process initialization if
the running kernel version is not known to contain a fix.

Unfortunately, there's no reliable way to detect the fix without crashing
the kernel.  So, we rely on whitelisting - I've included a list of upstream
kernel versions that will work.  In case someone uses a distribution kernel
or applied the fix themselves, an override switch is also included.

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

llvm-svn: 266297
2016-04-14 12:56:24 +00:00
Marcin Koscielnicki 0ffa9eaa4a [sanitizer] [SystemZ] Add virtual space size.
This teaches sanitizer_common about s390 and s390x virtual space size.
s390 is unusual in that it has 31-bit virtual space.

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

llvm-svn: 266296
2016-04-14 12:56:15 +00:00
Marcin Koscielnicki 545e507c43 [sanitizer] [SystemZ] Implement internal_mmap.
mmap on s390 is quite a special snowflake: since it has too many
parameters to pass them in registers, it passes a pointer to a struct
with all the parameters instead.

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

llvm-svn: 266295
2016-04-14 12:51:45 +00:00
Dmitry Vyukov 909d080d98 asan: fix build
Some bots failed with:

sanitizer_quarantine.h:104:7: error: unused typedef 'assertion_failed__104' [-Werror,-Wunused-local-typedef]
      COMPILER_CHECK(kPrefetch <= ARRAY_SIZE(b->batch));

Replace COMPILER_CHECK with CHECK.

llvm-svn: 266291
2016-04-14 11:40:08 +00:00
Dmitry Vyukov a7de697ae6 asan: fix out-of-bounds access in quarantine
llvm-svn: 266288
2016-04-14 09:52:33 +00:00
Kuba Brecka 036d060044 [sanitizer] Restore stderr when using forkpty() to spawn external symbolizer
In `AtosSymbolizer`, we're using `forkpty()` to create a new pseudo-terminal to communicate with the `atos` tool (we need that to avoid output buffering in interactive mode). This however redirects both stdout and stderr into a single stream, so when we read the output, we can't distinguish between errors and standard replies. Let's save&restore stderr to avoid that.

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

llvm-svn: 265923
2016-04-11 09:27:09 +00:00
Derek Bruening a7685389c8 [sanitizer] Add early call handling to strlen interceptor
Summary:
The strlen interceptor is sometimes invoked too early for REAL(strlen) to
be initialized.  A special check is added to use internal_strlen for this
situation.

Reviewers: dim

Subscribers: llvm-commits, samsonov

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

Change-Id: I3acc58f4abbae1904f25324abd84efea67aad0a2
llvm-svn: 265705
2016-04-07 18:07:09 +00:00
Kuba Brecka d0e83a6eb2 [sanitizer] Make AtosSymbolizer more resilient when symbolicating a zero address
llvm-svn: 265269
2016-04-03 19:13:03 +00:00
Reid Kleckner 1992ac75db Fix warnings uncovered by building with clang-cl
Move ifdefs to avoid unused static helpers. Move alignment attribute so
that it is respected in GCC and MSVC.

llvm-svn: 265153
2016-04-01 17:09:12 +00:00
Reid Kleckner a8e5c0c200 Fix a load of -Wunknown-pragma warnings from clang-cl
llvm-svn: 265152
2016-04-01 17:09:08 +00:00
Derek Bruening e988af9073 [sanitizer] Add memset, memmove, and memcpy to the common interceptors
Summary:
Currently, sanitizer_common_interceptors.inc has an implicit, undocumented
assumption that the sanitizer including it has previously declared
interceptors for memset and memmove.  Since the memset, memmove, and memcpy
routines require interception by many sanitizers, we add them to the
set of common interceptions, both to address the undocumented assumption
and to speed future tool development.  They are intercepted under a new
flag intercept_intrin.

The tsan interceptors are removed in favor of the new common versions.  The
asan and msan interceptors for these are more complex (they incur extra
interception steps and their function bodies are exposed to the compiler)
so they opt out of the common versions and keep their own.

Reviewers: vitalybuka

Subscribers: zhaoqin, llvm-commits, kcc

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

llvm-svn: 264451
2016-03-25 19:33:45 +00:00
Kuba Brecka 46b9363683 [tsan] Use direct syscalls for internal_mmap and internal_munmap on OS X
On OS X, internal_mmap just uses mmap, which can invoke callbacks into libmalloc (e.g. when MallocStackLogging is enabled). This can subsequently call other intercepted functions, and this breaks our Darwin-specific ThreadState initialization. Let's use direct syscalls in internal_mmap and internal_munmap. Added a testcase.

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

llvm-svn: 264259
2016-03-24 11:50:21 +00:00
Derek Bruening b584410b80 [sanitizer] Add strnlen to the common interceptors
Summary:
Adds strnlen to the common interceptors, under the existing flag
intercept_strlen.

Removes the now-duplicate strnlen interceptor from asan and msan.
This adds strnlen to tsan, which previously did not intercept it.

Adds a new test of strnlen to the sanitizer_common test cases.

Reviewers: samsonov

Subscribers: zhaoqin, llvm-commits, kcc

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

llvm-svn: 264195
2016-03-23 21:24:28 +00:00
Evgeniy Stepanov accf390a75 [sanitizer] Add strchr* to the common interceptors
Adds strchr, strchrnul, and strrchr to the common interceptors, under a new
common flag intercept_strchr.

Removes the now-duplicate strchr interceptor from asan and all 3
interceptors from tsan. Previously, asan did not intercept strchrnul, but
does now; previously, msan did not intercept strchr, strchrnul, or strrchr,
but does now.

http://reviews.llvm.org/D18329

Patch by Derek Bruening!

llvm-svn: 263992
2016-03-21 21:36:17 +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
Kuba Brecka 493028e8e2 Removing a non-intentional debug output that got committed in r263695.
llvm-svn: 263698
2016-03-17 09:27:40 +00:00
Kuba Brecka 4c80867ecf [sanitizer] On OS X, verify that interceptors work and abort if not, take 2
On OS X 10.11+, we have "automatic interceptors", so we don't need to use DYLD_INSERT_LIBRARIES when launching instrumented programs. However, non-instrumented programs that load TSan late (e.g. via dlopen) are currently broken, as TSan will still try to initialize, but the program will crash/hang at random places (because the interceptors don't work). This patch adds an explicit check that interceptors are working, and if not, it aborts and prints out an error message suggesting to explicitly use DYLD_INSERT_LIBRARIES.

TSan unit tests run with a statically linked runtime, where interceptors don't work. To avoid aborting the process in this case, the patch replaces `DisableReexec()` with a weak `ReexecDisabled()` function which is defined to return true in unit tests.

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

llvm-svn: 263695
2016-03-17 08:37:25 +00:00
Kuba Brecka 46bf454d18 [tsan] Detect uses of uninitialized, destroyed and invalid mutexes
This patch adds a new TSan report type, ReportTypeMutexInvalidAccess, which is triggered when pthread_mutex_lock or pthread_mutex_unlock returns EINVAL (this means the mutex is invalid, uninitialized or already destroyed).

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

llvm-svn: 263641
2016-03-16 15:39:20 +00:00
Mohit K. Bhakkad beb155b4fa [ASAN] Add support for mips/mips64 android
Patch by Duane Sand

Reviewers: samsonov

Subscribers: duanesand, jaydeep, sagar, llvm-commits, filcab.

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

llvm-svn: 263621
2016-03-16 08:23:10 +00:00
Kuba Brecka 0fb87f77ae Revert r263551 due to a test failure.
llvm-svn: 263553
2016-03-15 15:53:39 +00:00
Kuba Brecka 69b5943a05 [sanitizer] On OS X, verify that interceptors work and abort if not
On OS X 10.11+, we have "automatic interceptors", so we don't need to use DYLD_INSERT_LIBRARIES when launching instrumented programs. However, non-instrumented programs that load TSan late (e.g. via dlopen) are currently broken, as TSan will still try to initialize, but the program will crash/hang at random places (because the interceptors don't work). This patch adds an explicit check that interceptors are working, and if not, it aborts and prints out an error message suggesting to explicitly use DYLD_INSERT_LIBRARIES.

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

llvm-svn: 263551
2016-03-15 14:30:28 +00:00
Mohit K. Bhakkad f4cc1fc7e9 [Sanitizer][MIPS] internal lstat and fstat for mips64
Reviewers: dvyukov

Subscribers: jaydeep, sagar, llvm-commits

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

llvm-svn: 263218
2016-03-11 10:51:03 +00:00
Mohit K. Bhakkad ac4bd45f02 [Compiler-rt] Fix ioctl codes for MIPS in sanitizer_ioctl_test
Reviewers: samsonov

Subscribers: jaydeep, sagar, llvm-commits

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

llvm-svn: 263199
2016-03-11 05:57:20 +00:00
Alexey Samsonov ed3d347e25 [sanitizer] Add strlen to the common interceptors
Summary:
Adds strlen to the common interceptors, under a new common flag
intercept_strlen.  This provides better sharing of interception code among
sanitizers and cleans up the inconsistent type declarations of the
previously duplicated interceptors.

Removes the now-duplicate strlen interceptor from asan, msan, and tsan.
The entry check semantics are normalized now for msan and asan, whose
private strlen interceptors contained multiple layers of checks that
included impossible-to-reach code.  The new semantics are identical to the
old: bypass interception if in the middle of init or if both on Mac and not
initialized; else, call the init routine and proceed.

Patch by Derek Bruening!

Reviewers: samsonov, vitalybuka

Subscribers: llvm-commits, kcc, zhaoqin

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

llvm-svn: 263177
2016-03-11 00:45:49 +00:00
Reid Kleckner ad04914a53 [Windows] Fix UnmapOrDie and MmapAlignedOrDie
Now ASan can return virtual memory to the underlying OS. Portable
sanitizer runtime code needs to be aware that UnmapOrDie cannot unmap
part of previous mapping.

In particular, this required changing how we implement MmapAlignedOrDie
on Windows, which is what Allocator32 uses.

The new code first attempts to allocate memory of the given size, and if
it is appropriately aligned, returns early. If not, it frees the memory
and attempts to reserve size + alignment bytes. In this region there
must be an aligned address. We then free the oversized mapping and
request a new mapping at the aligned address immediately after. However,
a thread could allocate that virtual address in between our free and
allocation, so we have to retry if that allocation fails. The existing
thread creation stress test managed to trigger this condition, so the
code isn't totally untested.

Reviewers: samsonov

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

llvm-svn: 263160
2016-03-10 20:47:26 +00:00
Dimitry Andric b45bf0af91 Retrieve command line arguments and environment correctly on FreeBSD
Summary:
Recently I saw the test `TestCases/Posix/print_cmdline.cc` failing on
FreeBSD, with "expected string not found in input".  This is because
asan could not retrieve the command line arguments properly.

In `lib/sanitizer_common/sanitizer_linux.cc`, this is taken care of by
the `GetArgsAndEnv()` function, but it uses `__libc_stack_end` to get at
the required data.  This variable does not exist on BSDs; the regular
way to retrieve the arguments and environment information is via the
`kern.ps_strings` sysctl.

I added this functionality in sanitizer_linux.cc, as a separate #ifdef
block in `GetArgsAndEnv()`.  Also, `ReadNullSepFileToArray()` becomes
unused due to this change.  (It won't work on FreeBSD anyway, since
`/proc` is not mounted by default.)

Reviewers: kcc, emaste, joerg, davide

Subscribers: llvm-commits, emaste

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

llvm-svn: 263157
2016-03-10 20:22:02 +00:00
Alexey Samsonov c1424fc7c8 sanitizer: Fix endianness checks for gcc
Summary:
__BIG_ENDIAN__ and __LITTLE_ENDIAN__ are not supported by gcc, which
eg. for ubsan Value::getFloatValue will silently fall through to
the little endian branch, breaking display of float values by ubsan.
Use __BYTE_ORDER__ == __ORDER_BIG/LITTLE_ENDIAN__ as the condition
instead, which is supported by both clang and gcc.

Noticed while porting ubsan to s390x.

Patch by Marcin Kościelnicki!

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

llvm-svn: 263077
2016-03-09 23:39:40 +00:00
Mohit K. Bhakkad 9e168987b9 [Compiler-rt][MIPS] Defining macros for MIPS archs
Reviewers: samsonov

Subscribers: filcab, jaydeep, sagar, llvm-commits

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

llvm-svn: 263000
2016-03-09 07:57:20 +00:00
Filipe Cabecinhas b08c76f5f8 [cmake] Address Samsonov's post-commit review of r262723
Reviewers: samsonov

Subscribers: llvm-commits

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

llvm-svn: 262770
2016-03-05 10:01:04 +00:00
Dmitry Vyukov a029b79e1a tsan: describe heap/data locations in Go
llvm-svn: 262343
2016-03-01 15:38:12 +00:00
Dmitry Vyukov f5fcdd268f sanitizer_common: silence compiler warning
llvm-svn: 262342
2016-03-01 15:36:42 +00:00
Mohit K. Bhakkad 1d1493219c [Compiler-rt][MIPS] Correct Dynamic Thread Vector offset for MIPS
Reviewers: samsonov

Subscribers: dsanders, jaydeep, sagar, llvm-commits

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

llvm-svn: 262303
2016-03-01 05:56:33 +00:00
Filipe Cabecinhas b7692bc3e9 [UBSan] Fix isDerivedFromAtOffset on iOS ARM64
Summary:
iOS on ARM64 doesn't unique RTTI.
Ref: clang's iOS64CXXABI::shouldRTTIBeUnique()

Due to this, pointer-equality will not necessarily work in this
architecture, across dylib boundaries.

dynamic_cast<>() will (as expected) still work, since Apple ships with
one prepared for this, but we can't rely on the type names being
pointer-equal.

I've limited the expensive strcmp check to the specific architecture
which needs it.

Example which triggers this bug:

lib.h:
  struct X {
    virtual ~X() {}
  };
  X *libCall();

lib.mm:
  X *libCall() {
    return new X;
  }

prog.mm:
  int main() {
    X *px = libCall();
    delete px;
  }

Expected output: Nothing
Actual output:
<unknown>: runtime error: member call on address 0x00017001ef50 which does not point to an object of type 'X'
0x00017001ef50: note: object is of type 'X'
 00 00 00 00  60 00 0f 00 01 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00
              ^~~~~~~~~~~~~~~~~~~~~~~
              vptr for ‘X’

Reviewers: kubabrecka, samsonov, eugenis, rsmith

Subscribers: aemerson, llvm-commits, rengolin

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

llvm-svn: 262147
2016-02-27 19:57:44 +00:00
Alexey Samsonov 07f9c0f558 [Sanitizer] Protect against compiler-inserted memcpy() in InternalMmapVector::push_back().
llvm-svn: 261909
2016-02-25 18:12:30 +00:00
Maxim Ostapenko 50ca4464c4 [sanitizer] Fix third parameter in COMMON_INTERCEPTOR_WRITE_RANGE in recv and recvfrom interceptors.
Pass res instead of len as third parameter to COMMON_INTERCEPTOR_WRITE_RANGE,
because otherwise we can write to unrelated memory (in MSan) or get wrong report (in ASan).

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

llvm-svn: 261898
2016-02-25 17:07:38 +00:00
Maxim Ostapenko b9fd2e0015 [sanitizer] Disable recv and recvfrom interceptors on Windows.
Trying to fix sanitizer-windows buildbot by disabling new interceptors on Windows.

llvm-svn: 261844
2016-02-25 09:36:20 +00:00
Maxim Ostapenko 7389936f57 [sanitizer] Move recvmsg and recv interceptors to sanitizer_common.
This patch moves recv and recvfrom interceptors from MSan and TSan to
sanitizer_common to enable them in ASan.

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

llvm-svn: 261841
2016-02-25 08:44:25 +00:00
Alexey Samsonov 8e3cbde27d [Sanitizer] Introduce ListOfModules object and use it to replace GetListOfModules().
Summary:
This removes the hard limit on the number of loaded modules (used to be
16K), and makes it easier to use LoadedModules w/o causing a memory
leak: ListOfModules owns the modules, and makes sure to properly clean
them in destructor.

Remove filtering functionality that is only needed in one place (LSan).

Reviewers: aizatsky

Subscribers: llvm-commits, kcc

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

llvm-svn: 261554
2016-02-22 18:52:51 +00:00
Mike Aizatsky 635ade9305 [sancov] use GetLoadedModules for list of modules rather than sanitizer's list.
llvm-svn: 261376
2016-02-19 22:55:21 +00:00
Reid Kleckner 0765fbc332 [WinASan] Fix page size and mmap granularity confusion
We were erroneously reporting 16K as the page size on Windows because
the code that does the shadow mapping was using page size instead of
allocation granularity. After fixing that, we can resolve the FIXMEs in
the Windows implementations of GetPageSize and GetMmapGranularity by
calling GetSystemInfo instead of returning hard-coded, incorrect
answers.

llvm-svn: 261233
2016-02-18 17:58:22 +00:00
Jonas Hahnfeld 9bf3acd5ff [compiler-rt] Return correct size of struct pthread for glibc-2.12.2
There seems to be a difference between 2.12.1 and 2.12.2 in 64-bit build.
Tested on Scientific Linux 6.6, based on RHEL.

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

llvm-svn: 261193
2016-02-18 07:08:26 +00:00
Zia Ansari 3cc265458f Fixed non-NULL terminating array bug in SanitizerCommon.StartSubprocessTest that caused them to fail sometimes and act flaky.
Differential Revision: http://reviews.llvm.org/D17228

llvm-svn: 260876
2016-02-15 05:11:51 +00:00
Alexey Samsonov eb649bcfb9 [LSan] Print more helpful error message if LSan crashes during leak detection.
llvm-svn: 260717
2016-02-12 20:20:51 +00:00
Mike Aizatsky 92cbbfcd89 [sancov] improved object files handling.
Updating sancov invocation on html_cov_dump.

sancov change: http://reviews.llvm.org/D17169

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

llvm-svn: 260629
2016-02-12 00:29:24 +00:00
Reid Kleckner ceda883e4d [Windows] Fill in read/write information in SignalContext
Implements https://github.com/google/sanitizers/issues/653

llvm-svn: 260539
2016-02-11 16:44:35 +00:00
Evgeniy Stepanov aa42f29221 [asan] Fix build on Windows and PowerPC.
llvm-svn: 260175
2016-02-09 00:28:57 +00:00
Evgeniy Stepanov 0d7839d0d3 [asan] Fix Windows build.
llvm-svn: 260167
2016-02-08 23:01:06 +00:00
Evgeniy Stepanov bc937a10a2 [asan] Remove leftover debug print statement.
llvm-svn: 260165
2016-02-08 22:54:46 +00:00
Evgeniy Stepanov 52f6c262d9 [asan] Implement SEGV read vs write detection for ARM and AArch64.
llvm-svn: 260163
2016-02-08 22:50:25 +00:00
Dimitry Andric 927e986ac4 Fix build on FreeBSD after r259741.
On FreeBSD, the uc_mcontext member of ucontext_t has a member called
mc_err, which corresponds to the Linux member gregs[REG_ERR].

Reviewed by:	rdivacky@FreeBSD.org

llvm-svn: 260046
2016-02-07 17:40:45 +00:00
Kostya Serebryany 0e05d6eb9c [asan] fix the non-x86 build
llvm-svn: 259745
2016-02-04 02:33:48 +00:00
Kostya Serebryany 2b9be25066 [asan] When catching a signal caused by a memory access, print if it's a READ or a WRITE. This touches win/mac files which I have not tested, if a win/mac bot fails I'll try to quick-fix
llvm-svn: 259741
2016-02-04 02:02:09 +00:00
Anna Zaks c77a080bdb [asan] Add iOS support.
llvm-svn: 259451
2016-02-02 02:01:17 +00:00
Mike Aizatsky c22e72e6b0 GetArgv returns null on widnows, do not crash
llvm-svn: 259005
2016-01-28 00:31:49 +00:00
Mike Aizatsky adc0a67a55 using /system/bin/sh on android in tests.
Subscribers: tberghammer, danalbert, srhines

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

llvm-svn: 259001
2016-01-27 23:58:23 +00:00
Mike Aizatsky 2654299d6a [sanitizers] generating html report on coverage dump
Subscribers: tberghammer, danalbert, srhines

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

llvm-svn: 258999
2016-01-27 23:51:36 +00:00
Mike Aizatsky 48c26de04e [sanitizers] using execv instead of execve with null env.
Differential Revision: http://reviews.llvm.org/D16646

llvm-svn: 258983
2016-01-27 20:35:18 +00:00
Mike Aizatsky abae3a44af [sanitizers] execve & waitpid on mac.
llvm-svn: 258874
2016-01-26 22:53:52 +00:00
Chris Bieneman 63a81b1415 Remove autoconf support for building runtime libraries.
Summary:
This patch is provided in preparation for removing autoconf on 1/26. The proposal to remove autoconf on 1/26 was discussed on the llvm-dev thread here: http://lists.llvm.org/pipermail/llvm-dev/2016-January/093875.html

    "I am the punishment of God... If [autoconf] had not committed great sins, God would not have sent a punishment like me upon [it]."
    -Genghis Khan

Reviewers: chandlerc, grosbach, bob.wilson, zaks.anna, kubabrecka, samsonov, echristo

Subscribers: iains, llvm-commits

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

llvm-svn: 258863
2016-01-26 21:31:12 +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
Mike Aizatsky 4a93316c8c [sanitizers] extracted process management functions
Differential Revision: http://reviews.llvm.org/D16546

llvm-svn: 258849
2016-01-26 20:10:01 +00:00
Mike Aizatsky 92f0f7c2f3 Revert "[sanitizers] extracted process management functions"
This reverts commit e5b34d5a2bf4c882bc647dd26a8cea2adc76f63c.

llvm-svn: 258713
2016-01-25 19:52:25 +00:00
Mike Aizatsky e71c99c7e2 fixed clang-tidy config
llvm-svn: 258711
2016-01-25 19:43:55 +00:00
Mike Aizatsky 53849fee26 [sanitizers] extracted process management functions
Differential Revision: http://reviews.llvm.org/D16542

llvm-svn: 258710
2016-01-25 19:43:52 +00:00
Evgeniy Stepanov 2531584daa [asan] Don't use sysconf(_SC_PAGESIZE) on Android.
This is broken in the current (post-MNC) master branch.
Use EXEC_PAGESIZE instead, the same as on x86 Linux.

This change fixes startup crashes in the existing tests on AOSP
master.

llvm-svn: 258706
2016-01-25 19:25:20 +00:00
Mike Aizatsky 6e9b970805 .clang-tidy for sanitizer package to override root llvm style
Summary:
sanitizer-common follows Google code style, override
clang-tidy config.

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

llvm-svn: 258449
2016-01-21 23:21:31 +00:00
Mike Aizatsky 7d866cb145 using const instead of constexpr: MSVC troubles
llvm-svn: 258253
2016-01-19 23:46:27 +00:00
Mike Aizatsky dba78e676f [sancov] NFC: simplifying DumpOffsets.
Summary: Extracting GetRangeOffset function before report-on-dump
functionality.

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

llvm-svn: 258211
2016-01-19 22:47:38 +00:00
Nico Weber 82210fbc1e Fix -Wexpansion-to-defined warnings in compiler-rt.
llvm-svn: 258200
2016-01-19 22:02:12 +00:00
Maxim Ostapenko 1965cc6258 [asan] Optionally print reproducer cmdline in ASan reports.
Differential Revision: http://reviews.llvm.org/D16070

llvm-svn: 258037
2016-01-18 07:55:12 +00:00
Peter Collingbourne d73cd4ab01 Attempt to fix sanitizer-windows bot.
llvm-svn: 257978
2016-01-16 01:15:19 +00:00
Peter Collingbourne 5788e1259b Introduce stats and stats_client libraries.
This is part of a new statistics gathering feature for the sanitizers.
See clang/docs/SanitizerStats.rst for further info and docs.

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

llvm-svn: 257972
2016-01-16 00:31:29 +00:00
Yabin Cui 66e5db99b3 [tsan] Use internal_sigfillset to replace REAL(sigfillset).
Summary:
Android doesn't intercept sigfillset, so REAL(sigfillset) is null.
And we can use internal_sigfillset() for all cases.

Reviewers: kcc, eugenis, kubabrecka, dvyukov

Subscribers: llvm-commits, tberghammer, danalbert

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

llvm-svn: 257862
2016-01-15 02:59:23 +00:00
Peter Collingbourne d2f24b62b5 Unbreak Windows build.
llvm-svn: 257860
2016-01-15 02:51:26 +00:00
Peter Collingbourne b825bf32b7 sanitizer_common: C++ify the IntrusiveList iterator interface.
llvm-svn: 257858
2016-01-15 02:19:20 +00:00
Sumanth Gundapaneni b76bf106b1 Fix the cross compilation of unit tests. NFC (second attempt)
With COMPILER_RT_INCLUDE_TESTS turned ON and in a cross compiling
environment, the unit tests fail to link. This patch does the following changes

>Rename COMPILER_RT_TEST_CFLAGS to COMPILER_RT_UNITTEST_CFLAGS to reflect the 
way it's used.
>Add COMPILER_RT_TEST_COMPILER_CFLAGS to COMPILER_RT_UNITTEST_CFLAGS so 
that cross-compiler would be able to build/compile the unit tests
>Add COMPILER_RT_UNITTEST_LINKFLAGS to COMPILER_RT_UNITTEST_CFLAGS so 
that cross-compiler would be able to link the unit tests (if needed)

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

llvm-svn: 257783
2016-01-14 18:18:49 +00:00
Kuba Brecka 0626dd0d3b [tsan] Introduce a "ignore_interceptors_accesses" option
On OS X, TSan already passes all unit and lit tests, but for real-world applications (even very simple ones), we currently produce a lot of false positive reports about data races. This makes TSan useless at this point, because the noise dominates real bugs. This introduces a runtime flag, "ignore_interceptors_accesses", off by default, which makes TSan ignore all memory accesses that happen from interceptors. This will significantly lower the coverage and miss a lot of bugs, but it eliminates most of the current false positives on OS X.

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

llvm-svn: 257760
2016-01-14 12:24:37 +00:00
Hans Wennborg 7b9d2b6c87 Revert r257686 "With COMPILER_RT_INCLUDE_TESTS turned ON and in a cross compiling"
This broke the build. For example, from
http://lab.llvm.org:8011/builders/clang-cmake-aarch64-full/builds/1191/steps/cmake%20stage%201/logs/stdio:

	-- Compiler-RT supported architectures: aarch64
	CMake Error at projects/compiler-rt/cmake/Modules/AddCompilerRT.cmake:170 (string):
		string sub-command REPLACE requires at least four arguments.
	Call Stack (most recent call first):
		projects/compiler-rt/lib/CMakeLists.txt:4 (include)

llvm-svn: 257694
2016-01-13 22:50:24 +00:00
Sumanth Gundapaneni 2d2f2b5c80 With COMPILER_RT_INCLUDE_TESTS turned ON and in a cross compiling
environment, the unit tests fail to link. This patch does the following changes

>Rename COMPILER_RT_TEST_CFLAGS to COMPILER_RT_UNITTEST_CFLAGS to reflect the 
way it's used.
>Add COMPILER_RT_TEST_COMPILER_CFLAGS to COMPILER_RT_UNITTEST_CFLAGS so that 
cross-compiler would be able to build/compile the unit tests
>Add COMPILER_RT_UNITTEST_LINKFLAGS to COMPILER_RT_UNITTEST_CFLAGS so that 
cross-compiler would be able to link the unit tests (if needed)

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

llvm-svn: 257686
2016-01-13 22:09:47 +00:00
Kostya Serebryany e3580956ea [libFuzzer] extend the weak memcmp/strcmp/strncmp interceptors to receive the result of the computations. With that, don't do any mutations if memcmp/etc returned 0
llvm-svn: 257423
2016-01-12 00:43:42 +00:00
Kuba Brecka 490b7f8b6d Follow-up fix for r256988 to unbreak the Linux buildbot.
llvm-svn: 257042
2016-01-07 09:14:41 +00:00
Anna Zaks 56c302fee6 [sanitizers] Log all output to CrashReport on OS X
Log all of sanitizers' output (not just ASan bug reports) to CrashReport,
which simplifies diagnosing failed checks as well as other errors. This
also allows to strip the color sequences early from the printed buffer,
which is more efficient than what we had perviously.

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

llvm-svn: 256988
2016-01-06 23:15:01 +00:00
Mike Aizatsky 54fc6575c5 [sancov] coverage pc buffer
Differential Revision: http://reviews.llvm.org/D15871

llvm-svn: 256804
2016-01-05 01:49:39 +00:00
Kostya Serebryany 1d1be3dd88 [asan] fix fopen interceptor to not crash if path is NULL
llvm-svn: 256182
2015-12-21 19:22:26 +00:00
Alexey Samsonov 081a24e3a7 [UBSan] Implement runtime suppressions (PR25066).
Summary:
Add the ability to suppress UBSan reports for files/functions/modules
at runtime. The user can now pass UBSAN_OPTIONS=suppressions=supp.txt
with the contents of the form:

signed-integer-overflow:file-with-known-overflow.cpp
alignment:function_doing_unaligned_access
vptr:shared_object_with_vptr_failures.so

Suppression categories match the arguments passed to -fsanitize=
flag (although, see below). There is no overhead if suppressions are
not provided. Otherwise there is extra overhead for symbolization.

Limitations:
1) sometimes suppressions need debug info / symbol table to function
   properly (although sometimes frontend generates enough info to
   do the match).
2) it's only possible to suppress recoverable UB kinds - if you've
   built the code with -fno-sanitize-recover=undefined, suppressions
   will not work.
3) categories are fine-grained check kinds, not groups like "undefined"
   or "integer", so you can't write "undefined:file_with_ub.cc".

Reviewers: rsmith, kcc

Subscribers: cfe-commits

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

llvm-svn: 256018
2015-12-18 19:56:42 +00:00
Kostya Serebryany 354bbb2ccd [asan] add option: handle_sigill
llvm-svn: 255588
2015-12-15 00:33:45 +00:00