summaryrefslogtreecommitdiff
path: root/lib/asan/asan_interceptors.h
AgeCommit message (Collapse)Author
2018-05-18[sanitizer] Trivial portion of the port to Myriad RTEMSWalter Lee
This commit contains the trivial portion of the port of ASan to Myriad RTEMS. - Whitelist platform in sanitizer_platform.h, ubsan_platform.h - Turn off general interception - Use memset for FastPoisonShadow - Define interception wrappers - Set errno symbol correctly - Enable ASAN_LOW_MEMORY - Enable preinit array - Disable slow unwinding - Use fuchsia offline symbolizer - Disable common code for: InitializeShadowMemory, CreateMainThread, AsanThread::ThreadStart, StartReportDeadlySignal, MaybeReportNonExecRegion. Differential Revision: https://reviews.llvm.org/D46454 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@332681 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-27Revert "[asan] Replace vfork with fork."Evgeniy Stepanov
Replacing vfork with fork results in significant slowdown of certain apps (in particular, memcached). This reverts r327752. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@328600 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-16[asan] Replace vfork with fork.Evgeniy Stepanov
Summary: vfork is not ASan-friendly because it modifies stack shadow in the parent process address space. While it is possible to compensate for that with, for example, __asan_handle_no_return before each call to _exit or execve and friends, simply replacing vfork with fork looks like by far the easiest solution. Posix compliant programs can not detect the difference between vfork and fork. Fixes https://github.com/google/sanitizers/issues/925 Reviewers: kcc, vitalybuka Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D44587 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@327752 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-16[asan] Remove empty fork interceptor.Evgeniy Stepanov
After a partial revert, ASan somehow ended up with an empty interceptor for fork(). git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@327748 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-27Disable ASan exceptions on NetBSDKamil Rytarowski
This is a workarond for the fallout from D42644: [asan] Intercept std::rethrow_exception indirectly. Reported problem on NetBSD/amd64: $ sh ./projects/compiler-rt/test/sanitizer_common/asan-i386-NetBSD/NetBSD/Output/ttyent.cc.script /usr/lib/i386/libgcc.a(unwind-dw2.o): In function `_Unwind_RaiseException': unwind-dw2.c:(.text+0x1b41): multiple definition of `_Unwind_RaiseException' /public/llvm-build/lib/clang/7.0.0/lib/netbsd/libclang_rt.asan-i386.a(asan_interceptors.cc.o):/public/llvm/projects/compiler-rt/lib/asan/asan_interceptors.cc:337: first defined here clang-7.0: error: linker command failed with exit code 1 (use -v to see invocation) git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@326216 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-27[asan] Enable ASAN_INTERCEPT___CXA_THROW for x86 AndroidVitaly Buka
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@326160 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-26Fix build for iOS/ARM ("__Unwind_RaiseException" is not available for armv7).Kuba Mracek
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@326150 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-26[asan] Intercept std::rethrow_exception indirectlyVitaly Buka
Summary: Fixes Bug 32434 See https://bugs.llvm.org/show_bug.cgi?id=32434 Short summary: std::rethrow_exception does not use __cxa_throw to rethrow the exception, so if it is called from uninstrumented code, it will leave the stack poisoned. This can lead to false positives. Long description: For functions which don't return normally (e.g. via exceptions), asan needs to unpoison the entire stack. It is not known before a call to such a function where execution will continue, some function which don't contain cleanup code like destructors might be skipped. After stack unwinding, execution might continue in uninstrumented code. If the stack has been poisoned before such a function is called, but the stack is unwound during the unconventional return, then zombie redzones (entries) for no longer existing stack variables can remain in the shadow memory. Normally, this is avoided by asan generating a call to asan_handle_no_return before all functions marked as [[noreturn]]. This asan_handle_no_return unpoisons the entire stack. Since these [[noreturn]] functions can be called from uninstrumented code, asan also introduces interceptor functions which call asan_handle_no_return before running the original [[noreturn]] function; for example, cxa_throw is intercepted. If a [[noreturn]] function is called from uninstrumented code (so the stack is left poisoned) and additionally, execution continues in uninstrumented code, new stack variables might be introduced and overlap with the stack variables which have been removed during stack unwinding. Since the redzones are not cleared nor overwritten by uninstrumented code, they remain but now contain invalid data. Now, if the redzones are checked against the new stack variables, false positive reports can occur. This can happen for example by the uninstrumented code calling an intercepted function such as memcpy, or an instrumented function. Intercepting std::rethrow_exception directly is not easily possible since it depends on the C++ standard library implementation (e.g. libcxx vs libstdc++) and the mangled name it produces for this function. As a rather simple workaround, we're intercepting _Unwind_RaiseException for libstdc++. For libcxxabi, we can intercept the ABI function __cxa_rethrow_primary_exception. Patch by Robert Schneider. Reviewers: kcc, eugenis, alekseyshl, vitalybuka Reviewed By: vitalybuka Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D42644 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@326132 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-11-10[sanitizer] Remove unneeded forward declaration of real_sigactionVitaly Buka
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317869 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10[sanitizer] Remove unneeded forward declarationsVitaly Buka
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317868 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-09[sanitizer] Allow sanitizers to redefine implementation of signal interceptorsVitaly Buka
Reviewers: eugenis Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D39870 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317843 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-16[sanitizer] Move signal interceptors from asan to sanitizer_commonVitaly Buka
Summary: Part of https://github.com/google/sanitizers/issues/637 Reviewers: eugenis, alekseyshl Subscribers: srhines, kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D37889 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@313449 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-07Add NetBSD support in asan_interceptors.hKamil Rytarowski
Summary: 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, filcab, kcc, fjricci, vitalybuka Reviewed By: vitalybuka Subscribers: kubamracek, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D36375 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@310246 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-02[asan] Interceptors for FuchsiaVitaly Buka
Summary: Fuchsia uses the "memintrinsics" interceptors, though not via any generalized interception mechanism. It doesn't use any other interceptors. Submitted on behalf of Roland McGrath. Reviewers: vitalybuka, alekseyshl, kcc Reviewed By: vitalybuka Subscribers: kubamracek, phosek, filcab, llvm-commits Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D36189 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@309798 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-20[asan] Move memcpy, memmove, memset code out of asan_interceptors.ccAlex Shlyapnikov
This is a pure refactoring change. It simply moves all the code and macros related to defining the ASan interceptor versions of memcpy, memmove, and memset into a separate file. This makes it cleaner to disable all the other interceptor code while still using these three, for a port that defines these but not the other common interceptors. Reviewers: alekseyshl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D35590 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@308575 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-04[ASAN] Add interceptor for __longjmp_chkPeter Wu
Summary: glibc on Linux calls __longjmp_chk instead of longjmp (or _longjmp) when _FORTIFY_SOURCE is defined. Ensure that an ASAN-instrumented program intercepts this function when a system library calls it, otherwise the stack might remain poisoned and result in CHECK failures and false positives. Fixes https://github.com/google/sanitizers/issues/721 Reviewed By: eugenis Differential Revision: https://reviews.llvm.org/D32408 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@302152 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-20[asan] Add __strdup interceptor.Evgeniy Stepanov
This happens on Linux when building as C (not C++) with optimization. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@266931 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-23[sanitizer] Add strnlen to the common interceptorsDerek Bruening
Summary: Adds strnlen to the common interceptors, under the existing flag intercept_strlen. Removes the now-duplicate strnlen interceptor from asan and msan. This adds strnlen to tsan, which previously did not intercept it. Adds a new test of strnlen to the sanitizer_common test cases. Reviewers: samsonov Subscribers: zhaoqin, llvm-commits, kcc Differential Revision: http://reviews.llvm.org/D18397 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@264195 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-22[asan] Intercept strdup on WindowsReid Kleckner
Some unit tests were failing because we didn't intercept strdup. It turns out it works just fine on 2013 and 2015 with a small patch to the interception logic. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@264013 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-22[asan] Versioned interceptor for pthread_create.Evgeniy Stepanov
This fixes a crash in pthread_create on linux/i386 due to abi incompatibility between intercepted and non-intercepted functions. See the test case for more details. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@248325 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-16[ASan] NFC: Factor out platform-specific interceptorsTimur Iskhodzhanov
Reviewed at http://reviews.llvm.org/D8321 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@232377 91177308-0d34-0410-b5e6-96231b3b80d8
2014-11-18[msan] Remove MSanDR and supporting code.Evgeniy Stepanov
MSanDR is a dynamic instrumentation tool that can instrument the code (prebuilt libraries and such) that could not be instrumented at compile time. This code is unused (to the best of our knowledge) and unmaintained, and starting to bit-rot. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@222232 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-25[sanitizer] move mlock interceptor from asan/tsan/msan to common; no ↵Kostya Serebryany
functionality change intended git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@216407 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-21Follow-up for r215436: use SIZE_T for strlen and wcslen interceptors.Alexander Potapenko
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@216184 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-12[ASan] Use more appropriate return types for strlen/wcslen to avoid MSVC ↵Timur Iskhodzhanov
warnings git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@215436 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-03[asan] i686-linux-android support.Evgeniy Stepanov
Large part of this change is required due to https://code.google.com/p/android/issues/detail?id=61799 dlsym() crashes when symbol resolution fails, which means we have to limit the interceptor list instead of relying on runtime detection. There are minor differencies in system headers, too. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@212273 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-04[sancov] Handle fork.Evgeniy Stepanov
Reset coverage data on fork(). For memory-mapped mode (coverage_direct=1) this helps avoid loss of data (before this change two processes would write to the same file simultaneously). For normal mode, this reduces coverage dump size, because PCs from the parent process are no longer inherited by the child. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@210180 91177308-0d34-0410-b5e6-96231b3b80d8
2014-05-14[asan] use some LIKELY/UNLIKELYKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@208776 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-04A set of trivial changes to support sanitizers on FreeBSD.Alexey Samsonov
Patch by Viktor Kutuzov! git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@202801 91177308-0d34-0410-b5e6-96231b3b80d8
2014-02-13[asan] Enable signal and sigaction interceptors on Android.Evgeniy Stepanov
Fixes AddressSanitizer.SignalTest breakage. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@201330 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-16[asan] Fix a bunch of style issues.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@199380 91177308-0d34-0410-b5e6-96231b3b80d8
2013-12-26[ASan] Delete asan_intercepted_functions.h, move the code into ↵Alexander Potapenko
asan_interceptors.h Fixes https://code.google.com/p/address-sanitizer/issues/detail?id=188. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@198048 91177308-0d34-0410-b5e6-96231b3b80d8
2013-12-20[sanitizer] Use the new sanitizer_interception.h header in all interceptors.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@197808 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-05[ASan] Delete the code related to static runtime on OS X.Alexander Potapenko
Nuke lib/interception/mach_override. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@174383 91177308-0d34-0410-b5e6-96231b3b80d8
2012-08-24If the program is linked to a dynamic ASan runtime which is not present in ↵Alexander Potapenko
DYLD_INSERT_LIBRARIES (which, in turn, is required for our interceptors to take effect), re-exec the program with DYLD_INSERT_LIBRARIES set. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@162547 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-25Lots of trivial changes to remove extraneous semicolons throughout ASan.Chandler Carruth
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@159128 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-15[Sanitizer] move all the rest re-implementations of libc functions from ASan ↵Alexey Samsonov
runtime to common sanitizer runtime git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@158519 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-15[Sanitizer] Use DEFINE_REAL macro in TSan runtime to call libc ↵Alexey Samsonov
implementations of functions. Move strchr to sanitizer_libc. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@158517 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-14[Sanitizer] Move internal_memcmp to common sanitizer libcAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@158450 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-08[Sanitizer] add internal_memset and internal_strrchr to sanitizer_common/Alexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@158202 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-06[Sanitizer] Move more functions/constants to sanitizer_common.Alexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@158056 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-05[Sanitizer] add sanitizer_posix.cc. Move more various functions into ↵Alexey Samsonov
sanitizer_libc: sscanf, munmap, memchr git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@157994 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-04[Sanitizer]: move internal_strcmp to sanitizer_commonAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@157926 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-04[Sanitizer] Move internal_strncpy to sanitizer_libc (and make its behavior ↵Alexey Samsonov
conforming to manual) git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@157922 91177308-0d34-0410-b5e6-96231b3b80d8
2012-05-31[asan] more renamingKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@157747 91177308-0d34-0410-b5e6-96231b3b80d8
2012-05-31[asan] more renamingKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@157746 91177308-0d34-0410-b5e6-96231b3b80d8
2012-03-29Add internal_memset and replace the uses of REAL(memset) with it where the ↵Alexander Potapenko
performance allows. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@153641 91177308-0d34-0410-b5e6-96231b3b80d8
2012-03-21[asan] merge mac-specific interceptors into one functionAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@153180 91177308-0d34-0410-b5e6-96231b3b80d8
2012-03-21[asan]: remove asan_mac.hAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@153179 91177308-0d34-0410-b5e6-96231b3b80d8