Commit Graph

64 Commits

Author SHA1 Message Date
Adhemerval Zanella 1005b7d90c msan: Enable 48-bit VMA support on aarch64
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.

llvm-svn: 279752
2016-08-25 17:05:56 +00:00
Sagar Thakur 49307c0297 [MSAN][MIPS] Changed memory mapping to support pie executable.
Reviewed by eugenis
Differential: D22993

llvm-svn: 278793
2016-08-16 12:49:54 +00:00
Kostya Serebryany bf6a04fde8 [sanitizers] introduce yet another API function: __sanitizer_install_malloc_and_free_hooks
llvm-svn: 272943
2016-06-16 20:06:06 +00:00
Marcin Koscielnicki 3f9d7a217d [sanitizers] [NFC] Add defines for the various PowerPC ABIs.
Differential Revision: http://reviews.llvm.org/D19542

llvm-svn: 267586
2016-04-26 18:44:13 +00:00
Alexey Samsonov 25f5913ddf [MSan] Clear parameters shadow before invoking malloc/free hooks.
MSan runtime is not itself instrumented, so we need to explicitly
clear shadow for function arguments before calling user-provided
functions from runtime (e.g. we already do this for several
interceptors).

I'm still crafting a test case that would demonstrate this issue
reliably, and will commit it later today.

llvm-svn: 258339
2016-01-20 19:56:04 +00:00
Adhemerval Zanella 689724e578 [compiler-rt] [msan] Unify aarch64 mapping
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

llvm-svn: 251625
2015-10-29 13:04:19 +00:00
Evgeniy Stepanov b688a47963 New MSan mapping layout (compiler-rt part).
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.

llvm-svn: 249754
2015-10-08 21:35:34 +00:00
Evgeniy Stepanov 7aba3960c7 [msan] Early allocator initialization.
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.

llvm-svn: 248829
2015-09-29 21:28:54 +00:00
Adhemerval Zanella 19074450ee [MSan] Enable MSAN for aarch64
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.

llvm-svn: 247809
2015-09-16 15:12:25 +00:00
Alexey Samsonov ab229c13a6 [Sanitizer] Dump coverage if we're killing the program with __sanitizer::Die().
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.

llvm-svn: 245890
2015-08-24 22:21:47 +00:00
Alexey Samsonov 4369a3f4ad Revert r245770 and r245777.
These changes break both autoconf Mac OS X buildbot (linker errors
due to wrong Makefiles) and CMake buildbot (safestack test failures).

llvm-svn: 245784
2015-08-22 05:15:55 +00:00
Alexey Samsonov 8e38c71cb7 [Sanitizer] Dump coverage if we're killing the program with __sanitizer::Die().
Previously we had to call __sanitizer_cov_dump() from tool-specific
callbacks - instead, let sanitizer_common library handle this in a single place.

llvm-svn: 245770
2015-08-22 00:28:12 +00:00
Alexey Samsonov 540ac1aab4 [MSan] Deprecate __msan_set_death_callback() in favor of __sanitizer_set_death_callback().
llvm-svn: 245754
2015-08-21 22:45:12 +00:00
Jay Foad 8677baf024 Enable memory sanitizer for PPC64
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

llvm-svn: 240623
2015-06-25 06:22:31 +00:00
Evgeniy Stepanov 45328240dc [msan] Mprotect all inaccessible memory regions.
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.

llvm-svn: 238109
2015-05-24 02:47:59 +00:00
Alexey Samsonov b3053d9cbe Allow UBSan+MSan and UBSan+TSan combinations (Clang part).
Embed UBSan runtime into TSan and MSan runtimes in the same as we do
in ASan. Extend UBSan test suite to also run tests for these
combinations.

llvm-svn: 235954
2015-04-28 00:56:48 +00:00
Alexey Samsonov 042a069b25 [MSan] Prepare for splitting msan_new_delete.cc into a separate library. NFC.
llvm-svn: 235926
2015-04-27 22:08:04 +00:00
Evgeniy Stepanov 8441bb239f [msan] Refactor memory layout specification and setup.
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.

llvm-svn: 227192
2015-01-27 13:20:34 +00:00
Evgeniy Stepanov d38af30b74 [msan] Better use-after-free reports.
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.

llvm-svn: 226821
2015-01-22 13:33:16 +00:00
Evgeniy Stepanov 84adb5d1d0 [msan] Refactor shadow operations.
Move a bunch of functions to a new source file and rename some of them for
consistency. No functional changes.

llvm-svn: 226673
2015-01-21 16:42:30 +00:00
Alexey Samsonov 6334f46db8 [Sanitizer] Introduce Allocator::may_return_null bool flag.
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

llvm-svn: 224148
2014-12-12 20:07:35 +00:00
Viktor Kutuzov 30bd345613 [Msan] Generalize mapping facilities to add FreeBSD support
Differential Revision: http://reviews.llvm.org/D6387

llvm-svn: 222919
2014-11-28 11:42:55 +00:00
Alexey Samsonov de13018874 [MSan] [MIPS] Adding support for MIPS64 (patch by Mohit Bhakkad).
Reviewed at http://reviews.llvm.org/D5906

llvm-svn: 222388
2014-11-19 21:42:33 +00:00
Evgeniy Stepanov 7555f5ed1f [msan] Remove MSanDR and supporting code.
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.

llvm-svn: 222232
2014-11-18 10:33:15 +00:00
Alexey Samsonov 9c85927012 [Sanitizer] Make StackTrace a lightweight reference to array of PCs, and
introduce a BufferedStackTrace class, which owns this array.

Summary:
This change splits __sanitizer::StackTrace class into a lightweight
__sanitizer::StackTrace, which doesn't own array of PCs, and BufferedStackTrace,
which owns it. This would allow us to simplify the interface of StackDepot,
and eventually merge __sanitizer::StackTrace with __tsan::StackTrace.

Test Plan: regression test suite.

Reviewers: kcc, dvyukov

Reviewed By: dvyukov

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D5985

llvm-svn: 220635
2014-10-26 03:35:14 +00:00
Evgeniy Stepanov 35eb265421 [msan] Handle param-tls overflow.
ParamTLS (shadow for function arguments) is of limited size. This change
makes all arguments that do not fit unpoisoned, and avoids writing
past the end of a TLS buffer.

llvm-svn: 220351
2014-10-22 00:12:40 +00:00
Alexey Samsonov b9ec65cd4d [Sanitizer] Kill deprecated allocator interfaces in ASan, MSan and TSan in favor of
a unified interface in <sanitizer/allocator_interface.h>.

llvm-svn: 215469
2014-08-12 20:28:20 +00:00
Alexey Samsonov 91bb8e0e3a Generalize sanitizer allocator public interface.
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.

llvm-svn: 212469
2014-07-07 17:39:31 +00:00
Evgeniy Stepanov c935ca8c3c [msan] Add store_context_size= flag.
A new flag to control stack trace size for store event (in
track-origins=2 mode) independently of malloc_context_size.

llvm-svn: 211896
2014-06-27 12:48:01 +00:00
Sergey Matveev a531058d2b [MSan] Implement __sanitizer_print_stack_trace().
llvm-svn: 209625
2014-05-26 13:08:08 +00:00
Evgeniy Stepanov bce21acf25 [msan] Implement MSAN_OPTIONS=print_stats=1.
llvm-svn: 209287
2014-05-21 09:56:28 +00:00
Evgeniy Stepanov 208aae8ee0 [msan] Chained origins re-design.
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.

llvm-svn: 209284
2014-05-21 09:02:13 +00:00
Evgeniy Stepanov 8dd62dc3be [msan] Fix __msan_check_mem_is_initialized and prettify its output.
llvm-svn: 208195
2014-05-07 11:50:14 +00:00
Evgeniy Stepanov fe250b0014 [msan] Prettify __msan_print_shadow.
Makes __msan_print_shadow output much more readable, adds origin info.

llvm-svn: 207622
2014-04-30 09:50:30 +00:00
Evgeniy Stepanov f653cda269 [msan] Introduce MsanThread. Move thread-local allocator cache out of TLS.
This reduces .tbss from 109K down to almost nothing.

llvm-svn: 205618
2014-04-04 09:47:41 +00:00
Evgeniy Stepanov a55fcd35e9 [msan] Precise origin handling in __unaligned_(load|store)*.
llvm-svn: 205412
2014-04-02 11:06:35 +00:00
Evgeniy Stepanov 3c95744de8 [msan] Remove an extra top frame from track-origins=2 reports.
llvm-svn: 205192
2014-03-31 14:18:55 +00:00
Evgeniy Stepanov 89602651e8 [msan] Implement __msan_set_death_callback.
llvm-svn: 204926
2014-03-27 14:04:58 +00:00
Evgeniy Stepanov 412d973980 [msan] Origin tracking with history, compiler-rt part.
Compiler-rt part of MSan implementation of advanced origin tracking,
when we record not only creation point, but all locations where
an uninitialized value was stored to memory, too.

llvm-svn: 204152
2014-03-18 13:45:19 +00:00
Evgeniy Stepanov 86d8fb5ba1 [msan] Clean stack and TLS shadow on thread exit.
llvm-svn: 197156
2013-12-12 13:48:47 +00:00
Evgeniy Stepanov cd07898cf8 [msan] Get stack limits with pthread_create interceptor.
Before we did it lazily on the first stack unwind in the thread.
It resulted in deadlock when the unwind was caused by memory allocation
inside pthread_getattr_np:
  pthread_getattr_np   <<< not reentable
  GetThreadStackTopAndBottom
  __interceptor_realloc
  pthread_getattr_np
  

llvm-svn: 197026
2013-12-11 10:55:42 +00:00
Alexey Samsonov b3d939902a [Sanitizer] Make StackTrace::Unwind the only public way to unwind a stack trace.
llvm-svn: 194196
2013-11-07 07:28:33 +00:00
Evgeniy Stepanov d280ee48e8 [msan] Fix invalid origin copying.
Origin copying may destroy valid origin info. This is caused by
__msan_copy_origin widening the address range to the nearest 4-byte aligned
addresses both on the left and on the right. If the target buffer is
uninitialized and the source is fully initialized, this will result in
overriding valid origin of target buffer with stale (possibly 0) origin of the
source buffer.

With this change the widened origin is copied only if corresponding shadow
values are non zero.

llvm-svn: 193338
2013-10-24 11:56:03 +00:00
Evgeniy Stepanov 2794c47243 [msan] Drain allocator cache when leaving thread.
llvm-svn: 193163
2013-10-22 14:31:30 +00:00
Evgeniy Stepanov 65562f5281 [msan] Fix origin of deallocated memory.
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.

llvm-svn: 190781
2013-09-16 11:03:31 +00:00
Evgeniy Stepanov ac5ac34cf7 [msan] Add source file:line to stack origin reports.
Runtime library part.

llvm-svn: 190686
2013-09-13 12:49:13 +00:00
Alexey Samsonov ef643ce471 [sanitizer] fix code style
llvm-svn: 189474
2013-08-28 11:26:09 +00:00
Evgeniy Stepanov cb22c67a21 [msan] Save/restore va_arg_overflow_tls in signal handlers.
llvm-svn: 189351
2013-08-27 14:08:15 +00:00
Evgeniy Stepanov c41798152f [msan] Unpoison all TLS shadow when leaving a signal handler.
llvm-svn: 189343
2013-08-27 12:59:39 +00:00
Evgeniy Stepanov 44b77c26e4 [msan] Allocator statistics interface and malloc hooks.
llvm-svn: 187653
2013-08-02 14:26:58 +00:00