Commit Graph

2974 Commits

Author SHA1 Message Date
Evgeniy Stepanov 7a2bbc30a2 [msan] Remove CallocOverflow test.
This behaviour depends on MSAN_OPTIONS.
All interesting combinations are covered by lit_tests/allocator_returns_null.cc.

llvm-svn: 192691
2013-10-15 12:20:16 +00:00
Sergey Matveev 14b9924c7b Clean up StopTheWorld code after r192686.
Remove outdated comments. Also remove code that handled an issue in libc's
sigaction(), which we don't use anymore.

llvm-svn: 192689
2013-10-15 11:54:38 +00:00
Dmitry Vyukov 6f61206f55 tsan: resolve symlinks for called_from_lib suppressions
llvm-svn: 192688
2013-10-15 11:34:59 +00:00
Evgeniy Stepanov 113c646c56 [msan] Implement allocator_may_return_null=1 in MemorySanitizer.
llvm-svn: 192687
2013-10-15 11:33:48 +00:00
Dmitry Vyukov 59c850de6d tsan: implement internal syscall-based versions of sigaction/sigprocmask
use them in stoptheworld
fixes applications that intercept sigaction/sigprocmask

llvm-svn: 192686
2013-10-15 11:31:51 +00:00
Evgeniy Stepanov 3feb458a56 Fix a typo.
llvm-svn: 192685
2013-10-15 11:22:33 +00:00
Alexey Samsonov d2ddcf575d [ASan] Make test from r192581 Linux-only, as wild memory contents is less predictable on Mac
llvm-svn: 192677
2013-10-15 07:54:27 +00:00
Evgeniy Stepanov 251d1e5d21 [msan] Test for r192599.
llvm-svn: 192600
2013-10-14 15:17:05 +00:00
Sergey Matveev 43d90cbd86 [lsan] Support ASan's stack-use-after-return mode in LSan.
Treat the fake stack as live memory.

llvm-svn: 192593
2013-10-14 14:04:50 +00:00
Evgeniy Stepanov 7d7768e032 [msan] Remove a long-outdated comment.
llvm-svn: 192592
2013-10-14 13:30:40 +00:00
Sergey Matveev da9f5e7e7f [asan] Improve thread lifetime tracking on POSIX systems.
Call AsanThread::Destroy() from a late-running TSD destructor.
Previously we called it before any user-registered TSD destructors, which caused
false positives in LeakSanitizer.

llvm-svn: 192585
2013-10-14 12:01:05 +00:00
Evgeniy Stepanov 7aacd9c172 [msan] Intercept strto(d|f|ld)_l and glibc-specific __strto(d|f|ld)_l.
llvm-svn: 192583
2013-10-14 11:52:40 +00:00
Alexey Samsonov df6e6569c0 [ASan] Don't die with internal ASan error on large buffer overflows
Summary:
Out-of-bound access may touch not-yet allocated or already freed
and recycled from quarantine chunks. We should treat this situation as
a "free-range memory access" and avoid printing any data about that
irrelevant chunk (which may be inconsistent).

This should fix https://code.google.com/p/address-sanitizer/issues/detail?id=183

Reviewers: kcc

Reviewed By: kcc

CC: timurrrr, llvm-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D1893

llvm-svn: 192581
2013-10-14 11:13:54 +00:00
Evgeniy Stepanov 054d533d8d [msan] Regression test for r192575.
llvm-svn: 192577
2013-10-14 09:53:39 +00:00
Dmitry Vyukov 4314e319ab tsan: allow to override OnPrint() callback in Go runtime
llvm-svn: 192576
2013-10-14 09:52:40 +00:00
Alexey Samsonov c7ae7529e7 [Sanitizer] Return implementation of StackTrace::CopyFrom to header
llvm-svn: 192574
2013-10-14 07:36:10 +00:00
Dmitry Vyukov abc416f326 tsan: allow to override OnFinalize() in front-ends that does not support weak functions (Go)
llvm-svn: 192569
2013-10-14 06:31:03 +00:00
Alexey Samsonov 7f5823844a [Sanitizer] Remove StackTrace::max_depth field
llvm-svn: 192534
2013-10-12 12:40:47 +00:00
Alexey Samsonov c129e65661 [Sanitizer] Turn GetStackTrace() into StackTrace::Unwind()
llvm-svn: 192533
2013-10-12 12:23:00 +00:00
Sergey Matveev 53e61b1acf [sanitizer] Define kPthreadDestructorIterations on POSIX systems.
llvm-svn: 192453
2013-10-11 14:19:14 +00:00
Dmitry Vyukov 6dc0775f1f tsan: catch more races on file descriptors
llvm-svn: 192452
2013-10-11 14:13:11 +00:00
Dmitry Vyukov c9f9ada48d tsan: fix epoll_ctl interceptor
Currently data-race-test unittests fail with the following false positive:


WARNING: ThreadSanitizer: data race (pid=20365)
  Write of size 8 at 0x7da000008050 by thread T54:
    #0 close tsan_interceptors.cc:1483 (racecheck_unittest-linux-amd64-O0+0x0000000eb34a)
    #1 NegativeTests_epoll::Worker2() unittest/posix_tests.cc:1148 (racecheck_unittest-linux-amd64-O0+0x0000000cc6b1)
    #2 MyThread::ThreadBody(MyThread*) unittest/./thread_wrappers_pthread.h:367 (racecheck_unittest-linux-amd64-O0+0x000000097500)

  Previous read of size 8 at 0x7da000008050 by thread T49:
    #0 epoll_ctl tsan_interceptors.cc:1646 (racecheck_unittest-linux-amd64-O0+0x0000000e9fee)
    #1 NegativeTests_epoll::Worker1() unittest/posix_tests.cc:1140 (racecheck_unittest-linux-amd64-O0+0x0000000cc5b5)
    #2 MyThread::ThreadBody(MyThread*) unittest/./thread_wrappers_pthread.h:367 (racecheck_unittest-linux-amd64-O0+0x000000097500)

llvm-svn: 192448
2013-10-11 13:33:22 +00:00
Sergey Matveev 6c5e943953 [sanitizer] Ninja style fix to r192442.
llvm-svn: 192443
2013-10-11 12:15:45 +00:00
Sergey Matveev dc75cf3368 [sanitizer] Move the PTHREAD_DESTRUCTOR_ITERATIONS constant to sanitizer_linux.h.
Add a test.

llvm-svn: 192442
2013-10-11 12:09:49 +00:00
Alexey Samsonov 0cd96165f1 [Sanitizer] StackTrace: kill CopyTo and reimplement CopyFrom
llvm-svn: 192441
2013-10-11 11:14:20 +00:00
Alexey Samsonov 9d8385453b [Sanitizer] Simplify StackTrace::FastUnwindStack interface and fix a bug with one-frame stack traces
llvm-svn: 192428
2013-10-11 09:58:30 +00:00
Dmitry Vyukov 3431b38067 tsan: minor refactoring
Replace duplicate code snippet with function.

llvm-svn: 192357
2013-10-10 16:03:24 +00:00
Dmitry Vyukov fbb194ff34 tsan: add annotations to ignore synchronization operations
The annotations are AnnotateIgnoreSyncBegin/End,
may be useful to ignore some infrastructure synchronization
that introduces lots of false negatives.

llvm-svn: 192355
2013-10-10 15:58:12 +00:00
Sergey Matveev 6f7fb43ad3 [sanitizer] Fix the parent liveness check in StopTheWorld.
Comparing the parent PID with 1 isn't sufficient to ensure the parent is alive,
because of prctl(PR_SET_CHILD_SUBREAPER, ...). Compare with the real parent's
recorded PID instead.

llvm-svn: 192295
2013-10-09 13:36:20 +00:00
Sergey Matveev adef754297 [sanitizer] Fix deadlock in StopTheWorld.
The tracer thread in StopTheWorld could wait on a mutex forever if the parent
process died before unlocking it. Use PR_SET_PDEATHSIG so that the parent would
kill the child in this scenario.

llvm-svn: 192210
2013-10-08 18:01:03 +00:00
Sergey Matveev 398fb700a2 [sanitizer] Do not break the CFI unwind chain in clone().
Fixes build on clang 3.2, which doesn't support cfi_undefined. This change
doesn't seem to break the slow unwinder. Even if it does, the worst thing that
could happen is that we would not see a backtrace when a fatal error happens
under StopTheWorld.

llvm-svn: 192196
2013-10-08 16:38:39 +00:00
Alexey Samsonov 50ec07c196 [TSan] Automatically pick up llvm-symbolizer from PATH, as we do in another sanitizers
llvm-svn: 191954
2013-10-04 13:38:35 +00:00
Alexey Samsonov 12f5e639d6 [TSan] Add ValgrindSlowdown to the list of exported symbols
llvm-svn: 191952
2013-10-04 13:12:05 +00:00
Dmitry Vyukov 513a3a6c0b tsan: fix a bug in pthread_once when called from an ignored library
It must set thr->in_rtl = 0 before executing user callback.

llvm-svn: 191946
2013-10-04 10:27:21 +00:00
Alexey Samsonov f2b811a618 Refactor the usage of strip_path_prefix option and make it more consistent across sanitizers
llvm-svn: 191943
2013-10-04 08:55:03 +00:00
Dmitry Vyukov 302ec7b9bc tsan: add memory_limit_mb flag
The flag allows to bound maximum process memory consumption (best effort).
If RSS reaches memory_limit_mb, tsan flushes all shadow memory.

llvm-svn: 191913
2013-10-03 17:14:35 +00:00
Dmitry Vyukov c967d2f49c asan/msan/tsan: fix broken linux syscalls
Currently the following source code:

u64 NanoTime() {
  kernel_timeval tv = {};
  internal_syscall(__NR_gettimeofday, &tv, 0);
  return (u64)tv.tv_sec * 1000*1000*1000 + tv.tv_usec * 1000;
}

generates the following assembly:

Dump of assembler code for function __sanitizer::NanoTime():
=> 0x00007ff30657d380 <+0>:	lea    -0x10(%rsp),%rdi
   0x00007ff30657d385 <+5>:	xor    %esi,%esi
   0x00007ff30657d387 <+7>:	mov    $0x60,%eax
   0x00007ff30657d38c <+12>:	syscall 
   0x00007ff30657d38e <+14>:	mov    $0,%eax
   0x00007ff30657d393 <+19>:	retq   

with this change:

Dump of assembler code for function __sanitizer::NanoTime():
=> 0x00007faab834f380 <+0>:	movq   $0x0,-0x10(%rsp)
   0x00007faab834f389 <+9>:	movq   $0x0,-0x8(%rsp)
   0x00007faab834f392 <+18>:	lea    -0x10(%rsp),%rdi
   0x00007faab834f397 <+23>:	xor    %esi,%esi
   0x00007faab834f399 <+25>:	mov    $0x60,%eax
   0x00007faab834f39e <+30>:	syscall 
   0x00007faab834f3a0 <+32>:	mov    -0x8(%rsp),%rax
   0x00007faab834f3a5 <+37>:	mov    -0x10(%rsp),%rcx
   0x00007faab834f3aa <+42>:	imul   $0x3e8,%rax,%rdx
   0x00007faab834f3b1 <+49>:	imul   $0x3b9aca00,%rcx,%rax
   0x00007faab834f3b8 <+56>:	add    %rdx,%rax
   0x00007faab834f3bb <+59>:	retq   

llvm-svn: 191908
2013-10-03 16:53:50 +00:00
Dmitry Vyukov 19a1302046 asan/msan: fix "unused function 'OnExit'" warning
llvm-svn: 191904
2013-10-03 15:43:59 +00:00
Dmitry Vyukov fdfb2ade8f asan/msan/tsan: move _exit interceptor to common interceptors
llvm-svn: 191903
2013-10-03 15:22:29 +00:00
Dmitry Vyukov bfe7bb7034 tsan: include lsan into presubmit check
llvm-svn: 191902
2013-10-03 14:56:08 +00:00
Dmitry Vyukov 83ebd022d7 tsan: fix false positive in localtime()
llvm-svn: 191899
2013-10-03 14:12:09 +00:00
Dmitry Vyukov e07dc7d1fe tsan: intercept _exit so that we can override exit status
llvm-svn: 191898
2013-10-03 14:00:46 +00:00
Dmitry Vyukov 5ba736457c tsan: ignore interceptors coming from specified libraries
LibIgnore allows to ignore all interceptors called from a particular set
of dynamic libraries. LibIgnore remembers all "called_from_lib" suppressions
from the provided SuppressionContext; finds code ranges for the libraries;
and checks whether the provided PC value belongs to the code ranges.

Also make malloc and friends interceptors use SCOPED_INTERCEPTOR_RAW instead of
SCOPED_TSAN_INTERCEPTOR, because if they are called from an ignored lib,
then must call our internal allocator instead of libc malloc.

llvm-svn: 191897
2013-10-03 13:37:17 +00:00
Evgeniy Stepanov 364f70c728 [asan] Don't require X86 to build Android runtime.
Patch by Greg Fitzgerald.

llvm-svn: 191883
2013-10-03 08:31:14 +00:00
Evgeniy Stepanov c907a60ffb [sanitizer] Fix localtime and gmtime interceptors to clean tm->tm_zone.
llvm-svn: 191827
2013-10-02 14:30:03 +00:00
Dmitry Vyukov 945397157b tsan: fix the following compiler warning
sanitizer_common_interceptors.inc:1142:53: warning: invoking macro INTERCEPTOR argument 3: empty macro arguments are undefined in ISO C90 and ISO C++98 [enabled by default]

llvm-svn: 191822
2013-10-02 14:04:23 +00:00
Dmitry Vyukov af335eddfe msan: fix compiler warnings about unused variables
llvm-svn: 191821
2013-10-02 14:02:08 +00:00
Dmitry Vyukov 8358c41477 tsan: use ninja instead of make (faster and less output)
llvm-svn: 191819
2013-10-02 12:57:43 +00:00
Nick Lewycky f60d8ae155 This fixme is resolved, fix the test.
llvm-svn: 191810
2013-10-02 05:05:28 +00:00
Nick Lewycky b7aa592c19 Make the InvalidValueData take a SourceLocation.
llvm-svn: 191807
2013-10-02 02:29:47 +00:00
Alexey Samsonov 20abdf69ec Add top-level CMake 'compiler-rt' target to build all compiler-rt libraries
llvm-svn: 191747
2013-10-01 12:52:15 +00:00
Alexey Samsonov 3b54a83d26 [LSan] Rework r191522 - treat allocations with short stack traces as live
llvm-svn: 191662
2013-09-30 10:57:56 +00:00
Alexey Samsonov f56ddf7fd1 [LSan] Don't report leaks with single-frame stack traces
llvm-svn: 191522
2013-09-27 13:54:20 +00:00
Evgeniy Stepanov 01781722b6 [sanitizer] Intercept backtrace, backtrace_symbols.
llvm-svn: 191516
2013-09-27 12:40:23 +00:00
Kostya Serebryany 3c42ce1516 [asan] introduce run-time flag uar_stack_size_log to control the size of FakeStack; don't crash when the fake stack is exhausted, move some code to .cc file
llvm-svn: 191510
2013-09-27 11:37:23 +00:00
Evgeniy Stepanov 022235cf04 [msan] Unpoison argument shadow for C++ module destructors.
Fixes PR17377.

llvm-svn: 191508
2013-09-27 11:32:21 +00:00
Dmitry Vyukov 439a904515 tsan: support allocator_may_return_null flag
Fixes https://code.google.com/p/thread-sanitizer/issues/detail?id=29

llvm-svn: 191482
2013-09-27 02:31:23 +00:00
Dmitry Vyukov e435f94b69 tsan: fix scanf interceptor
llvm-svn: 191445
2013-09-26 18:38:54 +00:00
Evgeniy Stepanov 8f27f6b549 [sanitizer] A bunch of libc interceptors.
sigwait
sigwaitinfo
sigtimedwait
sigemptyset
sigfillset
sigpending
sigprocmask

llvm-svn: 191374
2013-09-25 14:47:43 +00:00
Alexey Samsonov 4fc53e4c06 [Sanitizer] Don't include wordexp.h on Android
llvm-svn: 191358
2013-09-25 07:41:46 +00:00
Evgeniy Stepanov 2761ee0409 [sanitizer] Intercept wordexp.
llvm-svn: 191305
2013-09-24 14:38:22 +00:00
Alexander Potapenko ae49e8c34a [ASan] Fix GCD tests by spinning forever in the main thread.
Since the error is always reported by one of the GCD workers, this will help avoid premature program termination with exit code 0.

llvm-svn: 191294
2013-09-24 12:42:25 +00:00
Evgeniy Stepanov 46901f613b [msan] Test for atomic handling in MSan.
llvm-svn: 191288
2013-09-24 11:21:16 +00:00
Kostya Serebryany 01ff028814 [asan] remove -fsanitize=use-after-return from the tests (this flag now comes with asan by default)
llvm-svn: 191204
2013-09-23 14:34:06 +00:00
Evgeniy Stepanov ce72b2c20b [msan] Fix a WTF in r191196.
llvm-svn: 191197
2013-09-23 13:34:26 +00:00
Evgeniy Stepanov f497bfee76 [msan] Allow nested symbolizer and loader scopes.
llvm-svn: 191196
2013-09-23 13:26:31 +00:00
Timur Iskhodzhanov 7f92aa687a [ASan/Win] Slightly optimize the DLL thunk
llvm-svn: 191190
2013-09-23 11:40:58 +00:00
Timur Iskhodzhanov e2b207cfd2 [ASan] Fix a compile-time warning
llvm-svn: 191189
2013-09-23 11:19:43 +00:00
Timur Iskhodzhanov d6c93c7b4d [ASan] Add DLL thunks for the new stack UAR interface
llvm-svn: 191188
2013-09-23 11:05:41 +00:00
Alexander Potapenko 92b566b0e4 [ASan] Fix the interface test on Darwin.
llvm-svn: 191187
2013-09-23 10:38:23 +00:00
Kostya Serebryany b997c543fc [asan] disable the detect_stack_use_after_return run-time flag by default and enable it explicitly in tests. This is done in preparation to enabling the -fsanitize=use-after-return compile-time flag by default when -fsanitize=address is present.
llvm-svn: 191184
2013-09-23 08:58:14 +00:00
Dmitry Vyukov 2ea2d9cb29 tsan: remove unneeded ___chkstk_ms function from Go runtime
llvm-svn: 191161
2013-09-22 02:49:56 +00:00
Dmitry Vyukov a2c6e1e80f tsan: allow symbolization of non-native PCs, e.g. coming from JIT/JAVA/etc
llvm-svn: 191157
2013-09-22 00:14:57 +00:00
Dmitry Vyukov 76ec1910ac tsan: ignore malloc/free/strdup when called from libjvm
llvm-svn: 191153
2013-09-21 23:44:19 +00:00
Dmitry Vyukov 150406bbf3 tsan: ignore all interceptors coming directly from JVM
llvm-svn: 191152
2013-09-21 23:06:00 +00:00
Dmitry Vyukov 017015c9ed tsan: improve diagnostics for incorrect usages of mutexes
llvm-svn: 191151
2013-09-21 22:43:27 +00:00
Dmitry Vyukov 4e9c091dd7 tsan: allow to obtain code range for a particular module
this is required to ignore interceptors when called from the module

llvm-svn: 191149
2013-09-21 21:41:08 +00:00
Dmitry Vyukov 1da6b4d5c8 tsan: intercept fork syscall
llvm-svn: 191144
2013-09-21 20:59:04 +00:00
Dmitry Vyukov 3d15bcca1d tsan: do not try to use builtin atomic operations
see the comment in code

llvm-svn: 191132
2013-09-21 04:59:02 +00:00
Dmitry Vyukov a182592aa0 tsan: intercept close syscall
llvm-svn: 191129
2013-09-21 03:47:35 +00:00
Alexander Potapenko 6c49695e7a [ASan] Remove a complex multiline comment that baffles lint.
That comment is repeated in another function below.

llvm-svn: 191085
2013-09-20 11:33:14 +00:00
Alexander Potapenko d1bae72e39 [libsanitizer] Pass an explicit template to mktemp. Running mktemp without a template doesn't work on Darwin.
llvm-svn: 191084
2013-09-20 11:29:44 +00:00
Alexander Potapenko bff7e64a3f [ASan] Fix compilation of asan_str_test.cc on non-Darwin.
llvm-svn: 191083
2013-09-20 11:03:27 +00:00
Alexander Potapenko 7be1a632b2 [ASan] Enforce the memmove semantics for both memcpy() and memmove() interceptors on Darwin.
Due to bugs in the interposition of resolver functions on 10.7 and 10.8 both memcpy() and memmove()
were previously intercepted by INTERCEPTOR(memcpy), which led to false positives and crashes (see http://llvm.org/bugs/show_bug.cgi?id=16362)
We choose to use a memmove-like function in both cases. This effectively disables the overlap checks in memcpy(), but the overlaps
aren't possible in practice, because memcpy() and memmove() are the same function on Darwin.

Once the interposition is fixed in 10.9, we'll need to revisit this issue, see https://code.google.com/p/address-sanitizer/issues/detail?id=226

llvm-svn: 191081
2013-09-20 10:56:34 +00:00
Kostya Serebryany 2ab5a48dbe [asan] nuke yet another async-signal-safety bug in UAR (oh, my)
llvm-svn: 191080
2013-09-20 09:16:21 +00:00
Alexey Samsonov 29d7be1f68 [Sanitizer] Add pthread_cond_init to the list of versioned functions
llvm-svn: 191078
2013-09-20 08:37:57 +00:00
Dmitry Vyukov 481d90c480 tsan: handle memory read/write in syscalls
llvm-svn: 191074
2013-09-20 06:54:14 +00:00
Dmitry Vyukov c7547d0527 tsan: allow to ignore memory accesses in malloc and free
llvm-svn: 191072
2013-09-20 05:37:36 +00:00
Dmitry Vyukov 20f6ff1e66 tsan: do not crash when user intercepts fopen()
llvm-svn: 191066
2013-09-20 02:01:38 +00:00
Dmitry Vyukov b523b9c8d4 tsan: fix linking of tsan runtime into dynamic libraries
versioned symbols can not be linked into dynamic library w/o linker script
also simplifies code as side effect

llvm-svn: 191056
2013-09-19 23:44:51 +00:00
Alexander Potapenko 8f5d907aea [ASan] Fix init-order-dlopen.cc test to not depend on the -Wl,-undefined,dynamic_lookup being passed to the linker.
llvm-svn: 191012
2013-09-19 17:12:45 +00:00
Kostya Serebryany f8bbdfaf95 [asan] fix one more async-signal-safety issue with use-after-return
llvm-svn: 191004
2013-09-19 14:59:52 +00:00
Alexey Samsonov 786ee9b1ad [MSan] Fix -Wempty-body warning
llvm-svn: 190994
2013-09-19 08:35:16 +00:00
Alexey Samsonov 1c5cd7516f [TSan] Fix -Wempty-body warning
llvm-svn: 190993
2013-09-19 07:59:18 +00:00
Dmitry Vyukov d78bc3aa11 asan/tsan/msan: use builtin atomic operations when available
this should fix episodic crashes on ARM/PPC
x86_32 is still broken

llvm-svn: 190991
2013-09-19 06:02:56 +00:00
Dmitry Vyukov f54631dcfe tsan: prevent the following false positive due to __cxa_atexit
WARNING: ThreadSanitizer: data race (pid=29103)
  Write of size 8 at 0x7d64003bbf00 by main thread:
    #0 free tsan_interceptors.cc:477
    #1 __run_exit_handlers <null>:0 (libc.so.6+0x000000050cb7)

  Previous write of size 8 at 0x7d64003bbf00 by thread T78 (mutexes: write M9896):
    #0 calloc tsan_interceptors.cc:449
    #1 ...

llvm-svn: 190989
2013-09-19 04:48:59 +00:00
Dmitry Vyukov c2437ffc23 tsan: consistently use thr instead of cur_thread() in annotations implementation
llvm-svn: 190988
2013-09-19 04:42:25 +00:00
Dmitry Vyukov 1a7ca92006 tsan: refactor internal IgnoreCtl interface
llvm-svn: 190987
2013-09-19 04:39:04 +00:00
Evgeniy Stepanov 91375fd66e [tsan] No-op implementation of AnnotateMemoryIsInitialized.
llvm-svn: 190933
2013-09-18 11:20:31 +00:00
Kostya Serebryany c3d43ca3ec [asan] add a run-time option detect_stack_use_after_return, add verbosity output for fake stack
llvm-svn: 190932
2013-09-18 10:35:12 +00:00