summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common/sanitizer_linux.cc
AgeCommit message (Collapse)Author
2018-07-26[sanitizer] Include signal.h instead of sys/signal.hFangrui Song
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@338004 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-06[sanitizer] Cleanup ReadFileToVector and ReadFileToBufferVitaly Buka
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 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@334130 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-05Introduce CheckASLR() in sanitizersKamil Rytarowski
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 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@333985 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-23Fix internal_mmap() on 32-bit NetBSD platformsKamil Rytarowski
There is need to use internal_syscall64() instead of internal_syscall_ptr(). The offset argument of type off_t is always 64-bit. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@333075 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-10[sanitizer] Fix typo in commentVitaly Buka
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@331956 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-10[sanitizer] Fix compilation after invalid rebaseVitaly Buka
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@331954 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-10[sanitizer] Don't miss threads by ThreadSuspenderVitaly Buka
Summary: Enumerating /proc/<pid>/task/ dir Linux may stop if thread is dead. In this case we miss some alive threads and can report false memory leaks. To solve this issue we repeat enumeration if the last thread is dead. Do detect dead threads same way as proc_task_readdir we use /proc/<pid>/task/<tid>/status. Similarly it also ends enumeration of if proc_fill_cache fails, but in this case Linux sets inode to 1 (Bad block). And just in case re-list threads if we had to call internal_getdents more than twice or result takes more than half of the buffer. Reviewers: eugenis, dvyukov, glider Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D46517 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@331953 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-09[sanitizer] Fix argument type and remove unneeded vector resizeVitaly Buka
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@331927 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-09[sanitizer] Use tid_t in ThreadListerVitaly Buka
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@331921 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-08[sanitizer] Fix error checking in ThreadListerVitaly Buka
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@331735 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-07[sanitizer] Simplify ThreadLister interfaceVitaly Buka
Reviewers: eugenis Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D46516 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@331701 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-07[sanitizer] Make InternalScopedBuffer::size() behavior similar to vector.Vitaly Buka
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@331612 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-25[mips] Implement GetWriteFlag() for mipsPetar Jovanovic
The read/write flag is set by manually decoding the instruction that caused the exception. It is implemented this way because the cause register which contains the needed flag was removed from the signal context structure which the user handler receives from the kernel. Patch by Milos Stojanovic. Differential Revision: https://reviews.llvm.org/D45768 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@330840 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-16[sanitizer] Split Symbolizer/StackTraces from core RTSanitizerCommonKostya Kortchinsky
Summary: Host symbolizer & stacktraces related code in their own RT: `RTSanitizerCommonSymbolizer`, which is "libcdep" by nature. Symbolizer & stacktraces specific code that used to live in common files is moved to a new file `sanitizer_symbolizer_report.cc` as is. The purpose of this is the enforce a separation between code that relies on symbolization and code that doesn't. This saves the inclusion of spurious code due to the interface functions with default visibility, and the extra data associated. The following sanitizers makefiles were modified & tested locally: - dfsan: doesn't require the new symbolizer RT - esan: requires it - hwasan: requires it - lsan: requires it - msan: requires it - safestack: doesn't require it - xray: doesn't require it - tsan: requires it - ubsan: requires it - ubsan_minimal: doesn't require it - scudo: requires it (but not for Fuchsia that has a minimal runtime) This was tested locally on Linux, Android, Fuchsia. Reviewers: alekseyshl, eugenis, dberris, kubamracek, vitalybuka, dvyukov, mcgrathr Reviewed By: alekseyshl, vitalybuka Subscribers: srhines, kubamracek, mgorny, krytarowski, delcypher, llvm-commits, #sanitizers Differential Revision: https://reviews.llvm.org/D45457 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@330131 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-09GetRandom / OpenBSD, using getentropy to get high quality randomnessVitaly Buka
Summary: - getentropy presence since late 2014, safe to use. - guarantees to delivers good random data up to 256 bytes. - fall back to /dev/urandom as long the buffer is correct. Patch by David CARLIER Reviewers: kubamracek, vitalybuka Reviewed By: vitalybuka Subscribers: cryptoad, llvm-commits, #sanitizers Differential Revision: https://reviews.llvm.org/D44866 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@329633 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-23[sanitizer] Fix PPC botVitaly Buka
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@328279 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-22More OpenBSD fixesVitaly Buka
Summary: - Use internal_syscall_ptr in internal_readlink - use sigcontext on OpenBSD Patch by David CARLIER Reviewers: krytarowski, vitalybuka Reviewed By: vitalybuka Subscribers: kubamracek, llvm-commits, #sanitizers Differential Revision: https://reviews.llvm.org/D44713 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@328239 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-21Fix declaration of environ after r327923Vitaly Buka
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@328077 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-19OpenBSD UBsan support missing bitsVitaly Buka
Summary: Lost bits since the WIP ticket Patch by David CARLIER Reviewers: vitalybuka, vsk Reviewed By: vitalybuka Subscribers: srhines, kubamracek, krytarowski, fedor.sergeev, llvm-commits, #sanitizers Differential Revision: https://reviews.llvm.org/D44599 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@327923 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-19Cleanup of "extern char **environ" declarationVitaly Buka
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@327904 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-03Sanitiser common, using u64 type for GetTid on posix systemsKamil Rytarowski
Summary: Moving from ptr to u64 for GetTid posix implementation. [FreeBSD] Moving from pthread_self to thr_self more appropriate to get thread ID. Patch by: David CARLIER Reviewers: krytarowski, vitalybuka Reviewed By: vitalybuka Subscribers: kubamracek, llvm-commits, #sanitizers Differential Revision: https://reviews.llvm.org/D43998 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@326647 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-26[asan] Be more careful and verbose when allocating dynamic shadow memoryKuba Mracek
FindAvailableMemoryRange can currently overwrite existing memory (by restricting the VM below addresses that are already used). This patch adds a check to make sure we don't restrict the VM space too much. We are also now more explicit about why the lookup failed and print out verbose values. Differential Revision: https://reviews.llvm.org/D43318 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@326106 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-21[hwasan] Fix inline instrumentation.Evgeniy Stepanov
This patch changes hwasan inline instrumentation: Fixes address untagging for shadow address calculation (use 0xFF instead of 0x00 for the top byte). Emits brk instruction instead of hlt for the kernel and user space. Use 0x900 instead of 0x100 for brk immediate (0x100 - 0x800 are unavailable in the kernel). Fixes and adds appropriate tests. Patch by Andrey Konovalov. Differential Revision: https://reviews.llvm.org/D43135 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@325711 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-17Recognize all NetBSD architectures in UBSanKamil Rytarowski
Summary: Use uniform accessors for Program Pointer, Stack Pointer and Frame Pointer. Remove CPU check in UBSan supported platforms and rely only on the OS type. This adds NetBSD support in GetPcSpBp() for: - ARM - ARM64 - HPPA - PowerPC/PowerPC64 - SPARC/SPARC64 - MIPS - DEC Alpha AXP - DEC VAX - M68K and M68010 - SH3 - IA64 - OR1K - RISCV Sponsored by <The NetBSD Foundation> Reviewers: joerg, vitalybuka, ro Reviewed By: vitalybuka Subscribers: aemerson, jyknight, sdardis, kubamracek, arichardson, llvm-commits, kristof.beyls, fedor.sergeev, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D43021 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@325431 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-07Correct a bug in GetArgsAndEnv() for NetBSDKamil Rytarowski
Fix setting envp. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@324481 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-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-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-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-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-08[sanitizer] Asm implementation of syscall() for arm32.Evgeniy Stepanov
Summary: These will be used in an ifunc resolver, when the binary may not be completely relocated, and syscall() function from libc could not be used. Reviewers: dvyukov, vitalybuka Subscribers: aemerson, kubamracek, javed.absar, llvm-commits, kristof.beyls Differential Revision: https://reviews.llvm.org/D39701 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317640 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-07(NFC) Rename GetMax{,User}VirtualAddress.Evgeniy Stepanov
Future change will introduce GetMaxVirtualAddress that will not take the kernel area into account. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317638 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-06[LSan] Detect dynamic loader by its base address.Alex Shlyapnikov
Summary: Relanding D38600, which was reverted due to various PPC bot failures. If it breaks something again, please provide some pointers to broken bots, not just revert it, otherwise it's very hard to reason what's wrong with this commit. Whenever possible (Linux + glibc 2.16+), detect dynamic loader module by its base address, not by the module name matching. The current name matching approach fails on some configurations. Reviewers: eugenis Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D39275 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317512 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-25Add NetBSD improvements in sanitizersKamil Rytarowski
Summary: Changes: * Add initial msan stub support. * Handle NetBSD specific pthread_setname_np(3). * NetBSD supports __attribute__((tls_model("initial-exec"))), define it in SANITIZER_TLS_INITIAL_EXEC_ATTRIBUTE. * Add ReExec() specific bits for NetBSD. * Simplify code and add syscall64 and syscall_ptr for !NetBSD. * Correct bunch of syscall wrappers for NetBSD. * Disable test/tsan/map32bit on NetBSD as not applicable. * Port test/tsan/strerror_r to a POSIX-compliant OSes. * Disable __libc_stack_end on NetBSD. * Disable ReadNullSepFileToArray() on NetBSD. * Define struct_ElfW_Phdr_sz, detected missing symbol by msan. * Change type of __sanitizer_FILE from void to char. This helps to reuse this type as an array. Long term it will be properly implemented along with SANITIZER_HAS_STRUCT_FILE setting to 1. * Add initial NetBSD support in lib/tsan/go/buildgo.sh. * Correct referencing stdout and stderr in tsan_interceptors.cc on NetBSD. * Document NetBSD x86_64 specific virtual memory layout in tsan_platform.h. * Port tests/rtl/tsan_test_util_posix.cc to NetBSD. * Enable NetBSD tests in test/msan/lit.cfg. * Enable NetBSD tests in test/tsan/lit.cfg. Sponsored by <The NetBSD Foundation> Reviewers: joerg, vitalybuka, eugenis, kcc, dvyukov Reviewed By: dvyukov Subscribers: #sanitizers, llvm-commits, kubamracek Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D39124 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@316591 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-05Revert "[LSan] Detect dynamic loader by its base address."Alex Shlyapnikov
This reverts commit r315024. Breaks sysconf_interceptor_bypass_test.cc git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@315031 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-05[LSan] Detect dynamic loader by its base address.Alex Shlyapnikov
Summary: Relanding D33859, which was reverted because it has "broken LOTS of ARM/AArch64 bots for two days". If it breaks something again, please provide some pointers to broken bots, not just revert it, otherwise it's very hard to reason what's wrong with this commit. Whenever possible (Linux + glibc 2.16+), detect dynamic loader module by its base address, not by the module name matching. The current name matching approach fails on some configurations. Reviewers: eugenis Subscribers: aemerson, kubamracek, kristof.beyls, llvm-commits Differential Revision: https://reviews.llvm.org/D38600 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@315024 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-15[sanitizer][mips64] fix MIPS64 kernel_stat_to_stat()Petar Jovanovic
This patch tackles with two issues: Output stat st_[a|m|c]time fields were holding wrong values. st_[a|m|c]time fields should have contained value of seconds and instead these are filled with st_[a|m|c]time_nsec fields which hold nanoseconds. Build fails for MIPS64 if SANITIZER_ANDROID. Recently <sys/stat.h> from bionic introduced st_[a|m|c]time_nsec macros for compatibility with old NDKs and those clashed with the field names of the <asm/stat.h> kernel_stat structure. To fix both issues and make sure sanitizer builds on all platforms, we must un-define all compatibility macros and access the fields directly when copying the 'time' fields. Patch by Miodrag Dinic <miodrag.dinic@imgtec.com> Differential Revision: https://reviews.llvm.org/D35671 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@313360 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-14[compiler-rt] Cleanup SignalContext initializationVitaly Buka
Reviewers: eugenis, alekseyshl Subscribers: kubamracek, dberris Differential Revision: https://reviews.llvm.org/D37827 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@313223 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-14[sanitizers] Add a blocking boolean to GetRandom prototypeKostya Kortchinsky
Summary: On platforms with `getrandom`, the system call defaults to blocking. This becomes an issue in the very early stage of the boot for Scudo, when the RNG source is not set-up yet: the syscall will block and we'll stall. Introduce a parameter to specify that the function should not block, defaulting to blocking as the underlying syscall does. Update Scudo to use the non-blocking version. Reviewers: alekseyshl Reviewed By: alekseyshl Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D36399 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@310839 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-08Reuse sanitizer_linux for NetBSDKamil Rytarowski
Summary: Follow FreeBSD and reuse sanitizer_linux for NetBSD. Part of the code inspired by the original work on libsanitizer in GCC 5.4 by Christos Zoulas. Sponsored by <The NetBSD Foundation> Reviewers: joerg, kcc, filcab, vitalybuka, fjricci, dvyukov Reviewed By: fjricci Subscribers: dvyukov, emaste, kubamracek, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D36325 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@310411 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-13Fix sanitizer build against latest glibcKostya Serebryany
Summary: libsanitizer doesn't build against latest glibc anymore, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81066 for details. One of the changes is that stack_t changed from typedef struct sigaltstack { ... } stack_t; to typedef struct { ... } stack_t; for conformance reasons. And the other change is that the glibc internal __need_res_state macro is now ignored, so when doing ``` #define __need_res_state #include <resolv.h> ``` the effect is now the same as just ``` #include <resolv.h> ``` and thus one doesn't get just the ``` struct __res_state { ... }; ``` definition, but newly also the ``` extern struct __res_state *__res_state(void) __attribute__ ((__const__)); ``` prototype. So __res_state is no longer a type, but a function. Reviewers: kcc, ygribov Reviewed By: kcc Subscribers: kubamracek Differential Revision: https://reviews.llvm.org/D35246 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@307969 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-12[asan] For iOS/AArch64, if the dynamic shadow doesn't fit, restrict the VM spaceKuba Mracek
On iOS/AArch64, the address space is very limited and has a dynamic maximum address based on the configuration of the device. We're already using a dynamic shadow, and we find a large-enough "gap" in the VM where we place the shadow memory. In some cases and some device configuration, we might not be able to find a large-enough gap: E.g. if the main executable is linked against a large number of libraries that are not part of the system, these libraries can fragment the address space, and this happens before ASan starts initializing. This patch has a solution, where we have a "backup plan" when we cannot find a large-enough gap: We will restrict the address space (via MmapFixedNoAccess) to a limit, for which the shadow limit will fit. Differential Revision: https://reviews.llvm.org/D35098 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@307865 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-11Refactor MemoryMappingLayout::Next to use a single struct instead of output ↵Francis Ricci
parameters. NFC. Summary: This is the first in a series of patches to refactor sanitizer_procmaps to allow MachO section information to be exposed on darwin. In addition, grouping all segment information in a single struct is cleaner than passing it through a large set of output parameters, and avoids the need for annotations of NULL parameters for unneeded information. The filename string is optional and must be managed and supplied by the calling function. This is to allow the MemoryMappedSegment struct to be stored on the stack without causing overly large stack sizes. Reviewers: alekseyshl, kubamracek, glider Subscribers: emaste, llvm-commits Differential Revision: https://reviews.llvm.org/D35135 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@307688 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-11Remove duplicate assignments in stat64/kernel_stat_to_stat functionsPetar Jovanovic
Remove duplicate assignments in stat64_to_stat() and kernel_stat_to_stat(). git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@307657 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-06More fixup for r307281: Move the #includes to sanitizer_linux.ccKuba Mracek
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@307284 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-06Fixup for r307281: Also move GetKernelAreaSize into sanitizer_linux.ccKuba Mracek
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@307282 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-06[sanitizer] Split GetMaxVirtualAddress into separate Linux version and Mac ↵Kuba Mracek
version [NFC] The logic in GetMaxVirtualAddress is already pretty complex, and I want to get rid of the hardcoded value for iOS/AArch64, which would need adding more Darwin-specific code, so let's split the implementation into sanitizer_linux.cc and sanitizer_mac.cc files. NFC. Differential Revision: https://reviews.llvm.org/D35031 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@307281 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-21[sanitizer] Add a function to gather random bytesKostya Kortchinsky
Summary: AFAICT compiler-rt doesn't have a function that would return 'good' random bytes to seed a PRNG. Currently, the `SizeClassAllocator64` uses addresses returned by `mmap` to seed its PRNG, which is not ideal, and `SizeClassAllocator32` doesn't benefit from the entropy offered by its 64-bit counterpart address space, so right now it has nothing. This function aims at solving this, allowing to implement good 32-bit chunk randomization. Scudo also has a function that does this for Cookie purposes, which would go away in a later CL once this lands. This function will try the `getrandom` syscall if available, and fallback to `/dev/urandom` if not. Unfortunately, I do not have a way to implement and test a Mac and Windows version, so those are unimplemented as of now. Note that `kRandomShuffleChunks` is only used on Linux for now. Reviewers: alekseyshl Reviewed By: alekseyshl Subscribers: zturner, rnk, llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D34412 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@305922 91177308-0d34-0410-b5e6-96231b3b80d8