Commit Graph

70 Commits

Author SHA1 Message Date
Evgeniy Stepanov 79ca0fd1a0 [msan] Update origin for the entire destination range on memory store.
Previously we always stored 4 bytes of origin at the destination address
even for 8-byte (and longer) stores.

This should fix rare missing, or incorrect, origin stacks in MSan reports.

llvm-svn: 226658
2015-01-21 13:21:31 +00:00
Alexander Potapenko 5823daf73d [msan] Put the coverage files for coverage-levels.cc into a temporary dir.
llvm-svn: 223355
2014-12-04 11:35:32 +00:00
Kostya Serebryany 29a2236c7d [msan] allow -fsanitize-coverage=N together with -fsanitize=memory, compiler-rt part
llvm-svn: 223314
2014-12-03 23:29:14 +00:00
Evgeniy Stepanov 8a988c40c8 [msan] Add one more test for the handling of stack origins.
llvm-svn: 223229
2014-12-03 13:26:56 +00:00
Evgeniy Stepanov a0b6899234 [msan] Fix origin propagation for select of floats.
MSan does not assign origin for instrumentation temps (i.e. the ones that do
not come from the application code), but "select" instrumentation erroneously
tried to use one of those.

https://code.google.com/p/memory-sanitizer/issues/detail?id=78

llvm-svn: 222918
2014-11-28 11:17:58 +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
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
Evgeniy Stepanov 3905bb9150 [asan] De-flake one test.
This change replaces an in-test timeout with an unconditional blocking wait.
It speeds up normal execution significantly at the cost of hanging up indefinitely
in case of a failure. This is a very specific regression test and we don't
expect any failures in the future.

Another approach ould be increasing the timeout to ~8 seconds, which seems too
much for a lit test.

llvm-svn: 217870
2014-09-16 12:03:52 +00:00
Evgeniy Stepanov 256d5512e6 [msan] Fix wrong array index in io_submit interceptor.
llvm-svn: 217362
2014-09-08 09:28:25 +00:00
Evgeniy Stepanov 36974a7061 [msan] Make chained_origin_limits test faster.
llvm-svn: 217361
2014-09-08 09:04:45 +00:00
Alexey Samsonov 62063b46fc Use "-gline-tables-only" instead of "-g" in sanitizer test suites.
We are interested in verifying that -gline-tables-only provides enough
debug information for verbose error reports and symbolized stack traces.

llvm-svn: 217284
2014-09-05 22:05:32 +00:00
Evgeniy Stepanov e9ca1c72be [msan] Fix fork test on centos-6.5.
Missing <atomic> header.

llvm-svn: 217142
2014-09-04 11:07:42 +00:00
Evgeniy Stepanov bb91e02efd [msan] Make origin tracking fork-safe.
Chained origins make plain memory stores async-signal-unsafe.
We already disable it inside signal handlers.
This change grabs all origin-related locks before fork() and releases
them after fork() to avoid a deadlock in the child process.

llvm-svn: 217140
2014-09-04 10:36:14 +00:00
Evgeniy Stepanov f1741f52ad [msan] Fix origin_history_per_stack_limit=0 behavior.
It disables the per-stack limit.

llvm-svn: 217030
2014-09-03 12:15:59 +00:00
Evgeniy Stepanov 5c72938c39 [msan] Use SIGHUP instead of SIGUSR1 in test.
Apparently, SIGUSR1 does not work on x86_64+ArchLinux for some reason.

For more details, see:
https://groups.google.com/forum/#!topic/llvm-dev/4Ag1FF4M2Dw

llvm-svn: 214289
2014-07-30 08:17:58 +00:00
Evgeniy Stepanov 465466e80c [msan] Stop demangling function name in the stack origin report.
This was done by calling __cxa_demangle directly, which is bad
when c++abi library is instrumented. The following line always
contains the demangled name (when running with a symbolizer) anyway.

llvm-svn: 212929
2014-07-14 09:35:27 +00:00
Evgeniy Stepanov 23e8dfd487 [msan] Make one test case less brittle.
llvm-svn: 212798
2014-07-11 08:47:51 +00:00
Alexey Samsonov 1ce0929465 [MSan] Make one more test standalone
llvm-svn: 212487
2014-07-07 20:59:10 +00:00
Alexey Samsonov efe7828c69 [MSan] Use a single file for dso-origin test
llvm-svn: 212484
2014-07-07 20:37:12 +00:00
Alexey Samsonov c1856835d1 [Sanitizer] Move test for malloc/free hooks under test/sanitizer_common
llvm-svn: 212474
2014-07-07 18:47:29 +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 174242c74c [msan] Stop propagating shadow in blacklisted functions.
With this change all values passed through blacklisted functions
become fully initialized. Previous behavior was to initialize all
loads in blacklisted functions, but apply normal shadow propagation
logic for all other operation.

This makes blacklist applicable in a wider range of situations.

It also makes code for blacklisted functions a lot shorter, which
works as yet another workaround for PR17409.

llvm-svn: 212268
2014-07-03 11:56:30 +00:00
Evgeniy Stepanov e1a5a1f7a8 Revert of r212265.
llvm-svn: 212266
2014-07-03 11:35:08 +00:00
Evgeniy Stepanov cfc40ef98a [msan] Stop propagating shadow in blacklisted functions.
With this change all values passed through blacklisted functions
become fully initialized. Previous behavior was to initialize all
loads in blacklisted functions, but apply normal shadow propagation
logic for all other operation.

This makes blacklist applicable in a wider range of situations.

It also makes code for blacklisted functions a lot shorter, which
works as yet another workaround for PR17409.

llvm-svn: 212265
2014-07-03 11:18:48 +00:00
Evgeniy Stepanov 4e2d5edb0c [msan] Limit stack origin chain length.
Stack origins were created with unlimited length by mistake.

llvm-svn: 212036
2014-06-30 11:22:42 +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
Evgeniy Stepanov 7d3c68a9cf [msan] Fix truncated stack trace in chained origin reports.
This is a leftover from the times when the next (chained) origin id
was stored as the last frame of a stack trace.

llvm-svn: 211878
2014-06-27 07:32:08 +00:00
Evgeniy Stepanov b163f0276f [msan] Fix bad interaction between with-calls mode and chained origin tracking.
Origin history should only be recorded for uninitialized values, because it is
meaningless otherwise. This change moves __msan_chain_origin to the runtime
library side and makes it conditional on the corresponding shadow value.

Previous code was correct, but _very_ inefficient.

llvm-svn: 211700
2014-06-25 14:41:57 +00:00
Evgeniy Stepanov 7ad0bde843 [msan] Fix false positive on dynamic tls.
Use existing DTLS code in sanitizer_tls_get_addr.{h,cc} to unpoison DTLS
blocks both on allocation and deallocation.

https://code.google.com/p/memory-sanitizer/issues/detail?id=44

llvm-svn: 211683
2014-06-25 11:30:35 +00:00
Evgeniy Stepanov ad8065f01a [msan] Print stats even on successful run with atexit=1.
llvm-svn: 211574
2014-06-24 09:04:06 +00:00
Evgeniy Stepanov 2c27df9a33 [msan] Intercept __getdelim.
llvm-svn: 211162
2014-06-18 13:35:13 +00:00
Evgeniy Stepanov df187feae4 [msan] Fix handling of multiplication by a constant with a number of trailing zeroes.
Multiplication by an integer with a number of trailing zero bits leaves
the same number of lower bits of the result initialized to zero.
This change makes MSan take this into account in the case of multiplication by
a compile-time constant.

We don't handle the general, non-constant, case because
(a) it's not going to be cheap (computation-wise);
(b) multiplication by a partially uninitialized value in user code is
    a bad idea anyway.

Constant case must be handled because it appears from LLVM optimization of a
completely valid user code, as the test case in compiler-rt demonstrates.

llvm-svn: 211092
2014-06-17 09:23:12 +00:00
Evgeniy Stepanov 2be29929be Fix line numbers for code inlined from __nodebug__ functions.
Instructions from __nodebug__ functions don't have file:line
information even when inlined into no-nodebug functions. As a result,
intrinsics (SSE and other) from <*intrin.h> clang headers _never_
have file:line information.

With this change, an instruction without !dbg metadata gets one from
the call instruction when inlined.

Fixes PR19001.

llvm-svn: 210459
2014-06-09 09:09:19 +00:00
Evgeniy Stepanov ee98fb197b [msan] Fix wrong endianness when printing shadow.
llvm-svn: 210335
2014-06-06 14:06:14 +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 5680a26b0b [msan] Better open_memstream support.
Move fflush and fclose interceptors to sanitizer_common.
Use a metadata map to keep information about the external locations
that must be updated when the file is written to.

llvm-svn: 208676
2014-05-13 08:36:31 +00:00
Alexey Samsonov 0bef819f9f [Sanitizer] Add the machinery to run the same test under several sanitizers
llvm-svn: 208378
2014-05-09 00:28:18 +00:00
Alexey Samsonov 35744c4753 Fixup for r208066. Properly get values of PTRACE_GETREGSET/PTRACE_SETREGSET.
llvm-svn: 208363
2014-05-08 22:11:20 +00:00
Evgeniy Stepanov c5e51926dc [msan] Intercept strxfrm.
llvm-svn: 208303
2014-05-08 12:04:01 +00:00
Evgeniy Stepanov 9c20cb1a7c [msan] Fix potential infinite recursion in a test.
If printf is intercepted (it is not atm), REAL(printf) call in the interceptor
would get redirected back to my_lgamma, resulting in infinite recursion.

llvm-svn: 208294
2014-05-08 09:37:36 +00:00
Evgeniy Stepanov 55590227f8 [sanitizer] Intercept obstack.
llvm-svn: 208196
2014-05-07 11:50:56 +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 06475bf752 [msan] Fix print_shadow test.
llvm-svn: 208069
2014-05-06 08:15:50 +00:00
Greg Fitzgerald b8aae5405b Add %run to all lit tests
llvm-svn: 207709
2014-04-30 21:34:17 +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 f3d5d119a8 [sanitizer] Intercept a bunch of stdio calls.
Add move fopen/freopen interceptors from TSan to common.

llvm-svn: 207224
2014-04-25 13:26:21 +00:00
Evgeniy Stepanov 5a7c364343 [msan] Disable chained origins in signal handlers.
StackDepot is not async-signal-safe; storing a new origin to it can deadlock.

llvm-svn: 206983
2014-04-23 14:01:57 +00:00
Evgeniy Stepanov a7f9071f25 [sanitizer] Intercept tsearch.
llvm-svn: 206755
2014-04-21 14:21:51 +00:00
Evgeniy Stepanov 24c8d92fec [sanitizer] Intercept a subset of sunrpc interface (xdr_*).
llvm-svn: 205627
2014-04-04 14:51:23 +00:00