summaryrefslogtreecommitdiff
path: root/lib/msan/msan_linux.cc
AgeCommit message (Collapse)Author
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-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
2016-08-25msan: Enable 48-bit VMA support on aarch64Adhemerval Zanella
This patch adds 48-bits VMA support for msan on aarch64. As current mappings for aarch64, 48-bit VMA also supports PIE executable. The 48-bits segments only cover the usual PIE/default segments plus some more segments (262144GB total, 0.39% total VMA). Memory avaliability can be increase by adding multiple application segments like 39 and 42 mapping (some mappings were added on this patch as well). Tested on 39 and 48-bit VMA kernels on aarch64. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@279752 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-22[sanitizer] rename MmapNoAccess to MmapFixedNoAccess; NFCKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@267253 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-29[compiler-rt] [msan] Unify aarch64 mappingAdhemerval Zanella
This patch unify the 39-bit and 42-bit mapping for aarch64 to use only one instrumentation algorithm. A runtime check avoid mapping 42-bit only segments for 39-bit kernels. The mapping to use now is for 39 and 42-bits: 0x00000000000ULL-0x01000000000ULL MappingDesc::INVALID 0x01000000000ULL-0x02000000000ULL MappingDesc::SHADOW 0x02000000000ULL-0x03000000000ULL MappingDesc::ORIGIN 0x03000000000ULL-0x04000000000ULL MappingDesc::SHADOW 0x04000000000ULL-0x05000000000ULL MappingDesc::ORIGIN 0x05000000000ULL-0x06000000000ULL MappingDesc::APP 0x06000000000ULL-0x07000000000ULL MappingDesc::INVALID 0x07000000000ULL-0x08000000000ULL MappingDesc::APP And only for 42-bits: 0x08000000000ULL-0x09000000000ULL MappingDesc::INVALID 0x09000000000ULL-0x0A000000000ULL MappingDesc::SHADOW 0x0A000000000ULL-0x0B000000000ULL MappingDesc::ORIGIN 0x0B000000000ULL-0x0F000000000ULL MappingDesc::INVALID 0x0F000000000ULL-0x10000000000ULL MappingDesc::APP 0x10000000000ULL-0x11000000000ULL MappingDesc::INVALID 0x11000000000ULL-0x12000000000ULL MappingDesc::APP 0x12000000000ULL-0x17000000000ULL MappingDesc::INVALID 0x17000000000ULL-0x18000000000ULL MappingDesc::SHADOW 0x18000000000ULL-0x19000000000ULL MappingDesc::ORIGIN 0x19000000000ULL-0x20000000000ULL MappingDesc::INVALID 0x20000000000ULL-0x21000000000ULL MappingDesc::APP 0x21000000000ULL-0x26000000000ULL MappingDesc::INVALID 0x26000000000ULL-0x27000000000ULL MappingDesc::SHADOW 0x27000000000ULL-0x28000000000ULL MappingDesc::ORIGIN 0x28000000000ULL-0x29000000000ULL MappingDesc::SHADOW 0x29000000000ULL-0x2A000000000ULL MappingDesc::ORIGIN 0x2A000000000ULL-0x2B000000000ULL MappingDesc::APP 0x2B000000000ULL-0x2C000000000ULL MappingDesc::INVALID 0x2C000000000ULL-0x2D000000000ULL MappingDesc::SHADOW 0x2D000000000ULL-0x2E000000000ULL MappingDesc::ORIGIN 0x2E000000000ULL-0x2F000000000ULL MappingDesc::APP 0x2F000000000ULL-0x39000000000ULL MappingDesc::INVALID 0x39000000000ULL-0x3A000000000ULL MappingDesc::SHADOW 0x3A000000000ULL-0x3B000000000ULL MappingDesc::ORIGIN 0x3B000000000ULL-0x3C000000000ULL MappingDesc::APP 0x3C000000000ULL-0x3D000000000ULL MappingDesc::INVALID 0x3D000000000ULL-0x3E000000000ULL MappingDesc::SHADOW 0x3E000000000ULL-0x3F000000000ULL MappingDesc::ORIGIN 0x3F000000000ULL-0x40000000000ULL MappingDesc::APP And although complex it provides a better memory utilization that previous one. [1] http://reviews.llvm.org/D13817 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@251625 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-08-24[Sanitizer] Dump coverage if we're killing the program with __sanitizer::Die().Alexey Samsonov
Previously we had to call __sanitizer_cov_dump() from tool-specific callbacks - instead, let sanitizer_common library handle this in a single place. This is a re-application of r245770, with slightly different approach taken. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@245890 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-22Revert r245770 and r245777.Alexey Samsonov
These changes break both autoconf Mac OS X buildbot (linker errors due to wrong Makefiles) and CMake buildbot (safestack test failures). git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@245784 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-22[Sanitizer] Dump coverage if we're killing the program with __sanitizer::Die().Alexey Samsonov
Previously we had to call __sanitizer_cov_dump() from tool-specific callbacks - instead, let sanitizer_common library handle this in a single place. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@245770 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-21[MSan] Deprecate __msan_set_death_callback() in favor of ↵Alexey Samsonov
__sanitizer_set_death_callback(). git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@245754 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-21[Sanitizers] Unify the semantics and usage of "exitcode" runtime flag across ↵Alexey Samsonov
all sanitizers. Summary: Merge "exitcode" flag from ASan, LSan, TSan and "exit_code" from MSan into one entity. Additionally, make sure sanitizer_common now uses the value of common_flags()->exitcode when dying on error, so that this flag will automatically work for other sanitizers (UBSan and DFSan) as well. User-visible changes: * "exit_code" MSan runtime flag is now deprecated. If explicitly specified, this flag will take precedence over "exitcode". The users are encouraged to migrate to the new version. * __asan_set_error_exit_code() and __msan_set_exit_code() functions are removed. With few exceptions, we don't support changing runtime flags during program execution - we can't make them thread-safe. The users should use __sanitizer_set_death_callback() that would call _exit() with proper exit code instead. * Plugin tools (LSan and UBSan) now inherit the exit code of the parent tool. In particular, this means that ASan would now crash the program with exit code "1" instead of "23" if it detects leaks. Reviewers: kcc, eugenis Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D12120 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@245734 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-29Add descriptive names to sanitizer entries in /proc/self/maps. Helps debugging.Evgeniy Stepanov
This is done by creating a named shared memory region, unlinking it and setting up a private (i.e. copy-on-write) mapping of that instead of a regular anonymous mapping. I've experimented with regular (sparse) files, but they can not be scaled to the size of MSan shadow mapping, at least on Linux/X86_64 and ext3 fs. Controlled by a common flag, decorate_proc_maps, disabled by default. This patch has a few shortcomings: * not all mappings are annotated, especially in TSan. * our handling of memset() of shadow via mmap() puts small anonymous mappings inside larger named mappings, which looks ugly and can, in theory, hit the mapping number limit. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@238621 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-24[msan] Mprotect all inaccessible memory regions.Evgeniy Stepanov
Fix 2 bugs in memory mapping setup: - the invalid region at offset 0 was not protected because mmap at address 0 fails with EPERM on most Linux systems. We did not notice this because the check condition was flipped: the code was checking that mprotect has failed. And the test that was supposed to catch this was weakened by the mitigations in the mmap interceptor. - when running without origins, the origin shadow range was left unprotected. The new test ensures that mmap w/o MAP_FIXED always returns valid application addresses. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@238109 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-10Split Mprotect into MmapNoAccess and MprotectNoAccess to be more portableTimur Iskhodzhanov
On Windows, we have to know if a memory to be protected is mapped or not. On POSIX, Mprotect was semantically different from mprotect most people know. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@234602 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-03[ASan] Add use_madv_dontdump flag.Yury Gribov
Differential Revision: http://reviews.llvm.org/D7294 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@227959 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-27[msan] Refactor memory layout specification and setup.Evgeniy Stepanov
A flexible way of describing MSan memory layout details on various platforms. No significant functional changes, but the memory layout description that you get at verbosity=1 looks slightly different. This change includes stronger sanity checks than before. The goal of this change is to allow more than 2 application memory ranges for https://code.google.com/p/memory-sanitizer/issues/detail?id=76. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@227192 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-19[msan] Use internal__exit() instead of _exit().Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@226437 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-17[msan] Stop calling pthread_getspecific in signal handlers.Evgeniy Stepanov
pthread_getspecific is not async-signal-safe. MsanThread pointer is now stored in a TLS variable, and the TSD slot is used only for its destructor, and never from a signal handler. This should fix intermittent CHECK failures in MsanTSDSet. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@224423 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-03[msan] allow -fsanitize-coverage=N together with -fsanitize=memory, ↵Kostya Serebryany
compiler-rt part git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@223314 91177308-0d34-0410-b5e6-96231b3b80d8
2014-11-28[Msan] Generalize mapping facilities to add FreeBSD supportViktor Kutuzov
Differential Revision: http://reviews.llvm.org/D6387 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@222919 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-06-24[msan] Print stats even on successful run with atexit=1.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@211574 91177308-0d34-0410-b5e6-96231b3b80d8
2014-05-21[msan] Implement MSAN_OPTIONS=print_stats=1.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@209287 91177308-0d34-0410-b5e6-96231b3b80d8
2014-04-11[msan] mprotect() more memory to detect user code outside of application range.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@206028 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
2014-03-27[msan] Implement __msan_set_death_callback.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@204926 91177308-0d34-0410-b5e6-96231b3b80d8
2013-12-05[sanitizer] Introduce VReport and VPrintf macros and use them in sanitizer code.Sergey Matveev
Instead of "if (common_flags()->verbosity) Report(...)" we now have macros. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@196497 91177308-0d34-0410-b5e6-96231b3b80d8
2013-11-11[msan] Sanity check for non-PIE.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@194370 91177308-0d34-0410-b5e6-96231b3b80d8
2013-10-15tsan: move verbosity flag to CommonFlagsDmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@192701 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-29Move UnpoisonMappedDSO to sanitizer_common.Peter Collingbourne
This is so DFSan will be able to use it. Differential Revision: http://llvm-reviews.chandlerc.com/D1206 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@187372 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-19[sanitizer] Replace more platform checks with SANITIZER_ constants.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@177400 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-12[msan] Use sptr instead of ptrdiff_t.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@176854 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-11[msan] intercept dlopen and clear shadow for itReid Kleckner
Summary: The loader does not call mmap() through the PLT because it has to bootstrap the process before libc is present. Hooking dlopen() isn't enough either because the loader runs module initializers before returning, and they could run arbitrary msan instrumented code. If msandr is present, then we can intercept the mmaps from dlopen at the syscall layer and clear the shadow there. If msandr is missing, we clear the shadow after dlopen() and hope any initializers are trivial. Reviewers: eugenis CC: kcc, llvm-commits Differential Revision: http://llvm-reviews.chandlerc.com/D509 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@176818 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-30[Sanitizer] update style checker script and fix namespace style warningsAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@173910 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-22[msan] Remove the trap handler code.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@173161 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-10[sanitizer] better statistics for the large allocatorKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@172069 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-10[msan] Set program exit code in keep-going mode.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@172057 91177308-0d34-0410-b5e6-96231b3b80d8
2012-12-26[msan] Check for conflicting memory mappings.Evgeniy Stepanov
Check for conflicting memory mappings before attempting to map shadow. Helps avoid segfault on Linux with disabled ASLR. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@171100 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