Commit Graph

208 Commits

Author SHA1 Message Date
Daniel Sanders 9ede03d4f2 [mips][sanitizer_common] Don't use `ld` in internal_clone() on 32-bit MIPS.
Summary:
On a 32-bit MIPS, the `ld` instruction does not exist. However, GAS has an `ld`
macro that expands to a pair of `lw` instructions which load to a pair of
registers (reg, and reg+1). This macro is not available in the Integrated
Assembler and its use causes -fintegrated-as builds to fail. Even if it were
available, the behaviour on 32-bit MIPS would be incorrect since the current
usage of `ld` causes the code to clobber $5 (which is supposed to hold
child_stack). It also clobbers $k0 which is reserved for kernel use.

Aside from enabling builds with the integrated assembler, there is no functional
change since internal_clone() is only used by StopTheWorld() which is only used
by 64-bit sanitizers.

Reviewers: kcc, sagar

Subscribers: mohit.bhakkad, jaydeep, sagar, llvm-commits

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

llvm-svn: 269297
2016-05-12 14:21:33 +00:00
Kuba Brecka 00dde7563e Fixup for r269288. SleepForSeconds is not available in nolibc builds, let's add an internal_sleep.
llvm-svn: 269296
2016-05-12 14:08:56 +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 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 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
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
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
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
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
Evgeniy Stepanov aa42f29221 [asan] Fix build on Windows and PowerPC.
llvm-svn: 260175
2016-02-09 00:28:57 +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
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
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
Kostya Serebryany 354bbb2ccd [asan] add option: handle_sigill
llvm-svn: 255588
2015-12-15 00:33:45 +00:00
Bill Schmidt 2979162732 [PPC64, TSAN] LLVM basic enablement of thread sanitizer for PPC64 (BE and LE)
This patch is by Simone Atzeni with portions by Adhemerval Zanella.

This contains the LLVM patches to enable the thread sanitizer for
PPC64, both big- and little-endian.  Two different virtual memory
sizes are supported:  Old kernels use a 44-bit address space, while
newer kernels require a 46-bit address space.

There are two companion patches that will be added shortly.  There is
a Clang patch to actually turn on the use of the thread sanitizer for
PPC64.  There is also a patch that I wrote to provide interceptor
support for setjmp/longjmp on PPC64.

Patch discussion at reviews.llvm.org/D12841.

llvm-svn: 255057
2015-12-08 21:54:39 +00:00
Evgeniy Stepanov 2f107ce132 [asan] Remove the use of system properties on Android.
System properties are not accessible through NDK (we've been using
hacks to get to them) and they are unavailable during ASan
initialization in .preinit_array. Use environment variables and
files instead (ex. ASAN_OPTIONS=include_if_exists=/path).

No test changes. This feature was not tested because the properties
are system-wide and would conflict with the parallel test runner. Yet
another reason to get rid of it.

llvm-svn: 254783
2015-12-04 22:28:27 +00:00
Kuba Brecka 65aa45e872 [tsan] Use re-exec method to enable interceptors on older versions of OS X
In AddressSanitizer, we have the MaybeReexec method to detect when we're running without DYLD_INSERT_LIBRARIES (in which case interceptors don't work) and re-execute with the environment variable set. On OS X 10.11+, this is no longer necessary, but to have ThreadSanitizer supported on older versions of OS X, let's use the same method as well. This patch moves the implementation from `asan/` into `sanitizer_common/`.

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

llvm-svn: 254600
2015-12-03 10:39:43 +00:00
Adhemerval Zanella b0d5dd0199 [lsan] [aarch64] Add support for AArch64
This patch add support for leak sanitizer for aarch64.  Similar to
MIPS it uses a SizeClassAllocator32 due VMA constraints (aarch64
currently supports 39 and 42-bit VMA).

It also fixes the android build issue.

llvm-svn: 250898
2015-10-21 13:08:06 +00:00
Evgeniy Stepanov 437615639f Revert "[lsan] [aarch64] Add support for AArch64"
This reverts commit ea02fa45225c35613bfecab383fb526e24b74497 (r249337).

Reason: broken "ninja AsanUnitTests" on Android/AArch64.
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/20675/steps/build%20compiler-rt%20android%2Faarch64/logs/stdio

llvm-svn: 249730
2015-10-08 20:08:30 +00:00
Adhemerval Zanella 5ea8dcb8cf [lsan] [aarch64] Add support for AArch64
This patch add support for leak sanitizer for aarch64.  Similar to
MIPS it uses a SizeClassAllocator32 due VMA constraints (aarch64
currently supports 39 and 42-bit VMA).

llvm-svn: 249337
2015-10-05 19:16:09 +00:00
Vedant Kumar 552c0111f1 [sanitizer_common] Apply modernize-use-nullptr, other minor fixes
- Trim spaces.
- Use nullptr in place of 0 for pointer variables.
- Use '!p' in place of 'p == 0' for null pointer checks.

Patch by Eugene Zelenko!

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

llvm-svn: 248964
2015-09-30 23:52:54 +00:00
Adhemerval Zanella 36b5042753 [compiler-rt] [sanitizers] Add aarch64 syscall optimization support
This patch adds the inline syscall support for aarch64 instead of relying
on the syscall runtime function.

llvm-svn: 245702
2015-08-21 14:50:36 +00:00
Kostya Serebryany cc9fd3cbe9 [sanitizer] 2-nd attempt. Add the flag handle_sigfpe that is default true to handle SIGFPE crashes same as SIGSEV crashes, patch by Karl Skomski. This time the test is enabled only on x86-64 (it broke on ARM)
llvm-svn: 244234
2015-08-06 17:52:54 +00:00
Renato Golin 4ae2e1f575 Revert "[sanitizer] Add the flag handle_sigfpe that is default true to handle SIGFPE crashes same as SIGSEV crashes, patch by Karl Skomski"
This reverts commit r244136, it was breaking the ARM bots for too long. We should investigate it offline.

llvm-svn: 244210
2015-08-06 12:42:46 +00:00
Kostya Serebryany ce1799a83f [sanitizer] Add the flag handle_sigfpe that is default true to handle SIGFPE crashes same as SIGSEV crashes, patch by Karl Skomski
llvm-svn: 244136
2015-08-05 21:19:11 +00:00
Adhemerval Zanella d7984710ae [tsan] Enable tsan for aarch64
This patch enabled TSAN for aarch64 with 39-bit VMA layout.  As defined by
tsan_platform.h the layout used is:

0000 4000 00 - 0200 0000 00: main binary
2000 0000 00 - 4000 0000 00: shadow memory
4000 0000 00 - 5000 0000 00: metainfo
5000 0000 00 - 6000 0000 00: -
6000 0000 00 - 6200 0000 00: traces
6200 0000 00 - 7d00 0000 00: -
7d00 0000 00 - 7e00 0000 00: heap
7e00 0000 00 - 7fff ffff ff: modules and main thread stack

Which gives it about 8GB for main binary, 4GB for heap and 8GB for
modules and main thread stack.

Most of tests are passing, with the exception of:

 * ignore_lib0, ignore_lib1, ignore_lib3 due a kernel limitation for
   no support to make mmap page non-executable.

 * longjmp tests due missing specialized assembly routines.

These tests are xfail for now.

The only tsan issue still showing is:

  rtl/TsanRtlTest/Posix.ThreadLocalAccesses

Which still required further investigation.  The test is disable for
aarch64 for now.

llvm-svn: 244055
2015-08-05 15:17:59 +00:00
Daniel Sanders adf1fcc2a5 Re-commit r243686 - [Sanitizers] [Bug 24151] Generalize type of offset in internal_mmap
The builder remains broken in the same way without this patch so this patch is
innocent.

llvm-svn: 243744
2015-07-31 11:29:25 +00:00
Daniel Sanders 923906a600 Revert r243686 - [Sanitizers] [Bug 24151] Generalize type of offset in internal_mmap
It's implicated in a buildbot failure and while the failure looks unrelated,
this commit is the only probably candidate in the blamelist.

llvm-svn: 243740
2015-07-31 09:04:37 +00:00
Daniel Sanders 043717d572 [Sanitizers] [Bug 24151] Generalize type of offset in internal_mmap
Summary:
Using u64 as type for offset changes its value, changing starting address for map in file.
This patch solves Bug 24151, which raises issue while mapping file in mips32.

Patch by Mohit Bhakkad

Reviewers: dsanders, kcc

Subscribers: hans, llvm-commits, samsonov, nitesh.jain, sagar, bhushan, jaydeep

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

llvm-svn: 243686
2015-07-30 21:00:48 +00:00
Evgeniy Stepanov 30257173b3 [sanitizer] Fix Mac build.
llvm-svn: 243480
2015-07-28 21:01:42 +00:00
Evgeniy Stepanov 7eeb02bd09 [asan] Read process name from /proc/self/cmdline on Linux.
Rename getBinaryBasename() to getProcessName() and, on Linux,
read it from /proc/self/cmdline instead of /proc/self/exe. The former
can be modified by the process. The main motivation is Android, where
application processes re-write cmdline to a package name. This lets
us setup per-application ASAN_OPTIONS through include=/some/path/%b.

llvm-svn: 243473
2015-07-28 20:27:51 +00:00
Evgeniy Stepanov f021b9b3b3 [asan] Fix android system property access on aarch64.
__system_property_get is gone from the NDK headers and libs in 64-bit
toolchains, but it is still exported by platform libc.so.

llvm-svn: 243137
2015-07-24 18:57:44 +00:00
Evgeniy Stepanov 5a268b10b3 [sanitizer] Implement logging to syslog.
Previously, Android target had a logic of duplicating all sanitizer
output to logcat. This change extends it to all posix platforms via
the use of syslog, controlled by log_to_syslog flag. Enabled by
default on Android, off everywhere else.

A bit of cmake magic is required to allow Printf() to call a libc
function. I'm adding a stub implementation to support no-libc builds
like dfsan and safestack.

This is a second attempt. I believe I've fixed all the issues that
prompted the revert: Mac build, and all kinds of non-CMake builds
(there are 3 of those).

llvm-svn: 243051
2015-07-23 22:05:20 +00:00
Evgeniy Stepanov ffbc4ec790 Revert r242975.
Breaks Mac build.

llvm-svn: 242978
2015-07-23 01:29:26 +00:00
Evgeniy Stepanov 4f03227fa2 [sanitizer] Implement logging to syslog.
Previously, Android target had a logic of duplicating all sanitizer
output to logcat. This change extends it to all posix platforms via
the use of syslog, controlled by log_to_syslog flag. Enabled by
default on Android, off everywhere else.

A bit of cmake magic is required to allow Printf() to call a libc
function. I'm adding a stub implementation to support no-libc builds
like dfsan and safestack.

llvm-svn: 242975
2015-07-22 23:57:19 +00:00
Alexey Samsonov e6c614d48a [Sanitizer] Teach ReadFileToBuffer to distinguish empty file from inaccessible file.
Summary:
This fixes https://code.google.com/p/address-sanitizer/issues/detail?id=399
(sanitizers crash with empty suppression files).

Reviewers: kcc

Subscribers: llvm-commits

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

llvm-svn: 242594
2015-07-17 23:50:08 +00:00
Evgeniy Stepanov 856b11199f [asan] Fix SanitizerCommon.PthreadDestructorIterations test on Android L.
On Android L, TSD destructors run 8 times instead of 4.
Back to 4 times on the current master branch (as well as on K).

llvm-svn: 240992
2015-06-29 20:28:55 +00:00
Evgeniy Stepanov 2f58bb6a34 [asan] Disable glibc-specific code chunk on Android.
Fixes quarantine_size_mb.cc test on the Android bot.

llvm-svn: 240854
2015-06-26 23:39:23 +00:00
Evgeniy Stepanov e33f64f682 [asan] Fix Android build for API >= 21.
/code/llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc:971:8: error: address of function 'dl_iterate_phdr' will always evaluate to 'true' [-Werror,-Wpointer-bool-conversion]
  if (!dl_iterate_phdr)
      ~^~~~~~~~~~~~~~~
/code/llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc:971:8: note: prefix with the address-of operator to silence this warning
  if (!dl_iterate_phdr)
       ^
       &

llvm-svn: 239321
2015-06-08 18:15:52 +00:00
Yury Gribov c019a57099 [ASan] Make binary name reader cross-platform.
Differential Revision: http://reviews.llvm.org/D10213

llvm-svn: 239020
2015-06-04 07:29:43 +00:00
Evgeniy Stepanov 6153377219 [asan] Fall back to /proc/$PID/maps on Android L.
dl_iterate_phdr is somewhat broken in L (see the code for details).
We add runtime OS version detection and fallback to /proc/maps on L or earlier.
This fixes a number of ASan tests on L.

llvm-svn: 236628
2015-05-06 18:55:31 +00:00
Sagar Thakur 26f165b04e [ASan][MIPS] Fix null_deref.cc test on MIPS64
Symbol for pc used in ucontext->uc_mcontext was wrong.

Reviewers: dsanders, kcc, samsonov
Subscribers: llvm-commits, mohit.bhakkad, jaydeep
Differential Revision: http://reviews.llvm.org/D9246

llvm-svn: 236572
2015-05-06 06:53:09 +00:00