Commit Graph

53 Commits

Author SHA1 Message Date
Alex Shlyapnikov c73d1e28f1 [ASan] Enhance libsanitizer support for invalid-pointer-pair.
Following patch adds support of all memory origins in
CheckForInvalidPointerPair function. For small difference of pointers,
it's directly done in shadow memory (the limit was set to 2048B).
Then we search for origin of first pointer and verify that the second
one has the same origin. If so, we verify that it points either to a same
variable (in case of stack memory or a global variable), or to a same
heap segment.

Committing on behanf of marxin and jakubjelinek.

Reviewers: alekseyshl, kcc

Subscribers: llvm-commits

Differential revision: https://reviews.llvm.org/D40600

llvm-svn: 319668
2017-12-04 18:00:24 +00:00
Vitaly Buka 86dd088f4d [asan] Remove ScopedDeadlySignal
This is used only to make fast = true in GetStackTraceWithPcBpAndContext
on SANITIZER_FREEBSD and SANITIZER_NETBSD and can be done explicitly.

llvm-svn: 313517
2017-09-18 06:56:57 +00:00
Vitaly Buka 7030354744 [asan] Refactor thread creation bookkeeping
Summary:
This is a pure refactoring change.  It paves the way for OS-specific
implementations, such as Fuchsia's, that can do most of the
per-thread bookkeeping work in the creator thread before the new
thread actually starts.  This model is simpler and cleaner, avoiding
some race issues that the interceptor code for thread creation has
to do for the existing OS-specific implementations.

Submitted on behalf of Roland McGrath.

Reviewers: vitalybuka, alekseyshl, kcc

Reviewed By: alekseyshl

Subscribers: phosek, filcab, llvm-commits, kubamracek

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D36385

llvm-svn: 310432
2017-08-09 00:38:57 +00:00
Kuba Mracek ceb30b0717 [sanitizer] Introduce tid_t as a typedef for OS-provided thread IDs
We seem to assume that OS-provided thread IDs are either uptr or int, neither of which is true on Darwin. This introduces a tid_t type, which holds a OS-provided thread ID (gettid on Linux, pthread_threadid_np on Darwin, pthread_self on FreeBSD).

Differential Revision: https://reviews.llvm.org/D31774

llvm-svn: 300473
2017-04-17 18:17:38 +00:00
Dmitry Vyukov b3587836bc [ASAN] Pass previous stack information through __sanitizer_finish_switch_fiber
This patch extends __sanitizer_finish_switch_fiber method to optionally return previous stack base and size.

This solves the problem of coroutines/fibers library not knowing the original stack context from which the library is used. It's incorrect to assume that such context is always the default stack of current thread (e.g. one such library may be used from a fiber/coroutine created by another library). Bulding a separate stack tracking mechanism would not only duplicate AsanThread, but also require each coroutines/fibers library to integrate with it.

Author: Andrii Grynenko (andriigrynenko)
Reviewed in: https://reviews.llvm.org/D24628

llvm-svn: 282582
2016-09-28 12:28:16 +00:00
Dmitry Vyukov 47b7c5c912 [asan] add primitives that allow coroutine implementations
This patch adds the __sanitizer_start_switch_fiber and
__sanitizer_finish_switch_fiber methods inspired from what can be found here
2ea64dd249 .

These methods are needed when the compiled software needs to implement
coroutines, fibers or the like. Without a way to annotate them, when the program
jumps to a stack that is not the thread stack, __asan_handle_no_return shows a
warning about that, and the fake stack mechanism may free fake frames that are
still in use.

Author: blastrock (Philippe Daouadi)
Reviewed in http://reviews.llvm.org/D20913

llvm-svn: 273260
2016-06-21 12:29:18 +00:00
Alexey Samsonov 5535c51606 [LSan] Use __tls_get_addr interceptor to keep track of dynamic TLS.
Summary:
We have a way to keep track of allocated DTLS segments: let's use it
in LSan. Although this code is fragile and relies on glibc
implementation details, in some cases it proves to be better than
existing way of tracking DTLS in LSan: marking as "reachable" all
memory chunks allocated directly by "ld".

The plan is to eventually get rid of the latter, once we are sure
it's safe to remove.

Reviewers: kcc

Subscribers: llvm-commits

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

llvm-svn: 257785
2016-01-14 18:50:09 +00:00
Vedant Kumar 59ba7b8cd1 [compiler-rt] Apply modernize-use-nullptr fixes in sanitizers
- 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

llvm-svn: 248966
2015-10-01 00:22:21 +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 Kornienko d829812f65 Use 'override/final' instead of 'virtual' for overridden methods
The patch is generated using clang-tidy misc-use-override check.

This command was used:

  tools/clang/tools/extra/clang-tidy/tool/run-clang-tidy.py \
    -checks='-*,misc-use-override' -header-filter='llvm|clang' -j=32 -fix \
    -format

llvm-svn: 234680
2015-04-11 02:44:24 +00:00
Sergey Matveev eba518be94 [ASan] Refactor thread starting code.
Move thread context creation into AsanThread::Create().

llvm-svn: 223483
2014-12-05 17:31:13 +00:00
Sergey Matveev b029c5101f [ASan, LSan] Improve tracking of thread creation.
In the current scheme of things, the call to ThreadStart() in the child
thread is not synchronized with the parent thread. So, if a pointer is passed to
pthread_create, there may be a window of time during which this pointer will not
be discoverable by LSan. I.e. the pthread_create interceptor has already
returneed and thus the pointer is no longer on the parent stack, but we don't
yet know the location of the child stack. This has caused bogus leak reports
(see http://llvm.org/bugs/show_bug.cgi?id=21621/).

This patch makes the pthread_create interceptor wait until the child thread is
properly registered before returning.

llvm-svn: 223419
2014-12-05 00:10:15 +00:00
Viktor Kutuzov dc6cbfe859 [Sanitizers] Enable stack traces on FreeBSD
Differential Revision: http://reviews.llvm.org/D6086

llvm-svn: 221595
2014-11-10 15:22:04 +00:00
Alexey Samsonov 0470e24780 [ASan] Make stack-buffer-overflow reports more robust
Summary:
Fix the function that gets stack frame description by address in
thread stack, so that it clearly indicates failures. Make this error non-fatal,
and print as much information as we can in this case. Make all errors in
ParseFrameDescription non-fatal.

Test Plan: check-asan testsuite

Reviewers: kcc

Reviewed By: kcc

Subscribers: llvm-commits

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

llvm-svn: 218819
2014-10-01 21:13:00 +00:00
Alexey Samsonov 3d9adc0a73 [ASan] Speed up stack trace unwinding for stacks of size 2.
Summary:
We don't need to do any work in this case - just take
the current PC and caller PC.

Reviewers: eugenis, ygribov

Reviewed By: eugenis

CC: llvm-commits

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

llvm-svn: 202845
2014-03-04 13:12:25 +00:00
Kostya Serebryany 7a3a93f112 [asan] if verbosity>=2, print the fake stack usage stats at thread exit; No functionality change in non-verboze mode
llvm-svn: 197037
2013-12-11 13:54:01 +00:00
Alexey Samsonov e0e31c4a30 [ASan] Clarify that AsanThread objects are allocated only via mmap(). No functionality change.
llvm-svn: 195840
2013-11-27 13:22:21 +00:00
Kostya Serebryany 9628839869 [asan] reduce the size of AsanThreadContext by storing the stack trace in the stack depot
llvm-svn: 192979
2013-10-18 14:50:44 +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
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
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
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
Kostya Serebryany 43c4493b44 [asan] second attempt to use TLS with fake stack. This time it looks (more) async-signal safe.
llvm-svn: 190663
2013-09-13 06:32:26 +00:00
Kostya Serebryany 736bd08e05 [asan] don't lazy-init fake_stack if we only need to check that fake_stack exists (should fix 32-bit builds)
llvm-svn: 190593
2013-09-12 08:43:44 +00:00
Kostya Serebryany 628cda7367 [asan] hopefully make the FakeStack async-signal safe, enable the related test
llvm-svn: 190592
2013-09-12 08:34:50 +00:00
Evgeniy Stepanov 58dbe06230 [asan] Fix deadlock in stack unwinder on android/x86.
Fixes PR17116.
Patch by 林作健 (manjian2006 at gmail.com).

llvm-svn: 190590
2013-09-12 08:16:28 +00:00
Kostya Serebryany 729c8dc65b [asan] fully re-implement the FakeStack (use-after-return) to make it faster and async-signal-safe. The implementation is not yet complete (see FIXMEs) but the existing tests pass.
llvm-svn: 190588
2013-09-12 07:11:58 +00:00
Sergey Matveev bdeff959a1 [lsan] Handle fork() correctly.
Update the main thread's os_id on every pthread_create, and before
initiating leak checking. This ensures that we have the correct os_id even if we
have forked after Init().

llvm-svn: 185815
2013-07-08 12:57:24 +00:00
Kostya Serebryany 6a068a715d [asan] initialize fake_stack lazily and increase its maximal size. This makes -fsanitize=address,use-after-return more robust: all SPEC tests pass now. In the default mode thread stacks become a bit smaller.
llvm-svn: 184934
2013-06-26 12:16:05 +00:00
Sergey Matveev b94d5e2d1c [asan] Move lsan_disabled out of thread context.
Fix for the case where disabler is used in pthread key destructor.

llvm-svn: 184553
2013-06-21 14:51:52 +00:00
Sergey Matveev 17ee1abfa7 [lsan] Add __lsan_disable() and __lsan_enable().
Objects allocated after a call to __lsan_disable() will be treated as
live memory. Also add a ScopedDisabler.

llvm-svn: 183099
2013-06-03 11:21:34 +00:00
Sergey Matveev 09886cd17a [asan] Make ASan report the correct thread address ranges to LSan.
This CL enables thread support in LSan when used on top of ASan.

llvm-svn: 182854
2013-05-29 13:09:44 +00:00
Kostya Serebryany 4e0a33c8be [asan] move fake stack into a separate .h file; actually disable a failing test
llvm-svn: 179273
2013-04-11 11:39:19 +00:00
Kostya Serebryany 667a34a120 [asan] Change the way we report the alloca frame on stack-buff-overflow.
Before: the function name was stored by the compiler as a constant string
and the run-time was printing it.
Now: the PC is stored instead and the run-time prints the full symbolized frame.
This adds a couple of instructions into every function with non-empty stack frame,
but also reduces the binary size because we store less strings (I saw 2% size reduction).
This change bumps the asan ABI version to v3.

compiler-rt part, llvm part will follow.

Example of report (now):
==31711==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fffa77cf1c5 at pc 0x41feb0 bp 0x7fffa77cefb0 sp 0x7fffa77cefa8
READ of size 1 at 0x7fffa77cf1c5 thread T0
    #0 0x41feaf in Frame0(int, char*, char*, char*) stack-oob-frames.cc:20
    #1 0x41f7ff in Frame1(int, char*, char*) stack-oob-frames.cc:24
    #2 0x41f477 in Frame2(int, char*) stack-oob-frames.cc:28
    #3 0x41f194 in Frame3(int) stack-oob-frames.cc:32
    #4 0x41eee0 in main stack-oob-frames.cc:38
    #5 0x7f0c5566f76c (/lib/x86_64-linux-gnu/libc.so.6+0x2176c)
    #6 0x41eb1c (/usr/local/google/kcc/llvm_cmake/a.out+0x41eb1c)
Address 0x7fffa77cf1c5 is located in stack of thread T0 at offset 293 in frame
    #0 0x41f87f in Frame0(int, char*, char*, char*) stack-oob-frames.cc:12  <<<<<<<<<<<<<< this is new
  This frame has 6 object(s):
    [32, 36) 'frame.addr'
    [96, 104) 'a.addr'
    [160, 168) 'b.addr'
    [224, 232) 'c.addr'
    [288, 292) 's'
    [352, 360) 'd'

llvm-svn: 177723
2013-03-22 10:36:24 +00:00
Alexey Samsonov 54afba8b62 [ASan] Switch ASan to generic ThreadRegistry from sanitizer_common. Delete ASan-specific AsanThreadRegistry.
llvm-svn: 177634
2013-03-21 11:23:41 +00:00
Alexey Samsonov cf025cb2e6 [ASan] Move GetCurrentThread/SetCurrentThread from AsanThreadRegistry class into plain functions: they don't actually use registry
llvm-svn: 177501
2013-03-20 09:23:28 +00:00
Kostya Serebryany e7108227ca [asan] intercept prctl(PR_SET_NAME) and set the thread name. Output the thread names (if non-empty) in asan reports
llvm-svn: 169601
2012-12-07 15:15:01 +00:00
Alexey Samsonov c402cb62fd [ASan] Add print_full_thread_history runtime option (on by default) that prints all full thread creation paths for threads involved in ASan error report
llvm-svn: 163200
2012-09-05 07:37:15 +00:00
Alexey Samsonov c3a8119a41 Whitespace/lint
llvm-svn: 162909
2012-08-30 14:22:21 +00:00
Kostya Serebryany a57b4e823a [asan] even more refactoring to move StackTrace to sanitizer_common
llvm-svn: 162754
2012-08-28 13:49:49 +00:00
Kostya Serebryany 6b0d775229 [asan] some renaming before we move StackTrace into sanitizer_common
llvm-svn: 162747
2012-08-28 11:54:30 +00:00
Kostya Serebryany bb6f165952 [asan] get rid of AsanPrintf in favor of Printf from sanitizer_common
llvm-svn: 162746
2012-08-28 11:34:40 +00:00
Kostya Serebryany 78713bc574 [asan] get rid of the last operator new call in asan rtl
llvm-svn: 160347
2012-07-17 07:20:13 +00:00
Kostya Serebryany 79437fe376 [asan] make tid u32 instead of int
llvm-svn: 158074
2012-06-06 15:06:58 +00:00
Alexey Samsonov 51ae983718 [Sanitizer]: Introduce a common internal printf function. For now, also use tool-specific wrappers TsanPrintf (its output is controlled by TSan flags) and AsanPrintf (which copies its results to the ASan-private buffer). Supported formats: %[z]{d,u,x}, %s, %p. Re-write all format strings in TSan according to this format (this should have no effect on 64-bit platforms).
llvm-svn: 158065
2012-06-06 13:11:29 +00:00
Kostya Serebryany 8d03204204 [asan] more renaming
llvm-svn: 157746
2012-05-31 14:35:53 +00:00
Kostya Serebryany 02d5ec5ecf [asan] increase the stack size limit to 256M (yes, that happens); also CHECK that the stack size is less than that on a non-main thread
llvm-svn: 157249
2012-05-22 11:54:44 +00:00
Timur Iskhodzhanov 0f9c9a5332 [ASan] Intercept CreateThread on Windows
llvm-svn: 151366
2012-02-24 15:28:43 +00:00
Kostya Serebryany b5eb5a7a05 [asan] make sure the AsanThread object is destroyed if pthread_exit is called
llvm-svn: 149940
2012-02-07 00:27:15 +00:00
Alexey Samsonov 2d3a67b73b AddressSanitizer: create AsanThreadSummary together with AsanThread (in parent thread)
llvm-svn: 148286
2012-01-17 06:35:31 +00:00