summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/hwasan
Commit message (Collapse)AuthorAgeFilesLines
...
* [hwasan] Allow optional early shadow setup.Evgeniy Stepanov2018-08-134-13/+36
| | | | | | | | | | | | | | | | Summary: Provide __hwasan_shadow_init that can be used to initialize shadow w/o touching libc. It can be used to bootstrap an unusual case of fully-static executable with hwasan-instrumented libc, which needs to run hwasan code before it is ready to serve user calls like madvise(). Reviewers: vitalybuka, kcc Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D50581 llvm-svn: 339606
* [hwasan] Remove liblog dependency.Evgeniy Stepanov2018-08-101-1/+0
| | | | | | | | | | | | | | | | HWASan will not run on older Android releases where we use __android_log_write for logging. This dependency is also harmful in the case when libc itself depends on hwasan, because it creates a loop of libc -> hwasan -> liblog -> libc which makes liblog vs libc initialization order undetermined. Without liblog the loop is just libc -> hwasan -> libc and any init order issues can be solved in hwasan. llvm-svn: 339449
* sanitizers: consistently check result of MmapFixedNoReserveDmitry Vyukov2018-07-201-2/+1
| | | | | | | | | | | | | | | | MmapFixedNoReserve does not terminate process on failure. Failure to check its result and die will always lead to harder to debug crashes later in execution. This was observed in Go processes due to some address space conflicts. Consistently check result of MmapFixedNoReserve. While we are here also add warn_unused_result attribute to prevent such bugs in future and change return type to bool as that's what all callers want. Reviewed in https://reviews.llvm.org/D49367 llvm-svn: 337531
* [sanitizer] Use -Wl,-z,global on AndroidKostya Kortchinsky2018-07-131-14/+0
| | | | | | | | | | | | | | | | | | | | | | | Summary: Use `-Wl,-z,global` for all Sanitizer shared libraries on Android. We want them to be in the global group (https://android.googlesource.com/platform/bionic/+/master/android-changes-for-ndk-developers.md#changes-to-library-search-order) to avoid any alloc/dealloc mismatch between the libc allocator & said library. `audioserver` was one of the binary that exhibited the problem with Scudo, this seems to fix it. [edited for accuracy] Reviewers: eugenis, alekseyshl Reviewed By: eugenis Subscribers: kubamracek, srhines, mgorny, delcypher, #sanitizers, llvm-commits Differential Revision: https://reviews.llvm.org/D49198 llvm-svn: 337010
* [CMake] Fix a typo in the variable used to retrieve source file namesDan Liew2018-07-121-2/+1
| | | | | | | | for the `RTHwasan_dynamic` target. Differential Revision: https://reviews.llvm.org/D49178 llvm-svn: 336944
* [CMake] Add compiler-rt header files to the list of sources for targetsDan Liew2018-07-101-2/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | when building with an IDE so that header files show up in the UI. This massively improves the development workflow in IDEs. To implement this a new function `compiler_rt_process_sources(...)` has been added that adds header files to the list of sources when the generator is an IDE. For non-IDE generators (e.g. Ninja/Makefile) no changes are made to the list of source files. The function can be passed a list of headers via the `ADDITIONAL_HEADERS` argument. For each runtime library a list of explicit header files has been added and passed via `ADDITIONAL_HEADERS`. For `tsan` and `sanitizer_common` a list of headers was already present but it was stale and has been updated to reflect the current state of the source tree. The original version of this patch used file globbing (`*.{h,inc,def}`) to find the headers but the approach was changed due to this being a CMake anti-pattern (if the list of headers changes CMake won't automatically re-generate if globbing is used). The LLVM repo contains a similar function named `llvm_process_sources()` but we don't use it here for several reasons: * It depends on the `LLVM_ENABLE_OPTION` cache variable which is not set in standalone compiler-rt builds. * We would have to `include(LLVMProcessSources)` which I'd like to avoid because it would include a bunch of stuff we don't need. Differential Revision: https://reviews.llvm.org/D48422 llvm-svn: 336663
* [HWASan] Initalize shadow earler.Alex Shlyapnikov2018-06-251-4/+4
| | | | | | | | | | | | | | Summary: Initialize shadow memory before calling more libc functions to allow for HWASan-instrumented libc. Reviewers: eugenis Subscribers: kubamracek, delcypher, #sanitizers, llvm-commits Differential Revision: https://reviews.llvm.org/D48551 llvm-svn: 335502
* [HWASan] Report proper error on allocator failures instead of CHECK(0)-ingAlex Shlyapnikov2018-06-078-35/+89
| | | | | | | | | | | | | | | | Summary: Currently many allocator specific errors (OOM, for example) are reported as a text message and CHECK(0) termination, not stack, no details, not too helpful nor informative. To improve the situation, detailed and structured errors were defined and reported under the appropriate conditions. Reviewers: eugenis Subscribers: kubamracek, delcypher, llvm-commits, #sanitizers Differential Revision: https://reviews.llvm.org/D47798 llvm-svn: 334248
* [CMake] Build shared version of runtimes for FuchsiaPetr Hosek2018-05-091-1/+1
| | | | | | | | | Fuchsia is no longer treated as UNIX which means we need to explicitly enable building of shared versions of runtimes. Differential Revision: https://reviews.llvm.org/D46609 llvm-svn: 331922
* [sanitizer] Remove unneeded blank linesVitaly Buka2018-05-091-1/+0
| | | | llvm-svn: 331831
* [sanitizer] Update .clang-format in compiler-rtVitaly Buka2018-05-091-0/+2
| | | | | | Historically style is Google, but we never used AllowShortIfStatementsOnASingleLine. llvm-svn: 331829
* [sanitizer] Replace InternalScopedBuffer with InternalMmapVectorVitaly Buka2018-05-071-1/+1
| | | | llvm-svn: 331618
* [HWASan] Use dynamic shadow memory on Android only.Alex Shlyapnikov2018-04-241-3/+3
| | | | | | | | There're issues with IFUNC support on other platforms. Differential Revision: https://reviews.llvm.org/D45847 llvm-svn: 330666
* [HWASan] Add files missing in r330624Alex Shlyapnikov2018-04-233-0/+244
| | | | llvm-svn: 330628
* [HWASan] Introduce non-zero based and dynamic shadow memory (compiler-rt).Alex Shlyapnikov2018-04-2310-70/+169
| | | | | | | | | | | | | | | Retire the fixed shadow memory mapping to avoid conflicts with default process memory mapping (currently manifests on Android). Tests on AArch64 show <1% performance loss and code size increase, making it possible to use dynamic shadow memory by default. Keep the fixed shadow memory mapping around to be able to run performance comparison tests later. Re-commiting D45847 with fixed shadow for x86-64. llvm-svn: 330624
* Revert r330474 - "[HWASan] Introduce non-zero based and dynamic shadow ↵Reid Kleckner2018-04-2313-409/+70
| | | | | | | | | | | | | | | memory (compiler-rt)." This commit causes internal errors with ld.bfd 2.24. My guess is that the ifunc usage in this commit is causing problems. This is the default system linker on Trusty Tahr, which is from 2014. I claim it's still in our support window. Maybe we will decide to drop support for it, but let's get the bots green while we do the investigation and have that discussion. Discovered here: https://crbug.com/835864 llvm-svn: 330619
* [HWASan] Introduce non-zero based and dynamic shadow memory (compiler-rt).Alex Shlyapnikov2018-04-2013-70/+409
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: Retire the fixed shadow memory mapping to avoid conflicts with default process memory mapping (currently manifests on Android). Tests on AArch64 show <1% performance loss and code size increase, making it possible to use dynamic shadow memory by default. For the simplicity and unifirmity sake, use dynamic shadow memory mapping with base address accessed via ifunc resolver on all supported platforms. Keep the fixed shadow memory mapping around to be able to run performance comparison tests later. Complementing D45840. Reviewers: eugenis Subscribers: srhines, kubamracek, dberris, mgorny, kristof.beyls, delcypher, #sanitizers, llvm-commits Differential Revision: https://reviews.llvm.org/D45847 llvm-svn: 330474
* [HWASan] Add "N" suffix to generic __hwasan_load/store.Alex Shlyapnikov2018-04-182-8/+8
| | | | | | | | | | | | | | | Summary: "N" suffix is added by the instrumentation and interface functions are expected to be exported from the library as __hwasan_loadN* and __hwasan_storeN*. Reviewers: eugenis Subscribers: kubamracek, delcypher, #sanitizers, llvm-commits Differential Revision: https://reviews.llvm.org/D45739 llvm-svn: 330297
* [sanitizer] Split Symbolizer/StackTraces from core RTSanitizerCommonKostya Kortchinsky2018-04-161-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 llvm-svn: 330131
* Remove duplicated const qualifier.Alex Shlyapnikov2018-03-241-1/+1
| | | | llvm-svn: 328403
* [HWASan] Port HWASan to Linux x86-64 (compiler-rt)Alex Shlyapnikov2018-03-235-42/+95
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Porting HWASan to Linux x86-64, first of the three patches, compiler-rt part. The approach is similar to ARM case, trap signal is used to communicate memory tag check failure. int3 instruction is used to generate a signal, access parameters are stored in nop [eax + offset] instruction immediately following the int3 one Had to add HWASan init on malloc because, due to much less interceptors defined (most other sanitizers intercept much more and get initalized via one of those interceptors or don't care about malloc), HWASan was not initialized yet when libstdc++ was trying to allocate memory for its own fixed-size heap, which led to CHECK-fail in AllocateFromLocalPool. Also added the CHECK() failure handler with more detailed message and stack reporting. Reviewers: eugenis Subscribers: kubamracek, dberris, mgorny, kristof.beyls, delcypher, #sanitizers, llvm-commits Differential Revision: https://reviews.llvm.org/D44705 llvm-svn: 328385
* [sanitizer] Split coverage into separate RT in sanitizer_commonKostya Kortchinsky2018-03-221-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: `sanitizer_common`'s coverage support is fairly well separated, and libcdep by default. Several sanitizers don't make use of coverage, and as far as I can tell do no benefit from the extra dependencies pulled in by the coverage public interface functions. The following sanitizers call `InitializeCoverage` explicitely: MSan, ASan, LSan, HWAsan, UBSan. On top of this, any sanitizer bundling RTUBSan should add the coverage RT as well: ASan, Scudo, UBSan, CFI (diag), TSan, MSan, HWAsan. So in the end the following have no need: DFSan, ESan, CFI, SafeStack (nolibc anyway), XRay, and the upcoming Scudo minimal runtime. I tested this with all the sanitizers check-* with gcc & clang, and in standalone on Linux & Android, and there was no issue. I couldn't test this on Mac, Fuchsia, BSDs, & Windows for lack of an environment, so adding a bunch of people for additional scrunity. I couldn't test HWAsan either. Reviewers: eugenis, vitalybuka, alekseyshl, flowerhack, kubamracek, dberris, rnk, krytarowski Reviewed By: vitalybuka, alekseyshl, flowerhack, dberris Subscribers: mgorny, delcypher, #sanitizers, llvm-commits Differential Revision: https://reviews.llvm.org/D44701 llvm-svn: 328204
* Attempt to appease buildbotsGeorge Burgess IV2018-03-071-1/+1
| | | | | | | | | | | I can't reproduce this build error locally, but it appears straightforward enough to fix. r326851 renamed two of the params of this interceptor, but apparently to update their use here. Failure: http://lab.llvm.org:8011/builders/clang-cmake-aarch64-full/builds/4569 llvm-svn: 326876
* [sanitizer] Move mmap interceptors into sanitizer_commonVitaly Buka2018-03-071-30/+11
| | | | | | | | | | Reviewers: devnexen, krytarowski, eugenis Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D44125 llvm-svn: 326851
* [hwasan] Fix inline instrumentation.Evgeniy Stepanov2018-02-212-10/+10
| | | | | | | | | | | | | | | 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 llvm-svn: 325711
* Add NetBSD syscall hooks skeleton in sanitizersKamil Rytarowski2018-02-151-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Implement the skeleton of NetBSD syscall hooks for use with sanitizers. Add a script that generates the rules to handle syscalls on NetBSD: generate_netbsd_syscalls.awk. It has been written in NetBSD awk(1) (patched nawk) and is compatible with gawk. Generate lib/sanitizer_common/sanitizer_platform_limits_netbsd.h that is a public header for applications, and included as: <sanitizer_common/sanitizer_platform_limits_netbsd.h>. Generate sanitizer_syscalls_netbsd.inc that defines all the syscall rules for NetBSD. This file is modeled after the Linux specific file: sanitizer_common_syscalls.inc. Start recognizing NetBSD syscalls with existing sanitizers: ASan, ESan, HWASan, TSan, MSan. Sponsored by <The NetBSD Foundation> Reviewers: joerg, vitalybuka, kcc, dvyukov, eugenis Reviewed By: vitalybuka Subscribers: hintonda, kubamracek, mgorny, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D42048 llvm-svn: 325206
* [Sanitizers] Changes in Hwasan allocator missed in D42198.Alex Shlyapnikov2018-01-181-5/+5
| | | | | | Converting a few failure handler calls missed in D42198. llvm-svn: 322793
* [Sanitizers] Make common allocator agnostic to failure handling modes.Alex Shlyapnikov2018-01-171-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Make common allocator agnostic to failure handling modes and move the decision up to the particular sanitizer's allocator, where the context is available (call stack, parameters, return nullptr/crash mode etc.) It simplifies the common allocator and allows the particular sanitizer's allocator to generate more specific and detailed error reports (which will be implemented later). The behavior is largely the same, except one case, the violation of the common allocator's check for "size + alignment" overflow is now reportied as OOM instead of "bad request". It feels like a worthy tradeoff and "size + alignment" is huge in this case anyway (thus, can be interpreted as not enough memory to satisfy the request). There's also a Report() statement added there. Reviewers: eugenis Subscribers: kubamracek, llvm-commits, #sanitizers Differential Revision: https://reviews.llvm.org/D42198 llvm-svn: 322784
* [hwasan] Build runtime library with -fPIC, not -fPIE.Evgeniy Stepanov2018-01-161-1/+1
| | | | | | | | | | | | Summary: -fPIE can not be used when building a shared library. Reviewers: alekseyshl, peter.smith Subscribers: kubamracek, llvm-commits, mgorny Differential Revision: https://reviews.llvm.org/D42121 llvm-svn: 322588
* [hwasan] An LLVM flag to disable stack tag randomization.Evgeniy Stepanov2018-01-132-0/+11
| | | | | | | | | | | | Summary: Necessary to achieve consistent test results. Reviewers: kcc, alekseyshl Subscribers: kubamracek, llvm-commits, hiraditya Differential Revision: https://reviews.llvm.org/D42023 llvm-svn: 322429
* [hwasan] Stack instrumentation.Evgeniy Stepanov2018-01-115-8/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Very basic stack instrumentation using tagged pointers. Tag for N'th alloca in a function is built as XOR of: * base tag for the function, which is just some bits of SP (poor man's random) * small constant which is a function of N. Allocas are aligned to 16 bytes. On every ReturnInst allocas are re-tagged to catch use-after-return. This implementation has a bunch of issues that will be taken care of later: 1. lifetime intrinsics referring to tagged pointers are not recognized in SDAG. This effectively disables stack coloring. 2. Generated code is quite inefficient. There is one extra instruction at each memory access that adds the base tag to the untagged alloca address. It would be better to keep tagged SP in a callee-saved register and address allocas as an offset of that XOR retag, but that needs better coordination between hwasan instrumentation pass and prologue/epilogue insertion. 3. Lifetime instrinsics are ignored and use-after-scope is not implemented. This would be harder to do than in ASan, because we need to use a differently tagged pointer depending on which lifetime.start / lifetime.end the current instruction is dominated / post-dominated. Reviewers: kcc, alekseyshl Subscribers: srhines, kubamracek, javed.absar, hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D41602 llvm-svn: 322324
* [hwasan] An option to disable tag randomization.Evgeniy Stepanov2018-01-102-6/+14
| | | | | | | | | | | | | | | | | | Summary: Avoid flaky test failures by by using a monotonic number sequence of heap tags. Does not affect stack tags: the way we generate those guarantees uniqueness for at least 30-something first allocas in any function, as well as the UAR tag. Reviewers: alekseyshl, kcc Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D41882 llvm-svn: 322214
* [hwasan] Add heap tag randomization.Evgeniy Stepanov2018-01-033-8/+56
| | | | | | | | | | | | | | Summary: Generate tags for heap allocations from a pseudo-random sequence seeded with getrandom(), where available. Reviewers: kcc, alekseyshl Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D41616 llvm-svn: 321761
* [hwasan] Implement -fsanitize-recover=hwaddress.Evgeniy Stepanov2017-12-203-25/+127
| | | | | | | | | | | | Summary: Very similar to AddressSanitizer, with the exception of the error type encoding. Reviewers: kcc, alekseyshl Subscribers: cfe-commits, kubamracek, llvm-commits, hiraditya Differential Revision: https://reviews.llvm.org/D41417 llvm-svn: 321203
* [hwasan] Fix handling of store errors.Evgeniy Stepanov2017-12-191-1/+1
| | | | llvm-svn: 321121
* [hwasan] Inline instrumentation & fixed shadow.Evgeniy Stepanov2017-12-134-81/+128
| | | | | | | | | | | | Summary: This brings CPU overhead on bzip2 down from 5.5x to 2x. Reviewers: kcc, alekseyshl Subscribers: kubamracek, hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D41137 llvm-svn: 320538
* Hardware-assisted AddressSanitizer (compiler-rt)Evgeniy Stepanov2017-12-0919-0/+2274
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 llvm-svn: 320231
OpenPOWER on IntegriCloud