Commit Graph

4801 Commits

Author SHA1 Message Date
Dmitry Vyukov 1d9b5e6ece tsan: fix handling of condition variable destruction
POSIX states that "It shall be safe to destroy an initialized condition
variable upon which no threads are currently blocked", and later clarifies
"A condition variable can be destroyed immediately after all the threads
that are blocked on it are awakened) (in examples section). Tsan reported
such destruction as a data race.
Fixes https://llvm.org/bugs/show_bug.cgi?id=23616
Reviewed in http://reviews.llvm.org/D10693

llvm-svn: 241082
2015-06-30 17:23:29 +00:00
Evgeniy Stepanov 856b11199f [asan] Fix SanitizerCommon.PthreadDestructorIterations test on Android L.
On Android L, TSD destructors run 8 times instead of 4.
Back to 4 times on the current master branch (as well as on K).

llvm-svn: 240992
2015-06-29 20:28:55 +00:00
Alexander Potapenko 1669e68b57 [libsanitizer] Replace ReadBinaryName() with ReadBinaryNameCached(),
which caches the executable name upon the first invocation.
This is necessary because Google Chrome (and potentially other programs)
restrict the access to /proc/self/exe on linux.
This change should fix https://code.google.com/p/chromium/issues/detail?id=502974

llvm-svn: 240960
2015-06-29 15:58:16 +00:00
Dmitry Vyukov ffb551b2b0 tsan: implement suppressions for top frame only
The new suppression type is called "race_top" and is matched only against top frame in report stacks.
This is required for situations when we want to suppress a race in a "thread pool" or "event loop" implementation.
If we simply use "race:ThreadPool::Execute" suppression, that can suppress everything in the program.

Reviewed in http://reviews.llvm.org/D10686

llvm-svn: 240949
2015-06-29 14:38:31 +00:00
Jay Foad 55f65a3554 [msan] Fix infinite recursion when _Unwind_Backtrace calls memcpy
Summary:
On PPC64, half the msan tests fail with an infinite recursion through
GetStackTrace like this:

#0 __msan::GetStackTrace
#1 __msan_memcpy
#2 ?? () from /lib64/libgcc_s.so.1
#3 ?? () from /lib64/libgcc_s.so.1
#4 _Unwind_Backtrace
#5 __sanitizer::BufferedStackTrace::SlowUnwindStack
#6 __sanitizer::BufferedStackTrace::Unwind
#7 __msan::GetStackTrace
#8 __interceptor_calloc
#9 _dl_allocate_tls
#10 pthread_create@@GLIBC_2.17
#11 __interceptor_pthread_create
#12 main

The problem is that we call _Unwind_Backtrace to get a stack trace; but
_Unwind_Backtrace calls memcpy, which we intercept and try to get
another stack trace.

This patch fixes it in __msan_memcpy by skipping the stack trace if
IsInSymbolizer(). This works because GetStackTrace already creates a
SymbolizerScope to "block reports from our interceptors during
_Unwind_Backtrace".

Reviewers: samsonov, wschmidt, eugenis

Reviewed By: eugenis

Subscribers: llvm-commits

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

llvm-svn: 240878
2015-06-27 08:39:12 +00:00
Evgeniy Stepanov 2f58bb6a34 [asan] Disable glibc-specific code chunk on Android.
Fixes quarantine_size_mb.cc test on the Android bot.

llvm-svn: 240854
2015-06-26 23:39:23 +00:00
Evgeniy Stepanov 609af9098c [asan] Link sanitizer_common tests on Android as -pie.
llvm-svn: 240825
2015-06-26 20:39:30 +00:00
Alexey Samsonov 1ac144b51b [ASan] Clean up obsolete stats.
Remove stats that we no longer collect after the allocator change.
Use proper constant SizeClassMap::kNumClasses to fix potential buffer
overflow (https://code.google.com/p/address-sanitizer/issues/detail?id=397).

llvm-svn: 240816
2015-06-26 19:18:02 +00:00
Alexander Potapenko f4388a2ba4 [libsanitizer] Delete the unused GetBinaryName() function.
llvm-svn: 240767
2015-06-26 09:28:24 +00:00
Anna Zaks a16075cfc9 [asan] Do not unset DYLD_ROOT_PATH before calling atos on Darwin
We were unsetting DYLD_ROOT_PATH before calling atos on Darwin in order to
address it not working for symbolicating 32 bit binaries. (atos essentiall
tries to respawn as a 32 bit binary and it's disallowed to respawn if
DYLD_ROOT_PATH is set ... ) However, processes rely on having DYLD_ROOT_PATH
set under certain conditions, so this is not the right fix. In particular, this
always crashes when running ASanified process under the debugger in Xcode with
iOS simulator, which is a very important workflow for us to support.

This patch reverts the unsetting of the DYLD_ROOT_PATH. The correct fix to the
misbehavior on 32-bit binaries should happen inside atos.

http://reviews.llvm.org/D10722

llvm-svn: 240724
2015-06-25 23:36:21 +00:00
Jay Foad 86269dc5d0 [msan] Teach sanitizers about the PPC64 ptrace syscall
Summary:
This fixes test/msan/Linux/syscalls.cc, and should also fix the ppc64
sanitizer buildbots which are currently failing in
"make check-sanitizer".

Reviewers: samsonov, wschmidt, eugenis

Reviewed By: eugenis

Subscribers: llvm-commits

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

llvm-svn: 240692
2015-06-25 20:50:18 +00:00
Jay Foad 198337bf42 [msan] Fix SetShadow for mappings at the end of the application address space
Summary:
On PPC64 if you disable ASLR (or run under gdb) you're likely to see
mmap returning a mapping right at the end of the application address
space region. This caused SetShadow to call MEM_TO_SHADOW() on the
last+1 address in the region, which seems wrong to me; how can
MEM_TO_SHADOW() distinguish this from the first address in the following
region?

Fixed by only calling MEM_TO_SHADOW() once, on the start address.

Reviewers: samsonov, wschmidt, eugenis

Reviewed By: eugenis

Subscribers: llvm-commits

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

llvm-svn: 240690
2015-06-25 20:47:59 +00:00
Dmitry Vyukov 7c63340586 tsan: fix handling of dup2
Previously tsan modelled dup2(oldfd, newfd) as write on newfd.
We hit several cases where the write lead to false positives:
1. Some software dups a closed pipe in place of a socket before closing
   the socket (to prevent races actually).
2. Some daemons dup /dev/null in place of stdin/stdout.
On the other hand we have not seen cases when write here catches real bugs.
So model dup2 as read on newfd instead.

llvm-svn: 240687
2015-06-25 20:32:04 +00:00
Dmitry Vyukov b89a69dac6 tsan: merge function definition and declaration
llvm-svn: 240633
2015-06-25 11:45:45 +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
Alexey Samsonov 3fa03e3e9d [CMake] Fix PR23539: Don't reference C++ ABI symbols prior to Mac OS 10.9.
Summary:
This patch implements step 1 from
https://llvm.org/bugs/show_bug.cgi?id=23539#c10

I'd appreciate if you could test it on Mac OS and verify that parts of UBSan
runtime that reference C++ ABI symbols are properly excluded, and fix ASan/UBSan
builds.

Test Plan: regression test suite

Reviewers: thakis, hans

Subscribers: llvm-commits, zaks.anna, kubabrecka

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

llvm-svn: 240617
2015-06-25 00:57:42 +00:00
Chris Bieneman a9e77abc68 One more change required to build the sanitizers for iOS.
Summary: _Unwind_Backtrace is not available on iOS, so we should ifdef out the posix implementations of BufferedStackTrace::SlowUnwindStack and BufferedStackTrace::SlowUnwindStackWithContext on iOS.

Reviewers: samsonov

Reviewed By: samsonov

Subscribers: llvm-commits

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

llvm-svn: 240586
2015-06-24 20:13:44 +00:00
Dmitry Vyukov d58df749c1 tsan: fix false positive between dlopen and dl_iterate_phdr
We see false reports between dlopen and dl_iterate_phdr.
This happens because tsan does not see dynamic linker
internal synchronization. Unpoison module names
in dl_iterate_phdr callback.

llvm-svn: 240576
2015-06-24 19:49:32 +00:00
Peter Collingbourne 19e86199f1 SafeStack: Add another missing header to try to fix FreeBSD build.
llvm-svn: 240564
2015-06-24 18:16:05 +00:00
Peter Collingbourne 8454044b1f SafeStack: Add #include of <stdint.h>.
Should fix the FreeBSD build.

llvm-svn: 240555
2015-06-24 17:23:13 +00:00
Dmitry Vyukov b086a70206 asan: fix 32-bit build
llvm-svn: 240541
2015-06-24 13:27:56 +00:00
Dmitry Vyukov c871c03550 tsan: don't print external PCs in reports
They are meaningless.

llvm-svn: 240539
2015-06-24 13:04:12 +00:00
Dmitry Vyukov 89e0d57157 tsan: fix unbounded memory consumption for large mallocs
This happens only in corner cases, but we observed this on a real app.
See the test for description of the exact scenario that lead to unbounded memory consumption.

llvm-svn: 240535
2015-06-24 11:51:41 +00:00
Peter Collingbourne adbde27d2d Update SafeStack TODO in the safestack.cc
This patch clarifies the TODO note at the top of safestack.cc and brings
it more in sync with what we (the CPI team) actually plan to work on in
the future.

Patch by Volodymyr Kuznetsov!

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

llvm-svn: 240473
2015-06-23 22:26:48 +00:00
Chris Bieneman f1ba141041 Working on reconciling out-of-tree patches to compiler-rt for building for iOS.
Summary:
This is one of many changes needed for compiler-rt to get it building on iOS.

Darwin doesn't have _Unwind_VRS_Get, instead use _Unwind_GetIP directly.

Note: this change does not enable building for iOS, as there are more changes to come.

Reviewers: kubabrecka, bogner, samsonov

Reviewed By: samsonov

Subscribers: samsonov, llvm-commits

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

llvm-svn: 240470
2015-06-23 21:39:57 +00:00
Chris Bieneman d1a1444c1a Working on reconciling out-of-tree patches to compiler-rt for building for iOS.
Summary:
This is one of many changes needed for compiler-rt to get it building on iOS.

This change ifdefs out headers and functionality that aren't available on iOS, and adds support for iOS and the iOS simulator to as an.

Note: this change does not enable building for iOS, as there are more changes to come.

Reviewers: glider, kubabrecka, bogner, samsonov

Reviewed By: samsonov

Subscribers: samsonov, zaks.anna, llvm-commits

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

llvm-svn: 240469
2015-06-23 21:39:54 +00:00
Chris Bieneman 04f0643a76 Working on reconciling out-of-tree patches to compiler-rt for building for iOS.
Summary:
This is one of many changes needed for compiler-rt to get it building on iOS.

This change ifdefs out headers and functionality that aren't available on iOS.

Note: this change does not enable building for iOS, as there are more changes to come.

Reviewers: glider, kubabrecka, bogner, samsonov

Reviewed By: samsonov

Subscribers: samsonov, llvm-commits

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

llvm-svn: 240468
2015-06-23 21:39:52 +00:00
Chris Bieneman e13272a008 Working on reconciling out-of-tree patches to compiler-rt for building for iOS.
Summary:
This is one of many changes needed for compiler-rt to get it building on iOS.

This change does the following:
- Don't include crt_externs on iOS (it isn't available)
- Support ARM thread state objects

Note: this change does not enable building for iOS, as there are more changes to come.

Reviewers: glider, kubabrecka, bogner, samsonov

Reviewed By: samsonov

Subscribers: samsonov, aemerson, llvm-commits

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

llvm-svn: 240467
2015-06-23 21:39:49 +00:00
Pirama Arumuga Nainar 4a39e80809 Fix incorrect truncation at the overflow boundary
Summary:
This patch fixes incorrect truncation when the input wider value is
exactly 2^dstBits.  For that value, the overflow to infinity is not
correctly handled.  The fix is to replace a strict '>' with '>='.

Currently,
__truncdfsf2(340282366900000000000000000000000000000.0) returns infinity
__truncdfsf2(340282366920938463463374607431768211456.0) returns 0
__truncdfsf2(400000000000000000000000000000000000000.0) returns infinity

Likewise, __truncdfhf2 and __truncsfhf2 (and consequently gnu_f2h_ieee)
are discontinuous at 65536.0.

This patch adds tests for all three cases, along with adding a missing
header include to fp_test.h.

Reviewers: joerg, ab, srhines

Subscribers: llvm-commits

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

llvm-svn: 240450
2015-06-23 20:24:53 +00:00
Frederic Riss 66c868ce27 [Sanitizers] Pass the correct arch to the symbolizer for x86_64h
I have no idea how to directly test that as it depends on a particular
(micro-)architecure of the host processor.
Combined with llvm's r240339 this should fix issues people might have
be seeing intermitently on Darwin haswell machines (the symbolizer
would use the wrong slice of the binary, thus potentially resolving
to the wrong symbol).

llvm-svn: 240379
2015-06-23 05:35:19 +00:00
Filipe Cabecinhas 7af0a1cb84 CMake: Stop using LLVM's custom parse_arguments. NFC
Summary:
Use CMake's cmake_parse_arguments() instead.
It's called in a slightly different way, but supports all our use cases.
It's in CMake 2.8.8, which is our minimum supported version.

CMake 3.0 doc (roughly the same. No direct link to 2.8.8 doc):
http://www.cmake.org/cmake/help/v3.0/module/CMakeParseArguments.html?highlight=cmake_parse_arguments

Since I was already changing these calls, I changed ARCH and LIB into
ARCHS and LIBS to make it more clear that they're lists of arguments.

Reviewers: eugenis, samsonov, beanz

Subscribers: llvm-commits

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

llvm-svn: 240120
2015-06-19 03:39:24 +00:00
Peter Collingbourne 175d633271 Add control flow integrity diagnosis function to UBSan runtime library.
Also includes execution tests for the feature.

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

llvm-svn: 240111
2015-06-19 01:52:55 +00:00
Alexey Samsonov 2a567835d1 Revert "Revert "[CMake] LSan is not actually available on Darwin.""
Re-land fixed version of r239955.

llvm-svn: 240108
2015-06-19 01:34:06 +00:00
Evgeniy Stepanov 9a10674079 [msan] Intercept fopencookie.
https://code.google.com/p/memory-sanitizer/issues/detail?id=86

llvm-svn: 240107
2015-06-19 01:28:41 +00:00
Dmitry Vyukov 70dd0e2087 tsan: mark meta shadow as NOHUGEPAGE
Meta shadow is compressing and we don't flush it,
so it makes sense to mark it as NOHUGEPAGE to not over-allocate memory.
On one program it reduces memory consumption from 5GB to 2.5GB.

llvm-svn: 240028
2015-06-18 16:57:37 +00:00
Justin Bogner 66afb72e2a Revert "[CMake] LSan is not actually available on Darwin."
This change makes cmake fail to even run on Darwin with errors
evaluating "$<TARGET_OBJECTS:RTInterception.x86_64>".

This reverts r239955

llvm-svn: 239985
2015-06-18 03:39:51 +00:00
Alexey Samsonov b412c47934 [CMake] Remove redundant checks in TSan CMakeLists.txt
llvm-svn: 239956
2015-06-17 22:24:49 +00:00
Alexey Samsonov 5cce9e1e59 [CMake] LSan is not actually available on Darwin.
llvm-svn: 239955
2015-06-17 22:24:44 +00:00
Peter Collingbourne b64d0b1e6d Protection against stack-based memory corruption errors using SafeStack: compiler-rt runtime support library
This patch adds runtime support for the Safe Stack protection to compiler-rt
(see http://reviews.llvm.org/D6094 for the detailed description of the
Safe Stack).

This patch is our implementation of the safe stack on top of compiler-rt. The
patch adds basic runtime support for the safe stack to compiler-rt that
manages unsafe stack allocation/deallocation for each thread.

Original patch by Volodymyr Kuznetsov and others at the Dependable Systems
Lab at EPFL; updates and upstreaming by myself.

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

llvm-svn: 239763
2015-06-15 21:08:47 +00:00
Chris Bieneman 6bd006f31a [CMake] Cleanup add_compiler_rt_object_library to be platform-agnostic
Summary:
This change takes darwin-specific goop that was scattered around CMakeLists files and spread between add_compiler_rt_object_library and add_compiler_rt_darwin_object_library and moves it all under add_compiler_rt_object_library.

The goal of this is to try to push platform handling as low in the utility functions as possible.

Reviewers: rnk, samsonov

Reviewed By: rnk, samsonov

Subscribers: rnk, rsmith, llvm-commits

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

llvm-svn: 239498
2015-06-10 23:55:07 +00:00
Evgeniy Stepanov e33f64f682 [asan] Fix Android build for API >= 21.
/code/llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc:971:8: error: address of function 'dl_iterate_phdr' will always evaluate to 'true' [-Werror,-Wpointer-bool-conversion]
  if (!dl_iterate_phdr)
      ~^~~~~~~~~~~~~~~
/code/llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc:971:8: note: prefix with the address-of operator to silence this warning
  if (!dl_iterate_phdr)
       ^
       &

llvm-svn: 239321
2015-06-08 18:15:52 +00:00
Evgeniy Stepanov 572cd900b2 [asan] Fix build of AsanNoinstTest on Android.
Some of the asan-ubsan build changes were not replicated in the android branch in CMakeLists.

llvm-svn: 239320
2015-06-08 18:03:33 +00:00
Alexey Samsonov 9f97bf0943 [ASan] Bump maximum allowed malloc() size in ASan allocator to 1Tb.
1Tb of RAM ought to be enough for anybody.

llvm-svn: 239187
2015-06-05 20:50:02 +00:00
Yury Gribov 2d45554b82 [ASan] Add process basename to log name and error message to
simplify analysis of sanitized systems logs.
    
Differential Revision: http://reviews.llvm.org/D7333

llvm-svn: 239134
2015-06-05 06:08:23 +00:00
Yury Gribov e244b49f2c [ASan] Fix Darwin and Windows builds.
llvm-svn: 239027
2015-06-04 07:56:19 +00:00
Yury Gribov c019a57099 [ASan] Make binary name reader cross-platform.
Differential Revision: http://reviews.llvm.org/D10213

llvm-svn: 239020
2015-06-04 07:29:43 +00:00
Yury Gribov c5243f0c6a [ASan] Move ASan runtime library self-checks to a more appropriate place.
llvm-svn: 239018
2015-06-04 07:23:09 +00:00
Filipe Cabecinhas 215046bf98 [sanitizer_common] Added VS-style output for source locations
Summary:
With this patch, we have a flag to toggle displaying source locations in
the regular style:
file:line:column

or Visual Studio style:
file(line,column)

This way, they get picked up on the Visual Studio output window and one
can double-click them to get to that file location.

Reviewers: samsonov, rnk

Subscribers: llvm-commits

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

llvm-svn: 239000
2015-06-04 01:20:06 +00:00
Evgeniy Stepanov 1b3d46ec30 [asan] Fix undefined MAP_NORESERVE on FreeBSD.
llvm-svn: 238995
2015-06-04 00:42:15 +00:00
Evgeniy Stepanov 42fb96652b [sanitizer] Add -lrt to dyndd link line.
llvm-svn: 238626
2015-05-29 22:57:15 +00:00