summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc
Commit message (Collapse)AuthorAgeFilesLines
* compiler-rt: Rename .cc file in lib/sanitizer_common to .cppNico Weber2019-07-311-2106/+0
| | | | | | | | | | | See https://reviews.llvm.org/D58620 for discussion, and for the commands I ran. In addition I also ran for f in $(svn diff | diffstat | grep .cc | cut -f 2 -d ' '); do rg $f . ; done and manually updated (many) references to renamed files found by that. llvm-svn: 367463
* [Sanitizer][ASAN][MSAN] Fix infinite recursion on FreeBSDAlexander Richardson2019-07-311-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: MSAN was broken on FreeBSD by https://reviews.llvm.org/D55703: after this change accesses to the key variable call __tls_get_addr, which is intercepted. The interceptor then calls GetCurrentThread which calls MsanTSDGet which again calls __tls_get_addr, etc... Using the default implementation in the SANITIZER_FREEBSD case fixes MSAN for me. I then applied the same change to ASAN (introduced in https://reviews.llvm.org/D55596) but that did not work yet. In the ASAN case, we get infinite recursion again during initialization, this time because calling pthread_key_create() early on results in infinite recursion. pthread_key_create() calls sysctlbyname() which is intercepted but COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED returns true, so the interceptor calls internal_sysctlbyname() which then ends up calling the interceptor again. I fixed this issue by using dlsym() to get the libc version of sysctlbyname() instead. This fixes https://llvm.org/PR40761 Reviewers: vitalybuka, krytarowski, devnexen, dim, bsdjhb, #sanitizers, MaskRay Reviewed By: MaskRay Subscribers: MaskRay, emaste, kubamracek, jfb, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D65221 llvm-svn: 367442
* SanitizerCommon: 64-bit SPARC/Linux portVitaly Buka2019-03-121-0/+2
| | | | | | | | | | | | | | | | | | | Summary: This patch contains the bits required to make the common 32-bit allocator work on SPARC64/Linux. Patch by Eric Botcazou. Reviewers: #sanitizers, vitalybuka Reviewed By: #sanitizers, vitalybuka Subscribers: krytarowski, vitalybuka, ro, jyknight, kubamracek, fedor.sergeev, jdoerfert, llvm-commits, #sanitizers Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D58432 llvm-svn: 355978
* SanitizerCommon: fixes for unwinding & backtrace on SPARCVitaly Buka2019-03-121-19/+28
| | | | | | | | | | | | | | | | | | | Summary: This patch contains various fixes for the unwinding and backtrace machinery on the SPARC, which doesn't work correctly in various cases. It was tested with GCC on SPARC/Solaris and SPARC/Linux. Patch by Eric Botcazou. Reviewers: #sanitizers, vitalybuka Reviewed By: #sanitizers, vitalybuka Subscribers: jrtc27, delcypher, vitalybuka, ro, jyknight, kubamracek, fedor.sergeev, jdoerfert, llvm-commits, #sanitizers Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D58431 llvm-svn: 355965
* Remove esan.Nico Weber2019-03-111-24/+0
| | | | | | | | | | | It hasn't seen active development in years, and it hasn't reached a state where it was useful. Remove the code until someone is interested in working on it again. Differential Revision: https://reviews.llvm.org/D59133 llvm-svn: 355862
* Revert "Revert "[sanitizers] Restore internal_readlink for x32""H.J. Lu2019-02-281-1/+1
| | | | | | | | | This reverts revision 354601 and disables ReadBinaryNameCached check on Windows since Windows has no working ReadBinaryName. Differential Revision: https://reviews.llvm.org/D58788 llvm-svn: 355129
* Revert "[sanitizers] Restore internal_readlink for x32"Matt Morehouse2019-02-211-1/+1
| | | | | | This reverts r354451 since it broke the Windows sanitizer bot. llvm-svn: 354601
* [sanitizers] Restore internal_readlink for x32H.J. Lu2019-02-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | r316591 has @@ -389,13 +383,11 @@ uptr internal_dup2(int oldfd, int newfd) { } uptr internal_readlink(const char *path, char *buf, uptr bufsize) { -#if SANITIZER_NETBSD - return internal_syscall_ptr(SYSCALL(readlink), path, buf, bufsize); -#elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS +#if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS return internal_syscall(SYSCALL(readlinkat), AT_FDCWD, (uptr)path, (uptr)buf, bufsize); #else - return internal_syscall(SYSCALL(readlink), (uptr)path, (uptr)buf, bufsize); + return internal_syscall_ptr(SYSCALL(readlink), path, buf, bufsize); #endif } which dropped the (uptr) cast and broke x32. This patch puts back the (uptr) cast to restore x32 and fixes: https://bugs.llvm.org/show_bug.cgi?id=40783 Differential Revision: https://reviews.llvm.org/D58413 llvm-svn: 354451
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [sanitizer] Move android's GetPageSize to a header (NFC)Evgeniy Stepanov2019-01-121-4/+3
| | | | | | | No need to pay function call overhead for a function that returns a constant. llvm-svn: 350983
* [asan] Support running without /procEvgeniy Stepanov2019-01-081-0/+4
| | | | | | | | | | | | | | | | | | Summary: This patch lets ASan run when /proc is not accessible (ex. not mounted yet). It includes a special test-only flag that emulates this condition in an unpriviledged process. This only matters on Linux, where /proc is necessary to enumerate virtual memory mappings. Reviewers: vitalybuka, pcc, krytarowski Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D56141 llvm-svn: 350590
* Revert "[asan] Support running without /proc.", +1Evgeniy Stepanov2018-12-281-4/+0
| | | | | | | | | Revert r350104 "[asan] Fix build on windows." Revert r350101 "[asan] Support running without /proc." These changes break Mac build, too. llvm-svn: 350112
* [asan] Support running without /proc.Evgeniy Stepanov2018-12-271-0/+4
| | | | | | | | | | | | | | | | | | Summary: This patch lets ASan run when /proc is not accessible (ex. not mounted yet). It includes a special test-only flag that emulates this condition in an unpriviledged process. This only matters on Linux, where /proc is necessary to enumerate virtual memory mappings. Reviewers: pcc, vitalybuka Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D55874 llvm-svn: 350101
* [xray] Detect MPROTECT and error out when it's enabled (on NetBSD)Michal Gorny2018-12-231-0/+24
| | | | | | | | | | Add a CheckMPROTECT() routine to detect when pax MPROTECT is enabled on NetBSD, and error xray out when it is. The solution is adapted from existing CheckASLR(). Differential Revision: https://reviews.llvm.org/D56049 llvm-svn: 350030
* [sanitizer] Support running without fd 0,1,2.Evgeniy Stepanov2018-12-201-0/+4
| | | | | | | | | | | | | | | | | | | Summary: Support running with no open file descriptors (as may happen to "init" process on linux). * Remove a check that writing to stderr succeeds. * When opening a file (ex. for log_path option), dup the new fd out of [0, 2] range to avoid confusing the program. (2nd attempt, this time without the sanitizer_rtems change) Reviewers: pcc, vitalybuka Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D55801 llvm-svn: 349817
* Revert "[sanitizer] Support running without fd 0,1,2."Ilya Biryukov2018-12-201-4/+0
| | | | | | | | This reverts commit r349699. Reason: the commit breaks compilation of sanitizer_rtems.cc when building for RTEMS. llvm-svn: 349745
* [sanitizer] Support running without fd 0,1,2.Evgeniy Stepanov2018-12-191-0/+4
| | | | | | | | | | | | | | | | | Summary: Support running with no open file descriptors (as may happen to "init" process on linux). * Remove a check that writing to stderr succeeds. * When opening a file (ex. for log_path option), dup the new fd out of [0, 2] range to avoid confusing the program. Reviewers: pcc, vitalybuka Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D55801 llvm-svn: 349699
* [sanitizer] Fix nolibc internal_sleepFangrui Song2018-12-141-1/+1
| | | | | | | | | | | | Reviewers: kubamracek, vitalybuka Reviewed By: vitalybuka Subscribers: delcypher, llvm-commits, #sanitizers Differential Revision: https://reviews.llvm.org/D55692 llvm-svn: 349134
* Unbreak build due to style.David Carlier2018-12-041-1/+2
| | | | llvm-svn: 348295
* [Sanitizer] intercept part of sysctl ApiDavid Carlier2018-12-041-1/+9
| | | | | | | | | | | | | - Distringuish what FreeBSD/NetBSD can and NetBSD specifics. - Fixing page size value collection. Reviewers: krytarowski, vitalybuka Reviewed By: krytarowski Differential Revision: https://reviews.llvm.org/D55265 llvm-svn: 348293
* [sanitizer] Return headed to fix build after r346258Vitaly Buka2018-11-061-0/+1
| | | | llvm-svn: 346270
* [sanitizer] Use "fast mmap" kernel flag for shadow memory on macOS 10.13.4+Kuba Mracek2018-11-061-0/+4
| | | | | | | | This speeds up process startup and teardown and also reduces lock contention when running multiple ASanified/TSanified processes simultaneously. Should greatly improve lit testing time. Differential Revision: https://reviews.llvm.org/D48445 llvm-svn: 346262
* [sanitizer] Fix nolibc unittests broken by r346215Vitaly Buka2018-11-061-30/+1
| | | | | | | | Subscribers: kubamracek, krytarowski, fedor.sergeev, llvm-commits Differential Revision: https://reviews.llvm.org/D54163 llvm-svn: 346258
* [sanitizer] Add char **GetEnviron() on all other platformsVitaly Buka2018-11-061-3/+7
| | | | | | | | Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D54165 llvm-svn: 346257
* [sanitizer] Use AT_EXECFN in ReExec() if availableBenjamin Kramer2018-11-061-0/+4
| | | | | | | | | | execve("/proc/self/exe") will not work if the binary relies on $EXEC_ORIGIN in an rpath. Query AT_EXECFN instead, which will give the same string that the current binary was exec'd with. Differential Revision: https://reviews.llvm.org/D54113 llvm-svn: 346215
* Fix build on sparc64-linux-gnu.Martin Liska2018-11-051-2/+2
| | | | | | Differential Revision: https://reviews.llvm.org/D54030 llvm-svn: 346129
* [PowerPC]Disable randomized address space on Linux ppc64leLei Huang2018-11-021-0/+11
| | | | | | | | | | | Recent versions of Ubuntu (17.04 and 18.04) on PowerPC have introduced changes to Address Space Layout Randomization (ASLR) that is causing 500+ sanitizer failures. This patch disables ASLR when running the sanitizers on PowerPC 64bit LE. Differential Revision: https://reviews.llvm.org/D52900 llvm-svn: 346030
* [Sanitizer] openbsd does not have sysctlbyname callDavid Carlier2018-10-211-5/+2
| | | | | | | | | | | | Enabling only for FreeBSD. Reviewers: krytarowski, vitalybuka Reviewed By: krytarowski Differential Revision: https://reviews.llvm.org/D53413 llvm-svn: 344876
* Remove remnant code of using indirect syscall on NetBSDKamil Rytarowski2018-10-081-25/+24
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: The NetBSD version of internal routines no longer call the indirect syscall interfaces, as these functions were switched to lib calls. Remove the remnant code complication that is no longer needed after this change. Remove the variations of internal_syscall, as they were NetBSD specific. No functional change intended. Reviewers: vitalybuka, joerg, javed.absar Reviewed By: vitalybuka Subscribers: kubamracek, fedor.sergeev, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D52955 llvm-svn: 343988
* [Sanitizer] fix internal_sysctlbyname build for FreeBSD.David Carlier2018-10-081-1/+1
| | | | llvm-svn: 343964
* Introduce internal_sysctlbyname in place of sysctlbynameKamil Rytarowski2018-10-051-1/+11
| | | | | | | | | | | | | | | | | | Summary: This change will allow to install sysctlbyname() interceptors more easily in sanitizers. Reviewers: vitalybuka, joerg Reviewed By: vitalybuka Subscribers: kubamracek, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D52793 llvm-svn: 343840
* [Esan] Port cache frag to FreeBSDDavid Carlier2018-10-041-2/+12
| | | | | | | | | | | | Data involving struct accesses accounting work (plan to support only efficiency-cache-frag flag in the frontend side). Reviewers: krytarowski, vitalybuka, jfb Reviewed By : vitalybuka Differential Revision: https://reviews.llvm.org/D52608 llvm-svn: 343812
* Switch syscall(2)/__syscall(2) calls to libc calls on NetBSDKamil Rytarowski2018-10-011-51/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: When possible, switch syscall(2)/__syscall(2) calls to direct calls of internal libc symbols. Add a new function to detect address of a libc symbol of a function that could be intercepted. With the address detector in GetRealLibcAddress(), an optional interceptor of libc call will be bypassed. The original approach with syscall(2)/__syscall(2) wasn't portable across supported ABIs and CPU architectures. The indirect syscall interface is also a candidate for removal in future revisions of NetBSD, as the C language ABI is not a good domain for serialization of arbitrary functions arguments. Switch the following functions to libc calls: - internal_mmap() - internal_munmap() - internal_mprotect() - internal_close() - internal_open() - internal_read() - internal_write() - internal_ftruncate() - internal_stat() - internal_lstat() - internal_fstat() - internal_dup2() - internal_readlink() - internal_unlink() - internal_rename() - internal_sched_yield() - internal__exit() - internal_sleep() - internal_execve() - NanoTime() - internal_clock_gettime() - internal_waitpid() - internal_getpid() - internal_getppid() - internal_getdents() - internal_lseek() - internal_sigaltstack() - internal_fork() - internal_sigprocmask() - internal_sysctl() - internal_sigemptyset() - internal_sigfillset() - GetTid() - TgKill() This revision leaves room for refactoring in subsequent commits. Reviewers: vitalybuka, kcc, joerg Reviewed By: vitalybuka Subscribers: mgorny, fedor.sergeev, jfb, loverszhaokai, devnexen, kubamracek, llvm-commits, ro, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D51419 llvm-svn: 343523
* [sanitizer] AndroidGetApiLevel for static executables.Evgeniy Stepanov2018-09-261-1/+14
| | | | | | | | | | A version of AndroidGetApiLevel for static executables that is completely compile-time. The generic version uses dl_iterate_phdr which, even though it works in static executables, crashes if called before libc is initialized. llvm-svn: 343153
* Fix buildbot testDavid Carlier2018-09-021-1/+1
| | | | llvm-svn: 341286
* [Sanitizer] openbsd build fixDavid Carlier2018-09-021-0/+6
| | | | | | | | | | | | sysctl has a different signature under OpenBSD Reviewers: krytarowski Reviewed By: krytarowski Differential Revision: https://reviews.llvm.org/D51572 llvm-svn: 341285
* Improve portability of internal_sysctl()Kamil Rytarowski2018-08-311-1/+1
| | | | | | Add an explicit cast from uptr to size_t to prevent potential type mismatch. llvm-svn: 341183
* Add internal_sysctl() used by FreeBSD, NetBSD, OpenBSD and MacOSXKamil Rytarowski2018-08-311-6/+14
| | | | | | | | | | | | | | | | | | | | | | | Summary: Switch local sysctl(2) calls to internal_sysctl(). This is a preparation for introduction of interceptors for the sysctl*() family of functions and switching `internal_sysctl*()` to libc calls bypassing interceptors. No functional change intended with this revision. Reviewers: vitalybuka, joerg, kcc Reviewed By: vitalybuka Subscribers: kubamracek, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D51425 llvm-svn: 341181
* [sanitizer] Use private futex operations for BlockingMutexKostya Kortchinsky2018-08-201-2/+6
| | | | | | | | | | | | | | | | | | Summary: Use `FUTEX_PRIVATE_FLAG` in conjunction with the wait & wake operations employed by `BlockingMutex`. As far as I can tell, the mutexes are process-private, and there is an actual performance benefit at employing the private operations. There should be no downside to switching to it. Reviewers: eugenis, alekseyshl, dvyukov Reviewed By: dvyukov Subscribers: kubamracek, delcypher, #sanitizers, llvm-commits Differential Revision: https://reviews.llvm.org/D50910 llvm-svn: 340178
* [Sanitizer] Fix build openbsdDavid Carlier2018-08-161-1/+10
| | | | | | | | | | | | | | - The alternative syscall exists only on FreeBSD. - Adding OpenBSD's equivalent and while at it other remaining oses ones. Reviewers: vitalybuka, krytarowsky, hiraditya Reviewed By: hiraditya Differential Revision: https://reviews.llvm.org/D50760 llvm-svn: 339886
* Reland "SafeStack: Delay thread stack clean-up""Vlad Tsyrklevich2018-08-141-0/+8
| | | | | | | | | | This relands commit r339405 (reverted in commit r339408.) The original revert was due to tests failing on a darwin buildbot; however, after looking at the affected code more I realized that the Darwin safestack support has always been broken and disabled it in r339719. This relands the original commit. llvm-svn: 339723
* Revert "SafeStack: Delay thread stack clean-up"Vlad Tsyrklevich2018-08-101-8/+0
| | | | | | | | | This reverts commit r339405, it's failing on Darwin buildbots because it doesn't seem to have a tgkill/thr_kill2 interface. It has a __pthread_kill() syscall, but that relies on having a handle to the thread's port which is not equivalent to it's tid. llvm-svn: 339408
* SafeStack: Delay thread stack clean-upVlad Tsyrklevich2018-08-091-0/+8
| | | | | | | | | | | | | | | | | | Summary: glibc can call SafeStack instrumented code even after the last pthread data destructor has run. Delay cleaning-up unsafe stacks for threads until the thread is dead by having future threads clean-up prior threads stacks. Reviewers: pcc, eugenis Reviewed By: eugenis Subscribers: cryptoad, eugenis, kubamracek, delcypher, llvm-commits, #sanitizers, kcc Differential Revision: https://reviews.llvm.org/D50406 llvm-svn: 339405
* [sanitizer] Remove rsp from the clobber list in internal_cloneKostya Kortchinsky2018-08-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: When compiling with WERROR=ON, a new fatal warning started popping up recently (due to -Werror,-Winline-asm): ``` .../lib/sanitizer_common/sanitizer_linux.cc:1214:24: error: inline asm clobber list contains reserved registers: RSP [-Werror,-Winline-asm] "syscall\n" ^ <inline asm>:1:1: note: instantiated into assembly here syscall ^ .../lib/sanitizer_common/sanitizer_linux.cc:1214:24: note: Reserved registers on the clobber list may not be preserved across the asm statement, and clobbering them may lead to undefined behaviour. "syscall\n" ^ <inline asm>:1:1: note: instantiated into assembly here syscall ^ ``` Removing `rsp` from the clobber list makes the warning go away, and does not appear to have a functional impact. If there is another way to solve this, let me know. Reviewers: eugenis, vitalybuka Reviewed By: eugenis Subscribers: kubamracek, delcypher, llvm-commits, #sanitizers Differential Revision: https://reviews.llvm.org/D50519 llvm-svn: 339370
* Enable getentropy for FreeBSD 12David Carlier2018-08-091-1/+6
| | | | | | | | | | | | As for Linux with its getrandom's syscall, giving the possibility to fill buffer with native call for good quality but falling back to /dev/urandom in worst case similarly. Reviewers: vitalybuka, krytarowski Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D48804 llvm-svn: 339318
* [sanitizer] Include signal.h instead of sys/signal.hFangrui Song2018-07-261-5/+1
| | | | llvm-svn: 338004
* [sanitizer] Cleanup ReadFileToVector and ReadFileToBufferVitaly Buka2018-06-061-1/+1
| | | | | | | | | | | | | | | Summary: Added unit-test. Fixed behavior of max_len argument. Call read syscall with all available buffer, not just a page. Reviewers: eugenis Subscribers: kubamracek, mgorny, llvm-commits Differential Revision: https://reviews.llvm.org/D46618 llvm-svn: 334130
* Introduce CheckASLR() in sanitizersKamil Rytarowski2018-06-051-0/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: At least the ASan, MSan, TSan sanitizers require disabled ASLR on a NetBSD. Introduce a generic CheckASLR() routine, that implements a check for the current process. This flag depends on the global or per-process settings. There is no simple way to disable ASLR in the build process from the level of a sanitizer or during the runtime execution. With ASLR enabled sanitizers that operate over the process virtual address space can misbehave usually breaking with cryptic messages. This check is dummy for !NetBSD. Sponsored by <The NetBSD Foundation> Reviewers: vitalybuka, joerg Reviewed By: vitalybuka Subscribers: cryptoad, kubamracek, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D47442 llvm-svn: 333985
* Fix internal_mmap() on 32-bit NetBSD platformsKamil Rytarowski2018-05-231-1/+1
| | | | | | | There is need to use internal_syscall64() instead of internal_syscall_ptr(). The offset argument of type off_t is always 64-bit. llvm-svn: 333075
* [sanitizer] Fix typo in commentVitaly Buka2018-05-101-1/+1
| | | | llvm-svn: 331956
OpenPOWER on IntegriCloud