summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc
Commit message (Collapse)AuthorAgeFilesLines
...
* [sanitizer] Pair atomic acquire with release in BlockingMutex::UnlockAlex Shlyapnikov2017-05-251-1/+1
| | | | | | | | | | | | | | | Summary: Dmitry, seeking your expertise. I believe, the proper way to implement Lock/Unlock here would be to use acquire/release semantics. Am I missing something? Reviewers: dvyukov Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D33521 llvm-svn: 303869
* [compiler-rt] Replace ifs with switch statement in IsHandledDeadlySignalVitaly Buka2017-05-181-9/+13
| | | | | | | | | | Reviewers: eugenis Subscribers: kubamracek, llvm-commits, dberris Differential Revision: https://reviews.llvm.org/D33158 llvm-svn: 303392
* [sanitizer] Introduce tid_t as a typedef for OS-provided thread IDsKuba Mracek2017-04-171-1/+1
| | | | | | | | We seem to assume that OS-provided thread IDs are either uptr or int, neither of which is true on Darwin. This introduces a tid_t type, which holds a OS-provided thread ID (gettid on Linux, pthread_threadid_np on Darwin, pthread_self on FreeBSD). Differential Revision: https://reviews.llvm.org/D31774 llvm-svn: 300473
* Reapply "Enable LSan for arm Linux"Maxim Ostapenko2017-04-111-0/+66
| | | | | | This patch reapplies r299923 with typo fixed in BLX macros. llvm-svn: 299948
* Revert r299923, it doesn't build in bootstrap builds.Nico Weber2017-04-111-66/+0
| | | | | | | | | | | | | | | FAILED: lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.arm.dir/sanitizer_linux.cc.o lib/sanitizer_common/sanitizer_linux.cc:1340:24: error: invalid instruction BLX(ip) ^ lib/sanitizer_common/sanitizer_linux.cc:1313:19: note: expanded from macro 'BLX' # define BLX(R) "mov lr, pc; bx" #R "\n" ^ <inline asm>:6:13: note: instantiated into assembly here mov lr, pc; bxip ^~~~ llvm-svn: 299943
* [lsan] Enable LSan for arm LinuxMaxim Ostapenko2017-04-111-0/+66
| | | | | | | | This patch enables LSan for arm Linux. Differential Revision: https://reviews.llvm.org/D29586 llvm-svn: 299923
* [PPC64, Sanitizers] Proper stack frame for the thread spawned in internal_cloneAlex Shlyapnikov2017-04-101-24/+51
| | | | | | | | | | | | | | | Summary: Set up the proper stack frame for the thread spawned in internal_clone, the current code does not follow ABI (and causes SEGV trying to use this malformed frame). Reviewers: wschmidt Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D31555 llvm-svn: 299896
* Bypass potential libc's sysconf interceptorsAlex Shlyapnikov2017-03-231-0/+16
| | | | | | | | | | | | | | | | | | Summary: sysconf(_SC_PAGESIZE) is called very early during sanitizer init and any instrumented code (sysconf() wrapper/interceptor will likely be instrumented) calling back to sanitizer before init is done will most surely crash. 2nd attempt, now with glibc version checks (D31092 was reverted). Reviewers: eugenis Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D31221 llvm-svn: 298613
* Revert "Bypass potential libc's sysconf wrappers for sysconf(_SC_PAGESIZE) call"Vitaly Buka2017-03-211-3/+0
| | | | | | | | Bot can't find <sys/auxv.h> This reverts commit r298305. llvm-svn: 298343
* Bypass potential libc's sysconf wrappers for sysconf(_SC_PAGESIZE) callAlex Shlyapnikov2017-03-201-0/+3
| | | | | | | | | | | | | | | Summary: sysconf(_SC_PAGESIZE) is called very early, during sanitizer init and any instrumented code (a wrapper/interceptor will likely be instrumented) calling back to sanitizer before init is done will most surely crash. Reviewers: eugenis Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D31092 llvm-svn: 298305
* After rL297370 and rL297383, instead of a platform check, explicitlyDimitry Andric2017-03-141-1/+1
| | | | | | | | check for the existence of RTLD_DEEPBIND, since this constant is only supported for glibc >= 2.3.4. This fixes builds for FreeBSD and other platforms that do not have RTLD_DEEPBIND. llvm-svn: 297763
* [asan] Split SIGSEGV / SIGBUS handling so we can handle only one of them and ↵Filipe Cabecinhas2017-03-131-1/+3
| | | | | | | | | | | | | | not the other. Summary: This is useful in some platforms where one of these signals is special. Reviewers: kubamracek, kcc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D30783 llvm-svn: 297665
* [sanitizer] Fix android buildbots after r297370Maxim Ostapenko2017-03-091-0/+2
| | | | llvm-svn: 297383
* [sanitizer] Bail out with warning if user dlopens shared library with ↵Maxim Ostapenko2017-03-091-0/+13
| | | | | | | | | | | | RTLD_DEEPBIND flag People keep hitting on spurious failures in malloc/free routines when using sanitizers with shared libraries dlopened with RTLD_DEEPBIND (see https://github.com/google/sanitizers/issues/611 for details). Let's check for this flag and bail out with warning message instead of failing in random places. Differential Revision: https://reviews.llvm.org/D30504 llvm-svn: 297370
* [lsan] Renable LSan for x86 LinuxMaxim Ostapenko2017-01-311-0/+65
| | | | | | | | | The missed clang part was committed at https://reviews.llvm.org/rL293609 thus we can reenable LSan for x86 Linux. Differential Revision: https://reviews.llvm.org/D28609 llvm-svn: 293610
* Revert "[lsan] Enable LSan for x86 Linux."Evgeniy Stepanov2017-01-231-65/+0
| | | | | | | Breaks tests on i686/Linux due to missing clang driver support: error: unsupported option '-fsanitize=leak' for target 'i386-unknown-linux-gnu' llvm-svn: 292844
* [lsan] Enable LSan for x86 Linux.Maxim Ostapenko2017-01-231-0/+65
| | | | | | | | | | | | | People keep asking LSan to be available on 32 bit targets (e.g. https://github.com/google/sanitizers/issues/403) despite the fact that false negative ratio might be huge (up to 85%). This happens for big real world applications that may contain random binary data (e.g. browser), but for smaller apps situation is not so terrible and LSan still might be useful. This patch adds initial support for x86 Linux (disabled by default), ARM32 is in TODO list. We used this patch (well, ported to GCC) on our 32 bit mobile emulators and it worked pretty fine thus I'm posting it here to initiate further discussion. Differential Revision: https://reviews.llvm.org/D28609 llvm-svn: 292775
* [sanitizer] Add a 'print_module_map' flag which prints modules with UUIDs on ↵Kuba Mracek2017-01-061-0/+2
| | | | | | | | | | Darwin This patch add a new sanitizer flag, print_module_map, which enables printing a module map when the process exits, or after each report (for TSan). The output format is very similar to what Crash Reporter produces on Darwin (e.g. the format of module UUIDs). This enables users to use the existing symbol servers to offline symbolicate and aggregate reports. Differential Revision: https://reviews.llvm.org/D27400 llvm-svn: 291277
* [asan] Add a "dump_registers" flag to print out CPU registers after a SIGSEGVKuba Mracek2016-11-261-0/+4
| | | | | | | | This patch prints out all CPU registers after a SIGSEGV. These are available in the signal handler context. Only implemented for Darwin. Can be turned off with the dump_registers flag. Differential Revision: https://reviews.llvm.org/D11365 llvm-svn: 287957
* tsan: always define SANITIZER_GODmitry Vyukov2016-10-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | Currently we either define SANITIZER_GO for Go or don't define it at all for C++. This works fine with preprocessor (ifdef/ifndef/defined), but does not work for C++ if statements (e.g. if (SANITIZER_GO) {...}). Also this is different from majority of SANITIZER_FOO macros which are always defined to either 0 or 1. Always define SANITIZER_GO to either 0 or 1. This allows to use SANITIZER_GO in expressions and in flag default values. Also remove kGoMode and kCppMode, which were meant to be used in expressions, but they are not defined in sanitizer_common code, so SANITIZER_GO become prevalent. Also convert some preprocessor checks to C++ if's or ternary expressions. Majority of this change is done mechanically with: sed "s#ifdef SANITIZER_GO#if SANITIZER_GO#g" sed "s#ifndef SANITIZER_GO#if \!SANITIZER_GO#g" sed "s#defined(SANITIZER_GO)#SANITIZER_GO#g" llvm-svn: 285443
* [ESan][MIPS] Adds support for MIPS64Sagar Thakur2016-10-061-2/+2
| | | | | | | | | With this patch 12 out of 13 tests are passing. Reviewed by zhaoqin. Differential: D23799 llvm-svn: 283435
* [asan] Reapply: Switch to using dynamic shadow offset on iOSAnna Zaks2016-10-051-0/+5
| | | | | | | | The VM layout is not stable between iOS version releases, so switch to dynamic shadow offset. Differential Revision: https://reviews.llvm.org/D25218 llvm-svn: 283375
* Revert "[asan] Switch to using dynamic shadow offset on iOS"Anna Zaks2016-10-051-5/+0
| | | | | | | | This reverts commit b2af965b7924ad793b313996a96633bb72daf629. Revert as these changes broke a Chromium buildbot. llvm-svn: 283349
* [asan] Switch to using dynamic shadow offset on iOSAnna Zaks2016-10-041-0/+5
| | | | | | | | The VM layout is not stable between iOS version releases, so switch to dynamic shadow offset. Differential Revision: https://reviews.llvm.org/D25218 llvm-svn: 283240
* Revert "[ESan][MIPS] Adds support for MIPS64"Qin Zhao2016-09-081-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This reverts commit 62b3eecdbe72af0255f0639b0446087a47efbf48. (D23799) The CL cause 13 ESan test failure on x86_64: Failing Tests (13): EfficiencySanitizer-x86_64 :: TestCases/large-stack-linux.c EfficiencySanitizer-x86_64 :: TestCases/libc-intercept.c EfficiencySanitizer-x86_64 :: TestCases/mmap-shadow-conflict.c EfficiencySanitizer-x86_64 :: TestCases/struct-simple.cpp EfficiencySanitizer-x86_64 :: TestCases/verbose-simple.c EfficiencySanitizer-x86_64 :: TestCases/workingset-early-fault.c EfficiencySanitizer-x86_64 :: TestCases/workingset-memset.cpp EfficiencySanitizer-x86_64 :: TestCases/workingset-midreport.cpp EfficiencySanitizer-x86_64 :: TestCases/workingset-samples.cpp EfficiencySanitizer-x86_64 :: TestCases/workingset-signal-posix.cpp EfficiencySanitizer-x86_64 :: TestCases/workingset-simple.cpp EfficiencySanitizer-x86_64 :: Unit/circular_buffer.cpp EfficiencySanitizer-x86_64 :: Unit/hashtable.cpp Unexpected Failures: 13 Reviewers: bruening, slthakur Subscribers: sdardis, kubabrecka, beanz Differential Revision: https://reviews.llvm.org/D24350 llvm-svn: 280954
* [ESan][MIPS] Adds support for MIPS64Sagar Thakur2016-09-071-2/+2
| | | | | | | | | | | | | | | With this patch 10 out of 13 tests are passing. Following is the list of failing tests: struct-simple.cpp workingset-signal-posix.cpp mmap-shadow-conflict.c Reviewed by bruening Differential: D23799 llvm-svn: 280795
* [asan] Remove zero FSR check on ARM.Evgeniy Stepanov2016-07-261-4/+0
| | | | | | | | | | The kernel on Nexus 5X returns error_code in ucontext which has correct FSR_WRITE flag, but empty (zero) abort type field. Removing the checks means that we will report all SEGVs as READ on very old kernels, but will properly distinguish READ vs WRITE on moderately old ones. llvm-svn: 276803
* [asan] Hardcode page size 4096 on Android.Evgeniy Stepanov2016-07-261-2/+3
| | | | | | | EXEC_PAGESIZE lies. sysconf() is broken in .preinit_array. llvm-svn: 276802
* [esan|wset] Ensure SIGSEGV is not blockedDerek Bruening2016-07-061-0/+14
| | | | | | | | | | | | | | | | | | | | Summary: Adds interception of sigprocmask and pthread_sigmask to esan so that the working set tool can prevent SIGSEGV from being blocked. A blocked SIGSEGV results in crashes due to our lazy shadow page allocation scheme. Adds new sanitizer helper functions internal_sigemptyset and internal_sigismember. Adds a test to workingset-signal-posix.cpp. Reviewers: aizatsky Subscribers: vitalybuka, zhaoqin, kcc, eugenis, llvm-commits, kubabrecka Differential Revision: http://reviews.llvm.org/D22063 llvm-svn: 274672
* [sanitizer] Handle null in internal_sigaction_syscallDerek Bruening2016-07-061-0/+2
| | | | | | | | | | | | | | Summary: Adds support for nullptr as the action parameter to internal_sigaction_syscall(). Reviewers: aizatsky Subscribers: kubabrecka, vitalybuka, zhaoqin, kcc, eugenis, llvm-commits Differential Revision: http://reviews.llvm.org/D22061 llvm-svn: 274665
* [sanitizer][esan] Add internal_sigaction_syscallDerek Bruening2016-06-141-1/+25
| | | | | | | | | | | | | | | | | | | | | | | Summary: Adds a version of sigaction that uses a raw system call, to avoid circular dependencies and support calling sigaction prior to setting up interceptors. The new sigaction relies on an assembly sigreturn routine for its restorer, which is Linux x86_64-only for now. Uses the new sigaction to initialize the working set tool's shadow fault handler prior to libc interceptor being set up. This is required to support instrumentation invoked during interceptor setup, which happens with an instrumented tcmalloc or other allocator compiled with esan. Adds a test that emulates an instrumented allocator. Reviewers: aizatsky Subscribers: vitalybuka, tberghammer, zhaoqin, danalbert, kcc, srhines, eugenis, llvm-commits, kubabrecka Differential Revision: http://reviews.llvm.org/D21083 llvm-svn: 272676
* Revert r272591, http://lab.llvm.org:8011/builders/clang-x64-ninja-win7 has ↵Nico Weber2016-06-141-25/+1
| | | | | | been broken since this landed. llvm-svn: 272659
* [sanitizer][esan] Add internal_sigaction_syscallDerek Bruening2016-06-131-1/+25
| | | | | | | | | | | | | | | | | | | | | | | Summary: Adds a version of sigaction that uses a raw system call, to avoid circular dependencies and support calling sigaction prior to setting up interceptors. The new sigaction relies on an assembly sigreturn routine for its restorer, which is Linux x86_64-only for now. Uses the new sigaction to initialize the working set tool's shadow fault handler prior to libc interceptor being set up. This is required to support instrumentation invoked during interceptor setup, which happens with an instrumented tcmalloc or other allocator compiled with esan. Adds a test that emulates an instrumented allocator. Reviewers: aizatsky Subscribers: vitalybuka, tberghammer, zhaoqin, danalbert, kcc, srhines, eugenis, llvm-commits, kubabrecka Differential Revision: http://reviews.llvm.org/D21083 llvm-svn: 272591
* Revert "[sanitizer][esan] Add internal_sigaction_syscall"Derek Bruening2016-06-131-25/+1
| | | | | | | | This reverts commit r272553. The iOS build fails to link. llvm-svn: 272557
* [sanitizer][esan] Add internal_sigaction_syscallDerek Bruening2016-06-131-1/+25
| | | | | | | | | | | | | | | | | | | | | | | Summary: Adds a version of sigaction that uses a raw system call, to avoid circular dependencies and support calling sigaction prior to setting up interceptors. The new sigaction relies on an assembly sigreturn routine for its restorer, which is Linux x86_64-only for now. Uses the new sigaction to initialize the working set tool's shadow fault handler prior to libc interceptor being set up. This is required to support instrumentation invoked during interceptor setup, which happens with an instrumented tcmalloc or other allocator compiled with esan. Adds a test that emulates an instrumented allocator. Reviewers: aizatsky Subscribers: vitalybuka, tberghammer, zhaoqin, danalbert, kcc, srhines, eugenis, llvm-commits, kubabrecka Differential Revision: http://reviews.llvm.org/D21083 llvm-svn: 272553
* [mips][sanitizer_common] Don't use `ld` in internal_clone() on 32-bit MIPS.Daniel Sanders2016-05-121-0/+10
| | | | | | | | | | | | | | | | | | | | | | | 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
* Fixup for r269288. SleepForSeconds is not available in nolibc builds, let's ↵Kuba Brecka2016-05-121-0/+9
| | | | | | add an internal_sleep. llvm-svn: 269296
* [sanitizers] [SystemZ] Introduce sanitizer_linux_s390.cc.Marcin Koscielnicki2016-04-151-26/+3
| | | | | | | | | 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
* Revert "[sanitizer] [SystemZ] Abort if the kernel might be vulnerable to ↵Marcin Koscielnicki2016-04-151-67/+0
| | | | | | | | CVE-2016-2143." This reverts commit r266297. llvm-svn: 266470
* [sanitizer] [SystemZ] Add/fix kernel and libc type definitions.Marcin Koscielnicki2016-04-141-0/+9
| | | | | | | | | | | 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
* [sanitizer] remove FreeBSD PS_STRINGS fallbackEd Maste2016-04-141-4/+5
| | | | | | | | | | | | 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
* [sanitizer] [SystemZ] Abort if the kernel might be vulnerable to CVE-2016-2143.Marcin Koscielnicki2016-04-141-0/+67
| | | | | | | | | | | | | | | | | | 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
* [sanitizer] [SystemZ] Implement internal_mmap.Marcin Koscielnicki2016-04-141-1/+26
| | | | | | | | | | 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
* [sanitizer] On OS X, verify that interceptors work and abort if not, take 2Kuba Brecka2016-03-171-4/+0
| | | | | | | | | | 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
* [ASAN] Add support for mips/mips64 androidMohit K. Bhakkad2016-03-161-0/+4
| | | | | | | | | | | | Patch by Duane Sand Reviewers: samsonov Subscribers: duanesand, jaydeep, sagar, llvm-commits, filcab. Differential Revision: http://reviews.llvm.org/D17883 llvm-svn: 263621
* [Sanitizer][MIPS] internal lstat and fstat for mips64Mohit K. Bhakkad2016-03-111-0/+16
| | | | | | | | | | Reviewers: dvyukov Subscribers: jaydeep, sagar, llvm-commits Differential Revision: http://reviews.llvm.org/D18078 llvm-svn: 263218
* Retrieve command line arguments and environment correctly on FreeBSDDimitry Andric2016-03-101-1/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [asan] Fix build on Windows and PowerPC.Evgeniy Stepanov2016-02-091-0/+1
| | | | llvm-svn: 260175
* [asan] Remove leftover debug print statement.Evgeniy Stepanov2016-02-081-1/+0
| | | | llvm-svn: 260165
* [asan] Implement SEGV read vs write detection for ARM and AArch64.Evgeniy Stepanov2016-02-081-5/+44
| | | | llvm-svn: 260163
OpenPOWER on IntegriCloud