summaryrefslogtreecommitdiff
path: root/lib/msan/msan_allocator.cc
AgeCommit message (Collapse)Author
2015-10-08New MSan mapping layout (compiler-rt part).Evgeniy Stepanov
This is an implementation of https://github.com/google/sanitizers/issues/579 It has a number of advantages over the current mapping: * Works for non-PIE executables. * Does not require ASLR; as a consequence, debugging MSan programs in gdb no longer requires "set disable-randomization off". * Supports linux kernels >=4.1.2. * The code is marginally faster and smaller. This is an ABI break. We never really promised ABI stability, but this patch includes a courtesy escape hatch: a compile-time macro that reverts back to the old mapping layout. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@249754 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-01[compiler-rt] Apply modernize-use-nullptr fixes in sanitizersVedant Kumar
- Trim spaces. - Use nullptr in place of 0 for pointer variables. - Use '!p' in place of 'p == 0' for null pointer checks. - Add blank lines to separate function definitions. - Add 'extern "C"' or 'namespace foo' comments after the appropriate closing brackets This is a continuation of work from 409b7b82. The focus here is on the various sanitizers (not sanitizer_common, as before). Patch by Eugene Zelenko! Differential Revision: http://reviews.llvm.org/D13225 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@248966 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-29[msan] Early allocator initialization.Evgeniy Stepanov
Map MSan heap space early (in __msan_init) so that user code can not accidentally (i.e. w/o MAP_FIXED) create a conflicting mapping. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@248829 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-16[MSan] Enable MSAN for aarch64Adhemerval Zanella
This patch enabled msan for aarch64 with 39-bit VMA and 42-bit VMA. As defined by lib/msan/msan.h the memory layout used is for 39-bit is: 00 0000 0000 - 40 0000 0000: invalid 40 0000 0000 - 43 0000 0000: shadow 43 0000 0000 - 46 0000 0000: origin 46 0000 0000 - 55 0000 0000: invalid 55 0000 0000 - 56 0000 0000: app (low) 56 0000 0000 - 70 0000 0000: invalid 70 0000 0000 - 80 0000 0000: app (high) And for 42-bit VMA: 000 0000 0000 - 100 0000 0000: invalid 100 0000 0000 - 11b 0000 0000: shadow 11b 0000 0000 - 120 0000 0000: invalid 120 0000 0000 - 13b 0000 0000: origin 13b 0000 0000 - 2aa 0000 0000: invalid 2aa 0000 0000 - 2ab 0000 0000: app (low) 2ab 0000 0000 - 3f0 0000 0000: invalid 3f0 0000 0000 - 400 0000 0000: app (high) Most of tests are passing with exception of: * Linux/mallinfo.cc * chained_origin_limits.cc * dlerror.cc * param_tls_limit.cc * signal_stress_test.cc * nonnull-arg.cpp The 'Linux/mallinfo.cc' is due the fact AArch64 returns the sret in 'x8' instead of default first argument 'x1'. So a function prototype that aims to mimic (by using first argument as the return of function) won't work. For GCC one can make a register alias (register var asm ("r8")), but for clang it detects is an unused variable and generate wrong code. The 'chained_origin_limits' is probably due a wrong code generation, since it fails only when origin memory is used (-fsanitize-memory-track-origins=2) and only in the returned code (return buf[50]). The 'signal_streess_test' and 'nonnull-arg' are due currently missing variadic argument handling in memory sanitizer code instrumentation on LLVM side. Both 'dlerror' and 'param_tls_test' are unknown failures that require further investigation. All the failures are XFAIL for aarch64 for now. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@247809 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-25Enable memory sanitizer for PPC64Jay Foad
Summary: This patch adds basic memory sanitizer support for PPC64. PR23219. I have further patches ready to enable it in LLVM and Clang, and to fix most of the many failing tests in check-msan. Reviewers: kcc, willschm, samsonov, wschmidt, eugenis Reviewed By: eugenis Subscribers: wschmidt, llvm-commits Differential Revision: http://reviews.llvm.org/D10648 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@240623 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-22[msan] Better use-after-free reports.Evgeniy Stepanov
By attaching an extra integer tag to heap origins, we are able to distinguish between uninits - created by heap allocation, - created by heap deallocation (i.e. use-after-free), - created by __msan_allocated_memory call, - etc. See https://code.google.com/p/memory-sanitizer/issues/detail?id=35. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@226821 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-21[msan] Fix origins in realloc.Evgeniy Stepanov
Fixes 2 issues in origins arising from realloc() calls: * In the in-place grow case origin for the new memory is not set at all. * In the copy-realloc case __msan_memcpy is used, which unwinds stack from inside the MSan runtime. This does not generally work (as we may be built w/o frame pointers), and produces "bad" stack trace anyway, with several uninteresting (internal) frames on top. This change also makes realloc() honor "zeroise" and "poison_in_malloc" flags. See https://code.google.com/p/memory-sanitizer/issues/detail?id=73. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@226674 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-12[Sanitizer] Introduce Allocator::may_return_null bool flag.Alexey Samsonov
Summary: Turn "allocator_may_return_null" common flag into an Allocator::may_return_null bool flag. We want to make sure that common flags are immutable after initialization. There are cases when we want to change this flag in the allocator at runtime: e.g. in unit tests and during ASan activation on Android. Test Plan: regression test suite, real-life applications Reviewers: kcc, eugenis Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D6623 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@224148 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-03[msan] Change the way origin ids are built.Evgeniy Stepanov
Previously, all origin ids were "chained" origins, i.e values of ChainedOriginDepot. This added a level of indirection for simple stack and heap allocation, which were represented as chains of length 1. This costs both RAM and CPU, but provides a joined 2**29 origin id space. It also made function (any instrumented function) entry non-async-signal-safe, but that does not really matter because memory stores in track-origins=2 mode are not async-signal-safe anyway. With this change, the type of the origin is encoded in origin id. See comment in msan_origin.h for more details. This reduces chained and stack origin id range to 2**28 each, but leaves extra 2**31 for heap origins. This change should not have any user-visible effects. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@223233 91177308-0d34-0410-b5e6-96231b3b80d8
2014-11-19[MSan] [MIPS] Adding support for MIPS64 (patch by Mohit Bhakkad).Alexey Samsonov
Reviewed at http://reviews.llvm.org/D5906 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@222388 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-26Change StackDepot interface to use StackTrace more extensivelyAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@220637 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-12[Sanitizer] Kill deprecated allocator interfaces in ASan, MSan and TSan in ↵Alexey Samsonov
favor of a unified interface in <sanitizer/allocator_interface.h>. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@215469 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-07Generalize sanitizer allocator public interface.Alexey Samsonov
Introduce new public header <sanitizer/allocator_interface.h> and a set of functions __sanitizer_get_ownership(), __sanitizer_malloc_hook() etc. that will eventually replace their tool-specific equivalents (__asan_get_ownership(), __msan_get_ownership() etc.). Tool-specific functions are now deprecated and implemented as stubs redirecting to __sanitizer_ versions (which are implemented differently in each tool). Replace all uses of __xsan_ versions with __sanitizer_ versions in unit and lit tests. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@212469 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-04[msan] Reformat one source file.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@212329 91177308-0d34-0410-b5e6-96231b3b80d8
2014-05-28tsan: do not use 64-bit atomics in allocator codeDmitry Vyukov
64-bit atomics make porting of asan to 32-bits platforms problematic. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@209744 91177308-0d34-0410-b5e6-96231b3b80d8
2014-05-21[msan] Chained origins re-design.Evgeniy Stepanov
Generalize StackDepot and create a new specialized instance of it to efficiently (i.e. without duplicating stack trace data) store the origin history tree. This reduces memory usage for chained origins roughly by an order of magnitude. Most importantly, this new design allows us to put two limits on stored history data (exposed in MSAN_OPTIONS) that help avoid exponential growth in used memory on certain workloads. See comments in lib/msan/msan_origin.h for more details. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@209284 91177308-0d34-0410-b5e6-96231b3b80d8
2014-04-04[msan] Introduce MsanThread. Move thread-local allocator cache out of TLS.Evgeniy Stepanov
This reduces .tbss from 109K down to almost nothing. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@205618 91177308-0d34-0410-b5e6-96231b3b80d8
2013-11-20[msan] Unpoison memory that is returned to the OS and flush its shadow.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@195244 91177308-0d34-0410-b5e6-96231b3b80d8
2013-10-22[msan] Drain allocator cache when leaving thread.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@193163 91177308-0d34-0410-b5e6-96231b3b80d8
2013-10-15[msan] Implement allocator_may_return_null=1 in MemorySanitizer.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@192687 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-16[msan] Fix origin of deallocated memory.Evgeniy Stepanov
MSan poisons deallocated memory but it used to give it an invalid origin value, resulting in confusing reports. This change associates deallocation stack trace with such memory. Note that MSan does not have quarantine, and use-after-free detection is very limited. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@190781 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-10[msan] bool -> int to make msan_interface.h C-compatible.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@190402 91177308-0d34-0410-b5e6-96231b3b80d8
2013-08-02[msan] Allocator statistics interface and malloc hooks.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@187653 91177308-0d34-0410-b5e6-96231b3b80d8
2012-12-12[sanitizer] add OnMap/OnUmap callbacks to the allocator interfaceKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@169985 91177308-0d34-0410-b5e6-96231b3b80d8
2012-12-11[msan] MemorySanitizer runtime.Evgeniy Stepanov
Initial commit of the MemorySanitizer runtime library. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@169858 91177308-0d34-0410-b5e6-96231b3b80d8