summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common
AgeCommit message (Collapse)Author
2017-12-18[asan] Add interceptor for printf_chkMaxim Ostapenko
There could be a situation when a specific DSO was built with FORTIFY_SOURCE option. In case asan-ed binary link against that DSO, libasan can't handle the possible memory error because it does not have interceptors for spinrtf_chk, snprintf_chk, vprintf_chk, vsnprintf_chk, __fprintf_chk functions. Let's interceptors for them. Patch by Denis Khalikov. Differential Revision: https://reviews.llvm.org/D40951 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@320990 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-16[sanitizer] Define __sanitizer_clockid_t on FreeBSDKostya Kortchinsky
Summary: https://reviews.llvm.org/D41121 broke the FreeBSD build due to that type not being defined on FreeBSD. As far as I can tell, it is an int, but I do not have a way to test the change. Reviewers: alekseyshl, kparzysz Reviewed By: kparzysz Subscribers: kparzysz, emaste, kubamracek, krytarowski, #sanitizers, llvm-commits Differential Revision: https://reviews.llvm.org/D41325 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@320931 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-14[Sanitizers] Basic sanitizer Solaris support (PR 33274)Kamil Rytarowski
Summary: This is the first mostly working version of the Sanitizer port to 32-bit Solaris/x86. It is currently based on Solaris 11.4 Beta. This part was initially developed inside libsanitizer in the GCC tree and should apply to both. Subsequent parts will address changes to clang, the compiler-rt build system and testsuite. I'm not yet sure what the right patch granularity is: if it's profitable to split the patch up, I'd like to get guidance on how to do so. Most of the changes are probably straightforward with a few exceptions: * The Solaris syscall interface isn't stable, undocumented and can change within an OS release. The stable interface is the libc interface, which I'm using here, if possible using the internal _-prefixed names. * While the patch primarily target 32-bit x86, I've left a few sparc changes in. They cannot currently be used with clang due to a backend limitation, but have worked fine inside the gcc tree. * Some functions (e.g. largefile versions of functions like open64) only exist in 32-bit Solaris, so I've introduced a separate SANITIZER_SOLARIS32 to check for that. The patch (with the subsequent ones to be submitted shortly) was tested on i386-pc-solaris2.11. Only a few failures remain, some of them analyzed, some still TBD: AddressSanitizer-i386-sunos :: TestCases/Posix/concurrent_overflow.cc AddressSanitizer-i386-sunos :: TestCases/init-order-atexit.cc AddressSanitizer-i386-sunos :: TestCases/log-path_test.cc AddressSanitizer-i386-sunos :: TestCases/malloc-no-intercept.c AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/concurrent_overflow.cc AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/start-deactivated.cc AddressSanitizer-i386-sunos-dynamic :: TestCases/default_options.cc AddressSanitizer-i386-sunos-dynamic :: TestCases/init-order-atexit.cc AddressSanitizer-i386-sunos-dynamic :: TestCases/log-path_test.cc AddressSanitizer-i386-sunos-dynamic :: TestCases/malloc-no-intercept.c SanitizerCommon-Unit :: ./Sanitizer-i386-Test/MemoryMappingLayout.DumpListOfModules SanitizerCommon-Unit :: ./Sanitizer-i386-Test/SanitizerCommon.PthreadDestructorIterations Maybe this is good enough the get the ball rolling. Reviewers: kcc, alekseyshl Reviewed By: alekseyshl Subscribers: srhines, jyknight, kubamracek, krytarowski, fedor.sergeev, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40898 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@320740 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-14Set of corrections for MSan/NetBSDKamil Rytarowski
Summary: Changes: - Don't attempt to intercept GLIBC specific functions like __strtol_internal. This is required to stop intercepting it as we leak dlerror(3) for dlsym(3) that cannot manage to find a symbol. - Correct interception of fstatat(2). - Don't run a test for fgetgrent_r() that is missing on NetBSD. - Correct link_map location (offset) in Obj_Entry on x86_64 and i386. - Stop intercepting getpshared-like functions in pthread(3). This is feature is not enabled by default on NetBSD as it's unfinished. - Switch intercepting from UTMP to UTMPX functions. Sponsored by <The NetBSD Foundation> Reviewers: joerg, vitalybuka, eugenis, kcc Reviewed By: vitalybuka Subscribers: llvm-commits, srhines, kubamracek, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D41053 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@320663 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-14[sanitizer] Use MADV_FREE on Darwin/BSD to release pages to the OSKuba Mracek
MADV_DONTNEED on Linux actually mark the pages as free to be overwritten with zeroes, but on Darwin and BSD, it's just an advisory flag (the OS cannot discard the content). We should use MADV_FREE on Darwin and BSD. Differential Revision: https://reviews.llvm.org/D40666 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@320659 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-13[sanitizer] Introduce a vDSO aware timing functionKostya Kortchinsky
Summary: See D40657 & D40679 for previous versions of this patch & description. A couple of things were fixed here to have it not break some bots. Weak symbols can't be used with `SANITIZER_GO` so the previous version was breakin TsanGo. I set up some additional local tests and those pass now. I changed the workaround for the glibc vDSO issue: `__progname` is initialized after the vDSO and is actually public and of known type, unlike `__vdso_clock_gettime`. This works better, and with all compilers. The rest is the same. Reviewers: alekseyshl Reviewed By: alekseyshl Subscribers: srhines, kubamracek, krytarowski, llvm-commits, #sanitizers Differential Revision: https://reviews.llvm.org/D41121 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@320594 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-11[sanitizer] Revert rL320409Kostya Kortchinsky
Summary: D40679 broke a couple of builds, reverting while investigating. Reviewers: alekseyshl Reviewed By: alekseyshl Subscribers: srhines, kubamracek, krytarowski, llvm-commits, #sanitizers Differential Revision: https://reviews.llvm.org/D41088 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@320417 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-11[sanitizer] Introduce a vDSO aware time function, and use it in the ↵Kostya Kortchinsky
allocator [redo] Summary: Redo of D40657, which had the initial discussion. The initial code had to move into a libcdep file, and things had to be shuffled accordingly. `NanoTime` is a time sink when checking whether or not to release memory to the OS. While reducing the amount of calls to said function is in the works, another solution that was found to be beneficial was to use a timing function that can leverage the vDSO. We hit a couple of snags along the way, like the fact that the glibc crashes when clock_gettime is called from a preinit_array, or the fact that `__vdso_clock_gettime` is mangled (for security purposes) and can't be used directly, and also that clock_gettime can be intercepted. The proposed solution takes care of all this as far as I can tell, and significantly improve performances and some Scudo load tests with memory reclaiming enabled. @mcgrathr: please feel free to follow up on https://reviews.llvm.org/D40657#940857 here. I posted a reply at https://reviews.llvm.org/D40657#940974. Reviewers: alekseyshl, krytarowski, flowerhack, mcgrathr, kubamracek Reviewed By: alekseyshl, krytarowski Subscribers: #sanitizers, mcgrathr, srhines, llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D40679 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@320409 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-09Correct handling of the TLS/NetBSD block of the main programKamil Rytarowski
Summary: Include <sys/tls.h> for: - struct tls_tcb - thread control block structure - __HAVE___LWP_GETTCB_FAST - __lwp_gettcb_fast() is available - __HAVE___LWP_GETPRIVATE_FAST - __lwp_getprivate_fast() is available - __HAVE_TLS_VARIANT_I - TLS Variant I for this architecture - __HAVE_TLS_VARIANT_II - TLS Variant II for this architecture Rename ThreadSelfSegbase() to ThreadSelfTlsTcb and switch it to retrieve in a portable way TCB. Switch ThreadSelf() to retrieve pthread from struct tcb_tls. Use dl_iterate_phdr() to find out the size of TLS block of the main program. Correct the index of the TLS block of the main program (dlpi_tls_modid); it's 1, not 2. New NetBSD code is now CPU (NetBSD port) agnostic. Stop sharing the same code with FreeBSD. Sponsored by <The NetBSD Foundation> Reviewers: dvyukov, joerg, vitalybuka Reviewed By: vitalybuka Subscribers: emaste, kubamracek, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40159 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@320234 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-09Hardware-assisted AddressSanitizer (compiler-rt)Evgeniy Stepanov
Summary: Runtime library for HWASan, initial commit. Does not randomize tags yet, does not handle stack or globals. Reviewers: kcc, pcc, alekseyshl Subscribers: srhines, kubamracek, dberris, mgorny, llvm-commits, krytarowski Differential Revision: https://reviews.llvm.org/D40935 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@320231 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-09NetBSD ships with POSIX strerror_r(3)Kamil Rytarowski
Summary: Switch NetBSD from GNU to the POSIX strerror_r(3) interceptor. Sponsored by <The NetBSD Foundation> Reviewers: joerg, eugenis, vitalybuka Reviewed By: vitalybuka Subscribers: srhines, kubamracek, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D41019 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@320221 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-06Update other SizeEnums to be of type uptr as wellVlad Tsyrklevich
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319984 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-06Fix broken windows sanitizer buildbotVlad Tsyrklevich
r319875 caused a sign comparison build failure. Explicitly set the enum's type to be unsigned. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319977 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-06Handle NetBSD symbol renaming in msan_interceptors.ccKamil Rytarowski
Summary: NetBSD renames symbols for historical and compat reasons. Add required symbol renames in sanitizer_common_interceptors.inc: - gettimeofday -> __gettimeofday50 - getrusage -> __getrusage50 - shmctl -> __shmctl50 Additionally handle sigaction symbol mangling. Rename the function symbol in the file to SIGACTION_SYMNAME and define it as __sigaction14 for NetBSD and sigaction for !NetBSD. We cannot use simple renaming with the proprocessor, as there are valid fields named sigaction and they must be left intact. Sponsored by <The NetBSD Foundation> Reviewers: joerg, eugenis, vitalybuka, dvyukov Reviewed By: vitalybuka Subscribers: kubamracek, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40766 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319966 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-04[sanitizer] 64-bit allocator's PopulateFreeArray partial refactorKostya Kortchinsky
Summary: This is an attempt at making `PopulateFreeArray` less obscure, more consistent, and a tiny bit faster in some circumstances: - use more consistent variable names, that work both for the user & the metadata portions of the code; the purpose of the code is mostly the same for both regions, so it makes sense that the code should be mostly similar as well; - replace the while sum loops with a single `RoundUpTo`; - mask most of the metadata computations behind kMetadataSize, allowing some blocks to be completely optimized out if not use metadata; - `const` the constant variables; - add a `LIKELY` as the branch it applies to will almost always be taken. Reviewers: alekseyshl, flowerhack Reviewed By: alekseyshl Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D40754 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319673 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-04Handle NetBSD symbol renaming in sanitizer_common_interceptors.incKamil Rytarowski
Summary: NetBSD renames symbols for historical and compat reasons. Add required symbol renames in sanitizer_common_interceptors.inc: - clock_gettime -> __clock_gettime50 - clock_getres -> __clock_getres50 - clock_settime -> __clock_settime50 - setitimer -> __setitimer50 - getitimer -> __getitimer50 - opendir -> __opendir30 - readdir -> __readdir30 - time -> __time50 - localtime_r -> __localtime_r50 - gmtime_r -> __gmtime_r50 - gmtime -> __gmtime50 - ctime -> __ctime50 - ctime_r -> __ctime_r50 - mktime -> __mktime50 - getpwnam -> __getpwnam50 - getpwuid -> __getpwuid50 - getpwnam_r -> __getpwnam_r50 - getpwuid_r -> __getpwuid_r50 - getpwent -> __getpwent50 - glob -> __glob30 - wait3 -> __wait350 - wait4 -> __wait450 - readdir_r -> __readdir_r30 - setlocale -> __setlocale50 - scandir -> __scandir30 - sigtimedwait -> __sigtimedwait50 - sigemptyset -> __sigemptyset14 - sigfillset -> __sigfillset14 - sigpending -> __sigpending14 - sigprocmask -> __sigprocmask14 - shmctl -> __shmctl50 - times -> __times13 - stat -> __stat50 - getutent -> __getutent50 - getutxent -> __getutxent50 - getutxid -> __getutxid50 - getutxline -> __getutxline50 Sponsored by <The NetBSD Foundation> Reviewers: joerg, vitalybuka, cryptoad, dvyukov Reviewed By: cryptoad Subscribers: llvm-commits, kubamracek, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40765 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319670 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-04Move __tsan::Vector to __sanitizerKamil Rytarowski
Summary: The low-fat STL-like vector container will be reused in MSan. It is needed to implement an atexit(3) interceptor on NetBSD/amd64 in MSan. Sponsored by <The NetBSD Foundation> Reviewers: joerg, dvyukov, eugenis, vitalybuka, kcc Reviewed By: dvyukov Subscribers: kubamracek, mgorny, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40726 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319650 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-29[sanitizer] Add 'strip_env' flag to enable/disable removing sanitizer dylib ↵Kuba Mracek
from DYLD_INSERT_LIBRARIES On macOS, we usually don't require launching the target with DYLD_INSERT_LIBRARIES anymore. However, it is still necessary when running a target that is not instrumented (and e.g. dlopen's an instrument library later). In any case, ASan and TSan currently remove themselves from the DYLD_INSERT_LIBRARIES environment variable to avoid passing it onto children. This works well e.g. when instrumenting a shell. A problem arises when the target is a non-instrumented shim (e.g. "xcrun") that either re-execs or launches a child that is supposed to get DYLD_INSERT_LIBRARIES propagated. To support this mode, this patch introduces 'strip_env' flag that can be used to keep DYLD_INSERT_LIBRARIES untouched. Differential Revision: https://reviews.llvm.org/D39991 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319365 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-29[compiler-rt] Switch from deprecated TARGET_IPHONE_SIMULATOR to ↵Kuba Mracek
TARGET_OS_SIMULATOR Differential Revision: https://reviews.llvm.org/D39987 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319349 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-29[asan] Fix macOS FindDynamicShadowStart to consider the last gap in the VM mapKuba Mracek
It looks FindDynamicShadowStart has a bug: When iterating over the memory map, we will not consider the very last gap in the address space. Let's fix that. Differential Revision: https://reviews.llvm.org/D39989 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319348 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-29[asan] Don't crash on fclose(NULL)Kuba Mracek
It's explicitly forbidden to call fclose with NULL, but at least on Darwin, this succeeds and doesn't segfault. To maintain binary compatibility, ASan should survice fclose(NULL) as well. Differential Revision: https://reviews.llvm.org/D40053 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319347 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-29[asan] Allow getpwnam(NULL) for binary compatibilityKuba Mracek
Calling getpwnam(NULL) is probably a bug, but at least on Darwin, such a call succeeds without segfaulting. I have some existing code that relies on that. To maintain binary compatibility, ASan should also survive a call to getpwnam with NULL. Differential Revision: https://reviews.llvm.org/D40052 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319344 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-29[sanitizer] Refactor how assembly files are handledKuba Mracek
This renames ASM_TSAN_SYMBOL and ASM_TSAN_SYMBOL_INTERCEPTOR to just ASM_SYMBOL and ASM_SYMBOL_INTERCEPTOR, because they can be useful in more places than just TSan. Also introduce a CMake function to add ASM sources to a target. Differential Revision: https://reviews.llvm.org/D40143 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319339 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-28[LSan] Fix one source of stale segments in the process memory mapping.Alex Shlyapnikov
Summary: Load process memory map after updating the same cache to reflect the umap happening in the process of updating. Also clear out the buffer in case of failed read of /proc/self/maps (not the source of stale segments, but can lead to the similar crash). Reviewers: eugenis Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D40529 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319237 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-28Handle symbol renaming of sigaction for NetBSDKamil Rytarowski
Summary: NetBSD uses the __sigaction14 symbol name for historical and compat reasons for the sigaction(2) function name. Rename the interceptors and users of sigaction to sigaction_symname and reuse it in the code base. This change fixes 4 failing tests in TSan/NetBSD: - ThreadSanitizer-x86_64 :: signal_errno.cc - ThreadSanitizer-x86_64 :: signal_malloc.cc - ThreadSanitizer-x86_64 :: signal_sync2.cc - ThreadSanitizer-x86_64 :: signal_thread.cc Sponsored by <The NetBSD Foundation> Reviewers: joerg, vitalybuka, eugenis, dvyukov, kcc Reviewed By: dvyukov Subscribers: kubamracek, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40341 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319160 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-27[fuchsia] Update Fuchsia with a new mmap implementation.Kostya Kortchinsky
Summary: Now that the sanitizer_common interface for MmapNoAccess / MmapFixed have been refactored to allow a more OO-esque access pattern, update the Fuchsia mmap implementation to take advantage of this. Previously MmapNoAccess / MmapFixed relied on a global allocator_vmar, since the sanitizer_allocator only called MmapNoAccess once. Now, we create a new VMAR per ReservedAddressRange object. This allows the sanitizer allocator to work in tandem with the Scudo secondary allocator. This is part 4 of a 4 part changeset: * part 1 https://reviews.llvm.org/D38593 * part 2 https://reviews.llvm.org/D38592 * part 3 https://reviews.llvm.org/D38593 Reviewers: mcgrathr, cryptoad Reviewed By: cryptoad Subscribers: alekseyshl, mcgrathr, kubamracek, mehdi_amini Differential Revision: https://reviews.llvm.org/D38595 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319083 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-26Prevent Thread Exited/Joined events raceKamil Rytarowski
Summary: Add atomic verification to ensure that Thread is Joined after marking it Finished. It is required for NetBSD in order to prevent Thread Exited/Joined race, that may occur when native system libpthread(3) cannot be reliably traced in a way to guarantee that the mentioned events happen one after another. This change fixes at least TSan and LSan on NetBSD. Sponsored by <The NetBSD Foundation> Reviewers: joerg, dvyukov, vitalybuka Reviewed By: dvyukov Subscribers: llvm-commits, kubamracek, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40294 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319004 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-25Plug dlerror() leak for swift_demangleKamil Rytarowski
Summary: InitializeSwiftDemangler() attempts to resolve the swift_demangle symbol. If this is not available, we observe dlerror message leak. Caught on NetBSD/amd64 in TSan. Sponsored by <The NetBSD Foundation> Reviewers: joerg, kubamracek, vitalybuka, dvyukov, eugenis Reviewed By: dvyukov Subscribers: llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40382 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318980 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-22[scudo] Overhaul hardware CRC32 feature detectionKostya Kortchinsky
Summary: This patch aims at condensing the hardware CRC32 feature detection and making it slightly more effective on Android. The following changes are included: - remove the `CPUFeature` enum, and get rid of one level of nesting of functions: we only used CRC32, so we just implement and use `hasHardwareCRC32`; - allow for a weak `getauxval`: the Android toolchain is compiled at API level 14 for Android ARM, meaning no `getauxval` at compile time, yet we will run on API level 27+ devices. The `/proc/self/auxv` fallback can work but is worthless for a process like `init` where the proc filesystem doesn't exist yet. If a weak `getauxval` doesn't exist, then fallback. - couple of extra corrections. Reviewers: alekseyshl Reviewed By: alekseyshl Subscribers: kubamracek, aemerson, srhines, kristof.beyls, llvm-commits Differential Revision: https://reviews.llvm.org/D40322 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318859 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-21[scudo] Make getNumberOfCPUs Fuchsia compliant v2Kostya Kortchinsky
Summary: This change allows Fuchsia to boot properly using the Scudo allocator. A first version of this commit was reverted by rL317834 because it broke Android builds for toolchains generated with older NDKs. This commit introduces a fall back to solve that issue. Reviewers: cryptoad, krytarowski, rnk, alekseyshl Reviewed By: cryptoad, krytarowski, alekseyshl Subscribers: llvm-commits, srhines, kubamracek, krytarowski Differential Revision: https://reviews.llvm.org/D40121 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318802 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-21[sanitizer] Define SANITIZER_USE_GETAUXVAL for AndroidKostya Kortchinsky
Summary: Android for API level >= 21 has `getauxval`. Enable `SANITIZER_USE_GETAUXVAL` when those requirements are met. Correct a typo in the header. Reviewers: alekseyshl Reviewed By: alekseyshl Subscribers: srhines, llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D40260 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318775 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-21Correct NetBSD support in pthread_once(3)/TSanKamil Rytarowski
Summary: The pthread_once(3)/NetBSD type is built with the following structure: struct __pthread_once_st { pthread_mutex_t pto_mutex; int pto_done; }; Set the pto_done position as shifted by __sanitizer::pthread_mutex_t_sz from the beginning of the pthread_once struct. This corrects deadlocks when the pthread_once(3) function is used. Sponsored by <The NetBSD Foundation> Reviewers: joerg, dvyukov, vitalybuka Reviewed By: dvyukov Subscribers: llvm-commits, kubamracek, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40262 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318742 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-21[sanitizers] Add init function to set alignment of low level allocatorWalter Lee
ASan requires that the min alignment be at least the shadow granularity, so add an init function to do that. Differential Revision: https://reviews.llvm.org/D39473 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318717 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-20Add DemangleFunctionName for backtracing on NetBSDKamil Rytarowski
Summary: NetBSD uses indirection for old threading functions for historical reasons The mangled names are internal implementation detail and should not be exposed even in backtraces. Sponsored by <The NetBSD Foundation> Reviewers: joerg, vitalybuka, dvyukov Reviewed By: dvyukov Subscribers: kubamracek, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40251 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318671 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-20[asan] Use dynamic shadow on 32-bit Android, try 2.Evgeniy Stepanov
Summary: This change reverts r318575 and changes FindDynamicShadowStart() to keep the memory range it found mapped PROT_NONE to make sure it is not reused. We also skip MemoryRangeIsAvailable() check, because it is (a) unnecessary, and (b) would fail anyway. Reviewers: pcc, vitalybuka, kcc Subscribers: srhines, kubamracek, mgorny, llvm-commits, hiraditya Differential Revision: https://reviews.llvm.org/D40203 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318666 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-20[sanitizer] New attempt at using runtime checks for Android loggingKostya Kortchinsky
Summary: This is a second attempt after D40100 induced racey crashes with ASan (due to `__android_log_write` and the `strncpy` interceptor on API >= 21). This new version checks the runtime API level to be <= `ANDROID_KITKAT` for the use of `__android_log_write`, otherwise we use `syslog`, which should conform with the previous behavior. Unfortunately despite numerous efforts I couldn't reproduce the original crashes in my environments so I couldn't test that the fix was actually preventing crashes. Reviewers: eugenis Reviewed By: eugenis Subscribers: llvm-commits, srhines, kubamracek Differential Revision: https://reviews.llvm.org/D40149 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318659 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-20Correct return types of NetBSD specific functionsKamil Rytarowski
The __libc_mutex_lock, __libc_mutex_unlock and __libc_thr_setcancelstate functions return int, not void. This does not seem to introduce a functional change, however it looks better with fixed the function prototype. Sponsored by <The NetBSD Foundation> git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318654 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-20Handle NetBSD specific indirection of libpthread functionsKamil Rytarowski
Summary: Correct handling of three libpthread(3) functions on NetBSD: - pthread_mutex_lock(3), - pthread_mutex_unlock(3), - pthread_setcancelstate(3). Code out of the libpthread(3) context uses the libc symbols: - __libc_mutex_lock, - __libc_mutex_unlock, - __libc_thr_setcancelstate. The threading library (libpthread(3)) defines strong aliases: - __strong_alias(__libc_mutex_lock,pthread_mutex_lock) - __strong_alias(__libc_mutex_unlock,pthread_mutex_unlock) - __strong_alias(__libc_thr_setcancelstate,pthread_setcancelstate) This caused that these functions were invisible to sanitizers on NetBSD. Intercept the libc-specific ones and add them as NetBSD-specific aliases for the common pthread(3) ones. NetBSD needs to intercept both functions, as the regularly named ones are used internally in libpthread(3). Sponsored by <The NetBSD Foundation> Reviewers: joerg, dvyukov, vitalybuka Reviewed By: dvyukov Subscribers: llvm-commits, kubamracek, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40241 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318646 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-18Revert "[asan] Use dynamic shadow on 32-bit Android" and 3 more.Evgeniy Stepanov
Revert the following commits: r318369 [asan] Fallback to non-ifunc dynamic shadow on android<22. r318235 [asan] Prevent rematerialization of &__asan_shadow. r317948 [sanitizer] Remove unnecessary attribute hidden. r317943 [asan] Use dynamic shadow on 32-bit Android. MemoryRangeIsAvailable() reads /proc/$PID/maps into an mmap-ed buffer that may overlap with the address range that we plan to use for the dynamic shadow mapping. This is causing random startup crashes. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318575 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-16[sanitizer] Revert rL318410Kostya Kortchinsky
Summary: The patch seems to have turned some Android tests flaky. The reason is unclear. This reverts D40100 in case we can't figure out what is happening. Reviewers: eugenis Reviewed By: eugenis Subscribers: srhines, kubamracek Differential Revision: https://reviews.llvm.org/D40138 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318438 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-16Implement GetTls() for NetBSDKamil Rytarowski
Summary: Reuse the existing code for FreeBSD that is compatible with NetBSD. Add NetBSD support in tests: tls_race.cc and tls_race2.cc. Sponsored by <The NetBSD Foundation> Reviewers: joerg, dvyukov, vitalybuka, kcc, eugenis Reviewed By: dvyukov Subscribers: srhines, emaste, kubamracek, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40105 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318431 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-16[sanitizer] Use runtime checks instead of API level for Android loggingKostya Kortchinsky
Summary: Recent Bionic have a slew of `async_safe_*` logging functions that are basically the liblog ones but included within the libc. They have the advantage of not allocating memory. `async_safe_write_log` does no formatting and is likely the best candidate for logging. Use a weak definition to try and use it. Also, avoid API level checks (as the toolchain is compiled at a rather low API level) for `__android_log_write` in favor of a weak definition as well. Keep the fallback to `syslog` if nothing else was found. I tried to overhaul the code block to only have a single #if SANITIZER_ANDROID but I am not particularly attached to the form. LMKWYT. Reviewers: eugenis Reviewed By: eugenis Subscribers: srhines, kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D40100 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318410 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-13[sanitizer] Update scudo to use new APIKostya Kortchinsky
Summary: The ScudoAllocator uses a SecondaryHeader to keep track of the size and base address of each mmap'd chunk. This aligns well with what the ReservedAddressRange is trying to do. This changeset converts the scudo allocator from using the MmapNoAccess/MmapFixed APIs to the ReservedAddressRange::Init and ::Map APIs. In doing so, it replaces the SecondayHeader struct with the ReservedAddressRange object. This is part 3 of a 4 part changeset; part 1 https://reviews.llvm.org/D39072 and part 2 https://reviews.llvm.org/D38592 Reviewers: alekseyshl, mcgrathr, cryptoad, phosek Reviewed By: cryptoad Subscribers: llvm-commits, cryptoad, kubamracek Differential Revision: https://reviews.llvm.org/D38593 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318080 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-11Correct NetBSD build issueKamil Rytarowski
Cast SIG_IGN to (uptr). SIG_IGN is defined on NetBSD as a function pointer and cannot be assigned to an integer as it is. sys/signal.h:#define SIG_IGN ((void (*)(int)) 1) git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317978 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10[sanitizer] Remove unnecessary attribute hidden.Evgeniy Stepanov
This should fix windows build of compiler-rt broken in r317943. The attribute is unnecessary because since GetMaxVirtualAddress was split in two, we no longer use common_flags() in the ifunc resolver context. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317948 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10[tsan] Move out more types to sanitizer_commonVitaly Buka
https://github.com/google/sanitizers/issues/637 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317946 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10[asan] Use dynamic shadow on 32-bit Android.Evgeniy Stepanov
Summary: The following kernel change has moved ET_DYN base to 0x4000000 on arm32: https://marc.info/?l=linux-kernel&m=149825162606848&w=2 Switch to dynamic shadow base to avoid such conflicts in the future. Reserve shadow memory in an ifunc resolver, but don't use it in the instrumentation until PR35221 is fixed. This will eventually let use save one load per function. Reviewers: kcc Subscribers: aemerson, srhines, kubamracek, kristof.beyls, hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D39393 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317943 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10[compiler-rt] Fix const and volatile qualifier warningsKuba Mracek
Building with a new clang produces a bunch of warnings about dropped 'const' and 'volatile' qualifiers on pointers. Let's fix them. Differential Revision: https://reviews.llvm.org/D39861 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317929 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10[tsan] Use __sanitizer_siginfo from sanitizer_commonVitaly Buka
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317872 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10[sanitizer] Forward declaration of __sanitizer_sigaction without signal ↵Vitaly Buka
interceptors git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317870 91177308-0d34-0410-b5e6-96231b3b80d8