Commit Graph

734 Commits

Author SHA1 Message Date
Mike Aizatsky 04897dcc3d [sanitizers] trace buffer API to use user-allocated buffer.
Subscribers: kubabrecka

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

llvm-svn: 277858
2016-08-05 20:09:42 +00:00
Reid Kleckner 628d6b5c81 Fix dumping of process module list and test it
I probably broke this a year ago in r243895.

llvm-svn: 277842
2016-08-05 17:55:00 +00:00
Bruno Cardoso Lopes 4e786cf3de [ASAN] Mark test/asan/TestCases/ill.cc as unsupported on darwin
Introduced in r277621, this test is currently failing all around in
public bots: http://lab.llvm.org:8080/green/job/clang-stage1-configure-RA_check/20787
and internal bots. Mark it as unsupported on darwin until we figure
out how it should behave.

llvm-svn: 277733
2016-08-04 15:57:30 +00:00
Reid Kleckner 15a3ce0f59 Only run ill.cc test on x86, 32 or 64 bit
llvm-svn: 277679
2016-08-03 23:24:06 +00:00
Reid Kleckner 222610bf10 [ASan] Report illegal instruction exceptions in ASan
Summary:
Respect the handle_sigill common flag and handle_segv flags while we're
at it.

We still handle signals/exceptions differently on Unix and Windows. The
installation process is tricky on Windows, and difficult to push down
into sanitizer_common without concerning it with the different
static/dynamic CRT models on Windows.

Reviewers: kcc, etienneb

Subscribers: llvm-commits, kubabrecka

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

llvm-svn: 277621
2016-08-03 18:13:14 +00:00
Reid Kleckner d6371ea52a [asan] Intercept RtlRaiseException instead of kernel32!RaiseException
Summary:
On my install of Windows 10, RaiseException is a tail call to
kernelbase!RaiseException. Obviously, we fail to intercept that.
Instead, try hooking at the ntdll!RtlRaiseException layer. It is
unlikely that this layer will contain control flow.

Intercepting at this level requires adding a decoding for
'LEA ESP, [ESP + 0xXXXXXXXX]', which is a really obscure way to write
'SUB ESP, 0xXXXXXXXX' that avoids clobbering EFLAGS.

Reviewers: etienneb

Subscribers: llvm-commits, kubabrecka

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

llvm-svn: 277518
2016-08-02 20:36:29 +00:00
Reid Kleckner dabcee8b2c Remove stale CHECK lines that should have been included in r277478
We no longer assign ids to unregistered threads. We don't have any stack
trace for thread creation for these worker threads, so this shouldn't
affect report quality much.

llvm-svn: 277514
2016-08-02 20:26:59 +00:00
Reid Kleckner b0e4a86e05 [asan] Remove NtWaitForWorkViaWorkerFactory interceptor
Summary:
On Windows 10, this gets called after TLS has been torn down from NTDLL,
and we crash attempting to return fake_tsd. This interceptor isn't
needed after r242948 anyway, so let's remove it. The ASan runtime can
now tolerate unregistered threads calling __asan_handle_no_return.

Reviewers: vitalybuka, etienneb

Subscribers: kubabrecka, llvm-commits

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

llvm-svn: 277478
2016-08-02 16:17:32 +00:00
Evgeniy Stepanov 6c25e57a56 [asan] Disable android-coverage test on anything other than arm.
llvm-svn: 277395
2016-08-01 21:58:34 +00:00
Maxim Ostapenko 9f0546b5a9 [asan] Reduce flakiness of heavy recovery mode tests.
When we run halt_on_error-torture.cc with 10 threads and 20 iterations with halt_on_error=false:suppress_equal_pcs=false, we write 200 reports to 10.txt file and sometimes have collisions.
We have CHECK-COLLISION check that greps 'AddressSanitizer: nested bug in the same thread, aborting' message in 10.txt, but it doesn't contain this line.
If I don't redirect stderr > 10.txt 'AddressSanitizer: nested bug in the same thread, aborting' is printed to my screen as expected.
Same happens for halt_on_error_suppress_equal_pcs.cc and halt_on_error-torture.cc. This happens because of kernel bug: https://lkml.org/lkml/2014/2/17/324
Furtunately, we can fix these tests by implicitly setting O_APPEND for opened files (use >> instead of > for stderr redirection).

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

llvm-svn: 277324
2016-08-01 07:24:36 +00:00
Dimitry Andric 41d9b3640c Fix ASan alloca_constant_size.cc test on FreeBSD.
On FreeBSD <alloca.h> does not exist: alloca(3) is defined in <stdlib.h>
instead.

llvm-svn: 277300
2016-07-31 20:16:59 +00:00
Vitaly Buka 49dd9d23cc [asan] Enable the rest of use-after-scope tests
Summary:
Test where broken because of missing lifetime markers for temps and
because of aggressive optimization which removed markers in some cases.

PR27453

Reviewers: eugenis, kcc

Subscribers: llvm-commits, kubabrecka

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

llvm-svn: 277074
2016-07-28 23:03:27 +00:00
Reid Kleckner ff3ea5f4f8 Try to fix more Windows portability issues in sanitizer tests
Add a %stdcxx11 lit substitution for -std=c++11. Windows defaults to
-std=c++14 when VS 2015 is used because the STL requires it. Harcoding
-std=c++11 in the ASan tests actually downgrades the C++ standard level,
leading to test failures.

Relax a FileCheck pattern in use-after-scope-types.cc.

Disable the sanitizer_common OOM tests. They fail on bots with low swap,
and cause other concurrently running tests to OOM.

llvm-svn: 276454
2016-07-22 18:41:22 +00:00
Vitaly Buka 43efcced31 Fix test on windows, symbolizer returns invalid line
llvm-svn: 276381
2016-07-22 01:47:28 +00:00
Kostya Serebryany 8258686922 [asan] revert to using -std=c++11 on test/asan/TestCases/use-after-scope-capture.cc to fix Linux failures after r276332. This probably breaks the windows build, sorry, but returns to the earlier status quo.
llvm-svn: 276379
2016-07-22 01:34:32 +00:00
Vitaly Buka 60cb0b55c9 fix windows
llvm-svn: 276378
2016-07-22 01:34:12 +00:00
Vitaly Buka be6328b078 Fix test on windows
llvm-svn: 276376
2016-07-22 01:12:04 +00:00
Vitaly Buka 0a3e932e1d Add test to check detection of stack-use-after-scope on various types
Summary:
Test for D22657

PR27453

Reviewers: kcc, eugenis

Subscribers: kubabrecka

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

llvm-svn: 276375
2016-07-22 00:58:06 +00:00
Reid Kleckner 1558a2f3ee [asan] Fix Win64 test portability issues
The OOM test should really only run on 32-bits, since it's hard to OOM
on x64.

The operator_array_new_with_dtor_left_oob tests need to account for the
larger array cookie on x64 (8 bytes instead of 4).

Use -std=c++14 in use-after-scope-capture.cc to avoid errors in the MSVC
2015 STL on Windows. The default there is C++14 anyway.

llvm-svn: 276332
2016-07-21 21:04:34 +00:00
Etienne Bergeron 1acbc5207d Fix unsymbolize unittest. Adding win64 address.
llvm-svn: 276326
2016-07-21 20:02:03 +00:00
Etienne Bergeron 29539a0b7d [compiler-rt] Fix interception of memcpy/memmove on win64
Summary:
This patch is fixing running interception unittests for memcpy/memmove on
windows 64.

Reviewers: rnk

Subscribers: llvm-commits, wang0109, kubabrecka, chrisha

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

llvm-svn: 276324
2016-07-21 19:49:11 +00:00
Etienne Bergeron c6b096572e [compiler-rt] Disable some unittests on windows that rely on shell command
Summary:
These unittests are not running on windows because they are using incorrect commands.
They were not failing on 32-bits because there is a requirement: asan-64-bits.

```
$ "nm" "C:\src\llvm\ninja64\projects\compiler-rt\test\asan\X86_64WindowsConfig\TestCases\Output\no_asan_gen_globals.c.tmp.exe"
# command stderr:
'nm': command not found
error: command failed with exit status: 127
```

```
$ "rm" "-rf" "C:\src\llvm\ninja64\projects\compiler-rt\test\asan\X86_64WindowsConfig\TestCases\Output/coverage-tracing"
$ "mkdir" "C:\src\llvm\ninja64\projects\compiler-rt\test\asan\X86_64WindowsConfig\TestCases\Output/coverage-tracing"
$ "A=x"
# command stderr:
'A=x': command not found
error: command failed with exit status: 127
```


```
$ "DIR=C:\src\llvm\ninja64\projects\compiler-rt\test\asan\X86_64WindowsConfig\TestCases\Output/coverage-order-pcs"
# command stderr:
'DIR=C:\\src\\llvm\\ninja64\\projects\\compiler-rt\\test\\asan\\X86_64WindowsConfig\\TestCases\\Output/coverage-order-pcs': command not found
error: command failed with exit status: 127
```

Reviewers: rnk

Subscribers: tberghammer, llvm-commits, danalbert, wang0109, srhines, kubabrecka, chrisha

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

llvm-svn: 276290
2016-07-21 14:55:17 +00:00
Etienne Bergeron 65e38a53b3 [compiler-rt] Fix broken unittest on win64
Summary:
This is an other tentative to fix:
https://reviews.llvm.org/D22588

It's less clever, but should work.

Turn out there is not an easy way to write a portable print
for a pointer in lowercase without the prefix 0x.

Reviewers: rnk

Subscribers: llvm-commits, wang0109, kubabrecka, chrisha

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

llvm-svn: 276286
2016-07-21 14:36:25 +00:00
Etienne Bergeron d4528b2ea1 [compiler-rt] Fix broken SymInitialize unittest
Summary:
By adding the initialisation of the symbolisation library (DbgHelp)
we are swapping the order in which both warnings are produced.

We can't use CHECK-NEXT as the dbghelp warning is multiline.

Reviewers: rnk

Subscribers: kubabrecka, llvm-commits, wang0109, chrisha

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

llvm-svn: 276228
2016-07-21 02:32:37 +00:00
Etienne Bergeron 913feb2a0d revert rL276179: [compiler-rt] Fix broken unittest related to 64-bit print format
llvm-svn: 276187
2016-07-20 21:38:02 +00:00
Etienne Bergeron 0e4cf2f6b3 [compiler-rt] Fix broken unittest related to 64-bit print format
Summary:
The printf is not working correctly on 64-bit MSVC.

The portable way to print "size_t" is to use "%zx" (size_t in hexa).

Reviewers: rnk

Subscribers: kubabrecka, llvm-commits, wang0109, chrisha

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

llvm-svn: 276179
2016-07-20 20:55:02 +00:00
Etienne Bergeron 055bdb96f5 fix flaky test on windows sanitizer bots
llvm-svn: 276143
2016-07-20 17:35:15 +00:00
Kostya Serebryany 018259cd9b [asan] trying to fix the android bot
llvm-svn: 276134
2016-07-20 15:59:34 +00:00
Reid Kleckner bcb927ffc2 Try to deflake Windows/dll_host.cc test by not using repeated echo appending
llvm-svn: 276130
2016-07-20 15:28:49 +00:00
Etienne Bergeron 6de4bd62b1 [compiler-rt/asan] Disable irrelevant unittest on win64
Summary:
This test is allocating a 1gig chunk to make shadow allocation failed,
but on 64-bits architecture the test is working.

Reviewers: rnk

Subscribers: kubabrecka, llvm-commits, wang0109, chrisha

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

llvm-svn: 276122
2016-07-20 14:53:17 +00:00
Kostya Serebryany 1abc356e3e [asan] trying to fix the android bot
llvm-svn: 276031
2016-07-19 21:35:01 +00:00
Vitaly Buka 9f9c089fe2 Add detect_stack_use_after_scope runtime flag
Summary: This flag could be used to disable check in runtime.

Subscribers: kubabrecka

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

llvm-svn: 276004
2016-07-19 18:11:08 +00:00
Etienne Bergeron 83cc0622ec [compiler-rt] Fix Asan imports/exports unittest
Summary:
Avoid mismatch between imports/exports for 32-bit and 64-bits version.

The test is running grep over macros to detect which functions are
intercepted. Unfortunately, exception handlers differ in 32-bit and
64-bit.

This patch is removing the exception handlers from the test.

Reviewers: rnk

Subscribers: llvm-commits, wang0109, kubabrecka, chrisha

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

llvm-svn: 275982
2016-07-19 15:27:23 +00:00
Kostya Serebryany 4953a01461 [asan] trying to fix the windows build
llvm-svn: 275644
2016-07-15 23:13:03 +00:00
Kostya Serebryany ad0724692e [sanitizers] add interceptor for memmem; add weak hooks for strncasecmp, strcasecmp, strstr, strcasestr, memmem
llvm-svn: 275621
2016-07-15 21:28:58 +00:00
Maxim Ostapenko 26b0bc0bd6 [asan] Reduce flakiness of halt_on_error-torture.cc testcase.
It seems in some situations we have clashes on very first error so test only prints "nested bug in the same thread, aborting" rather than "use-after-poison", so remove corresponding " RUN: FileCheck %s < 10.txt" line.
Also, the two last " RUN: FileCheck --check-prefix=CHECK-COLLISION %s < 1.txt || FileCheck --check-prefix=CHECK-NO-COLLISION %s < 1.txt" look wrong, they should check 10.txt. Fix these lines too.

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

llvm-svn: 275539
2016-07-15 07:57:43 +00:00
Etienne Bergeron 47ea8f536d [compiler-rt] Fix missing argument in asan unittest
Summary:
Both test have the same command-line.
The second test is missing the /GS-.

Keep in mind that /GS is on by default.

Reviewers: rnk

Subscribers: llvm-commits, wang0109, kubabrecka, chrisha

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

llvm-svn: 275491
2016-07-14 22:16:31 +00:00
Vitaly Buka 0ba360bd68 Replace -mllvm -asan-use-after-scope=1 with -fsanitize-address-use-after-scope
Summary:
When test was added we had no -fsanitize-address-use-after-scope in clang
so we had to use -mllvm -asan-use-after-scope=1.

Reviewers: eugenis

Subscribers: kubabrecka

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

llvm-svn: 275475
2016-07-14 21:18:06 +00:00
Saleem Abdulrasool bcb8190f99 test: Use %clangxx in objc++ test files
These test in this change are objc++, but are built using %clang, not %clangxx.
The reason this works is the driver has been adding -lc++ for sanitizer enabled
builds. By making these tests use %clangxx, they no longer depend on the driver
linking to c++.  Doing so will allow us to prevent overlinking of libc++ for
applications.

llvm-svn: 274989
2016-07-09 21:14:36 +00:00
Ryan Govostes b395d7271d [asan] Update tests according to r274578
llvm-svn: 274579
2016-07-05 21:53:23 +00:00
Etienne Bergeron e6f424460a [compiler-rt] Fix broken unittest using alloca on MSVC.
Summary:
The alloca header is not present on windows.

This test was committed recently:
  http://reviews.llvm.org/D21509
  http://reviews.llvm.org/rL273889

Reviewers: rnk

Subscribers: llvm-commits, wang0109, chrisha, kubabrecka

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

llvm-svn: 274230
2016-06-30 14:37:02 +00:00
Kuba Brecka 7d1ebed0c5 [asan] fix false dynamic-stack-buffer-overflow report with constantly-sized dynamic allocas, compiler-rt part
See the bug report at https://github.com/google/sanitizers/issues/691. When a dynamic alloca has a constant size, ASan instrumentation will treat it as a regular dynamic alloca (insert calls to poison and unpoison), but the backend will turn it into a regular stack variable. The poisoning/unpoisoning is then broken. This patch will treat such allocas as static.

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

llvm-svn: 273889
2016-06-27 15:57:53 +00:00
Ryan Govostes d4492ee159 Move -ldl to the correct compiler invocation
llvm-svn: 273844
2016-06-27 05:44:47 +00:00
Ryan Govostes 6f92bd38d8 [asan] Improve global-registration.c test
Removes use of GNU language extensions from the test, and hopefully fixes the
link order on Linux.

llvm-svn: 273741
2016-06-24 22:39:23 +00:00
Ryan Govostes 00f607eef0 Change shared library load path to appease Android bot
llvm-svn: 273654
2016-06-24 06:49:01 +00:00
Ryan Govostes 0ec8ab680f [asan] Add failure logging to global-registration.c test case
llvm-svn: 273629
2016-06-23 23:26:25 +00:00
Ryan Govostes 3c0f63c98b [asan] Fix global-registration.c on Linux
llvm-svn: 273476
2016-06-22 20:52:34 +00:00
Anna Zaks 0a494bd4d4 [asan] Relax a flaky invalid-pointer-pairs test
This test is flaky. Specifically, on some Mac configurations we see the
__sanitizer_ptr_cmp as the 0th frame. Let's relax it to not require that
f is in frame #0.

61396==ERROR: AddressSanitizer: invalid-pointer-pair: 0x01e00510 0x01e004d0
0 0x18f5a3 in __sanitizer_ptr_cmp ... libclang_rt.asan_osx_dynamic.dylib+0xaf5a3)
1 0xdd924 in f(char, char*, char*) ... invalid-pointer-pairs.cc:14:14

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

llvm-svn: 273475
2016-06-22 20:52:21 +00:00
Ryan Govostes f66146914b [asan] Add a test case for global registration
This test case checks that globals from all object files are being registered
after they've been linked together. It also checks that globals from libraries
loaded at runtime are registered.

llvm-svn: 273464
2016-06-22 19:59:10 +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
Evgeniy Stepanov 352289b679 Hide send/sendto/sendmsg interptors under a flag.
A runtime flag to enable checking in send* interceptors.
Checking is enabled by default.

llvm-svn: 273174
2016-06-20 17:57:51 +00:00
Evgeniy Stepanov 3c17c73924 [msan] Intercept send/sendto/sendmsg.
send/sendmsg moved from tsan to sanitizer_common; sendto is new.

llvm-svn: 272980
2016-06-17 00:43:11 +00:00
Kostya Serebryany 422ea24d45 [asan] make print_memory_profile_test more reliable by using large allocation sizes. Hoping to fix the llvm-clang-lld-x86_64-debian-fast bot
llvm-svn: 272020
2016-06-07 16:08:59 +00:00
Chandler Carruth 7573cfe2b3 It really helps to not randomly delete one of the closing brackets. =/
llvm-svn: 271787
2016-06-04 09:06:59 +00:00
Chandler Carruth b330dcab19 Ok, now I know why I kept getting confused and not making progress
fixing tis test. There are different configurations running, and they
have subtly different backtraces. I didn't notice that the configs
changed and so I kept occilating between the two.

Now I've looked at two different configs at the same time, and so this
should be much more likely to work.

llvm-svn: 271786
2016-06-04 08:54:57 +00:00
Chandler Carruth 9ef4243824 Fix the test for printing the memory profile. This fuctionality is only
available along side the leak checking, so use the REQUIRES for that.

Also, use %run as other tests do when launching the built binary.

This fixes check-asan for me on Linux and looks like it should fix the
linux sanitizer bots as well.

llvm-svn: 271785
2016-06-04 08:45:32 +00:00
Chandler Carruth ece6d7bf2e Update this test yet again, this time based on a nice consecutive pair
of lines provided with the filecheck output from the previous run. I'll
probably give up after this and get someone with a Windows build to help
me out.

llvm-svn: 271784
2016-06-04 08:24:56 +00:00
Chandler Carruth 4f785dc1f6 I didn't actually get this right, but now I have frame #0 and frame #2.
This should fail on frame #1 and show what that should actually be.

llvm-svn: 271783
2016-06-04 08:09:24 +00:00
Chandler Carruth d26defd57e Amazingly, my guess was correct for the top two frames here. Hopefully
with this, the Windows sanitizer bot will go green!

llvm-svn: 271782
2016-06-04 07:29:10 +00:00
Chandler Carruth 79abce39bb Temporary hack to this test to try and get the sanitizer-windows bot to
show enough information for me to fix the patterns used here.

llvm-svn: 271779
2016-06-04 06:16:49 +00:00
Kostya Serebryany 5a7159c416 [asan] add an interface function __sanitizer_print_memory_profile (a basic memory profiler; asan/Linux-only for now)
llvm-svn: 271463
2016-06-02 01:21:52 +00:00
Bill Seurer a143aed23c [powerpc] mark static_tls.cc test as UNSUPPORTED on powerpc64
An upcoming change for ld in binutils 2.26 causes this test to
always fail.

llvm-svn: 270223
2016-05-20 14:54:37 +00:00
Daniel Sanders 962b2cda9c [mips][ias] Two XFAIL's now pass on 32-bit MIPS.
llvm-svn: 269571
2016-05-14 16:18:16 +00:00
Kuba Brecka 7a947b6c6d Update test expectations after r269291 (Fix a crash when demangling Swift symbols).
llvm-svn: 269311
2016-05-12 17:08:25 +00:00
Maxim Ostapenko 6dccd5bc1f [asan] Bail out on stack overflow in recovery mode.
In recovery mode, when ASan detects stack overflow (say, when infinite recursion detected),
it tries to continue program execution and hangs on repetitive error reports. There isn't any
sense to do it, we can just bail out on stack overflow error, because the program would crash soon anyway.

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

llvm-svn: 268713
2016-05-06 07:09:22 +00:00
Vitaly Buka 8742943cb0 Relax stack check as on some platforms demanglers fail
Summary:
  On Windows (already fixed) and FreeBSD we have stacks traces without
  operator().

Reviewers: eugenis

Subscribers: llvm-commits

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

llvm-svn: 268332
2016-05-02 23:34:40 +00:00
Vitaly Buka 9102fc20f8 Add another failing use-after-scope test
Summary:
  Use after scope is not detected if array larger then 8 bytes.

Subscribers: kubabrecka

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

llvm-svn: 268330
2016-05-02 23:12:04 +00:00
Kuba Brecka a90528bb89 [sanitizer] Fix a crash in SizeClassAllocator32 with an out-of-range pointer
This happens on a 64-bit platform that uses SizeClassAllocator32 (e.g. ASan on AArch64). When querying a large invalid pointer, `__sanitizer_get_allocated_size(0xdeadbeefdeadbeef)`, an assertion will fail.  This patch changes PointerIsMine to return false if the pointer is outside of [kSpaceBeg, kSpaceBeg + kSpaceSize).

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

llvm-svn: 268243
2016-05-02 15:23:01 +00:00
Filipe Cabecinhas 30cba35a84 Finally fix invalid-pointer-pairs.cc. This time the demangle on the Windows buildbot.
llvm-svn: 268160
2016-04-30 08:34:40 +00:00
Filipe Cabecinhas 486c5d6ae9 Fix test's memory leaks.
llvm-svn: 268138
2016-04-29 23:42:34 +00:00
Filipe Cabecinhas dd754ef857 Try to fix clang-cmake-aarch64-42vma by removing a memory leak (have a global var capture it).
llvm-svn: 268114
2016-04-29 21:33:12 +00:00
Filipe Cabecinhas 04d61050ea [asan] Assert in __sanitizer_ptr_{sub,cmp} if one of the pointers was freed.
Summary:
This (partially) implements the check mentioned at
http://kristerw.blogspot.co.uk/2016/04/dangling-pointers-and-undefined-behavior.html
(via John Regehr)

Quoting:
"That the behavior is undefined follows from C11 6.2.4 "Storage
durations of objects"
  The lifetime of an object is the portion of program execution during
  which storage is guaranteed to be reserved for it. An object exists, has
  a constant address, and retains its last-stored value throughout its
  lifetime. If an object is referred to outside of its lifetime, the
  behavior is undefined. The value of a pointer becomes indeterminate when
  the object it points to (or just past) reaches the end of its lifetime.
and 7.22.3 "Memory management functions" that says that free ends the
lifetime of objects
  The lifetime of an allocated object extends from the allocation until
  the deallocation.
"

We can probably implement this for stack variables too, but I think this
is a good start to see if there's interest in this check.
We can also hide this behind a flag, too.

Reviewers: samsonov, kcc, rsmith, regehr

Subscribers: kubabrecka, llvm-commits

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

llvm-svn: 268097
2016-04-29 20:37:34 +00:00
Marcin Koscielnicki a0193ecfe1 [ASan] [SystemZ] Mark segv_read_write.c as UNSUPPORTED.
On s390*-linux, sigcontext just doesn't contain any information that could
be used to recover the type of access, so there's no way to fix this, short
of emulating the faulting instruction.

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

llvm-svn: 267960
2016-04-29 00:43:20 +00:00
Vedant Kumar 6a2ec9fc57 [test/asan] Update a test case to work with old Darwin SDK's
On Darwin, MAP_ANONYMOUS is a synonym for MAP_ANON. However, some SDK's
don't define MAP_ANONYMOUS. Use MAP_ANON to work around this.

(As a point of interest, the situation is exactly reversed on Linux.)

llvm-svn: 267907
2016-04-28 17:48:35 +00:00
Mike Aizatsky ccd318dc7e [sanitizers] read/write page fault detection on mac.
Summary: Resubmit of http://reviews.llvm.org/D19495 enabled only on intel.

Subscribers: kubabrecka

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

llvm-svn: 267750
2016-04-27 18:02:21 +00:00
Reid Kleckner a16ef7633b Un-XFAIL tests on Windows after fixing PR27492
Private symbols in PDBs do not have parameter types in their names so we
have to drop the parens from the lambda call operator.

llvm-svn: 267735
2016-04-27 16:38:03 +00:00
Mike Aizatsky a3060c1159 [sanitizers] rewriting test assuming assert() changes coverage.
Summary:
On windows platform assert() call creates two distinct CFG edges
which are coverage-instrumented. Simply calling assert would
change coverage numbers on the platform.

Subscribers: kubabrecka

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

llvm-svn: 267610
2016-04-26 21:56:14 +00:00
Marcin Koscielnicki 7ecdeb7ac3 [sanitizer] [SystemZ] Add ptrace support bits.
Differential Revision: http://reviews.llvm.org/D19134

llvm-svn: 267548
2016-04-26 10:41:30 +00:00
Mehdi Amini 9163f4997a Revert "[sanitizers] read/write page fault detection on mac."
This reverts commit r267477.
It broke our bots that enables the AArch64 backends, it seems that
this code is using a Darwin *X86 specific* field.

From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 267526
2016-04-26 07:03:11 +00:00
Mike Aizatsky f2bee298a0 [sanitizers] read/write page fault detection on mac.
Subscribers: kubabrecka

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

llvm-svn: 267477
2016-04-25 21:44:43 +00:00
Evgeniy Stepanov 988ebe9f34 [asan] Disable one test on windows.
Patch by Vitaly Buka.

llvm-svn: 267088
2016-04-22 00:34:10 +00:00
Evgeniy Stepanov 4c0f6afbab Enable stack-use-after-scope tests.
Fix and enable working stack-use-after-scope tests.
Add more failing tests for the feature, for fix later.

PR27453.

Patch by Vitaly Buka.

llvm-svn: 267084
2016-04-22 00:10:23 +00:00
Evgeniy Stepanov 0e97e036d3 [asan] Mark strdup test as unsupported on arm/linux.
llvm-svn: 267028
2016-04-21 18:18:09 +00:00
Evgeniy Stepanov 5d71bc5252 [asan] Add __strdup interceptor.
This happens on Linux when building as C (not C++) with optimization.

llvm-svn: 266931
2016-04-20 22:45:23 +00:00
Mandeep Singh Grang 04ccbd4053 [compiler-rt] Remove unwanted --check-prefix=CHECK from unit tests. NFC.
Summary:
Removed unwanted --check-prefix=CHECK from the following unit tests:
      test/asan/TestCases/Posix/start-deactivated.cc
      test/tsan/Darwin/ignored-interceptors.mm

 Patch by: Mandeep Singh Grang (mgrang)

Reviewers: samsonov, kcc, dvyukov, eugenis

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

llvm-svn: 266813
2016-04-19 20:29:59 +00:00
Kostya Serebryany d8ce87f850 Additional test for use-after-scope
Summary: Test that asan detects access to the dead variable captured by lambda.

Reviewers: aizatsky, kcc

Subscribers: llvm-commits

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

llvm-svn: 266676
2016-04-18 21:36:34 +00:00
Evgeniy Stepanov b70a2dd157 [asan] Prefer alloc-dealloc-mismatch to new-delete-type-mismatch.
With -fsized-deallocation, new[] vs delete mismatch is reported as
new-delete-type-mismatch. This is technically true, but
alloc-dealloc-mismatch describes it better.

llvm-svn: 266246
2016-04-13 21:04:27 +00:00
Mike Aizatsky 87b30a0ef2 [sancov] updaing android test after enabling cc edge pruning
llvm-svn: 265714
2016-04-07 20:21:21 +00:00
Mike Aizatsky 66505137eb [sancov] updaing android test
llvm-svn: 265692
2016-04-07 16:22:34 +00:00
Mike Aizatsky 5d4d715b99 [sancov] removing flaky test case (win)
llvm-svn: 265627
2016-04-07 00:23:02 +00:00
Mike Aizatsky 49a68258f5 [sancov] enabling coverage edge pruning by default.
Differential Revision: http://reviews.llvm.org/D18845

llvm-svn: 265614
2016-04-06 23:24:16 +00:00
Reid Kleckner 80fc4bc68a Apply suggestion from HJ Lu to avoid misaligned stack in test
Fixes PR27191

llvm-svn: 265322
2016-04-04 18:27:32 +00:00
Kuba Brecka 428a9f95a4 [asan,tsan] Make Darwin-specific tests more stable (use ignore_interceptors_accesses=1 for GCD tests and printf instead of NSLog).
llvm-svn: 265300
2016-04-04 14:54:05 +00:00
Ryan Govostes e0f41da049 [asan] Mark the initialization-bug.cc unsupported on OS X Yosemite and older
This test should fail on OS X Yosemite and older, and pass on OS X El Capitan
and newer as well as on other platforms.

llvm-svn: 264938
2016-03-30 22:21:58 +00:00
Ryan Govostes 89daa29fa6 [asan] Make the Darwin/dead-strip.c test require El Capitan or newer
llvm-svn: 264766
2016-03-29 18:54:29 +00:00
Ryan Govostes dc91fe5d8b [asan] Add runtime support for __asan_(un)register_image_globals
This change introduces routines that register and unregister all
instrumented globals in a loaded executable image.

These routines are only implemented on Darwin, where globals metadata
is expected to be placed in the __DATA,__asan_globals section.

Review: http://reviews.llvm.org/D16841
llvm-svn: 264644
2016-03-28 20:28:17 +00:00
Kostya Serebryany b48f8f09b1 [asan] bump the scariness score of read-after-frees (based on feedback from the Chrome security team)
llvm-svn: 264481
2016-03-26 00:00:19 +00:00
Reid Kleckner 2ea051e699 [asan] Relax strdup test check lines
On the buildbot, strdup appears as frame 1 instead of frame 0. Either is
an acceptable user experience.

llvm-svn: 264016
2016-03-22 01:04:33 +00:00
Reid Kleckner 23d0fde535 [asan] Intercept strdup on Windows
Some unit tests were failing because we didn't intercept strdup.  It
turns out it works just fine on 2013 and 2015 with a small patch to the
interception logic.

llvm-svn: 264013
2016-03-22 00:52:47 +00:00
Reid Kleckner c35d402aeb Fix coverage-related asan tests for VS 2015
printf is an inline function in VS 2015, giving these tests an
unexpected extra point of coverage. This change works around that by
avoiding printf.

llvm-svn: 264010
2016-03-22 00:11:51 +00:00
Reid Kleckner 60e53cdcb7 Fix order of arguments to fputs
This time actually tested on Linux, where the test is not XFAILed.

llvm-svn: 263294
2016-03-11 21:07:48 +00:00
Reid Kleckner 3b07caef66 Switch to fputs stderr to try to fix output buffering issues
llvm-svn: 263293
2016-03-11 20:54:14 +00:00
Reid Kleckner 7a2113882f Make printf-4 more robust to strlen interception after r263177
The CHECK line was matching stack-buffer-overflow from puts calling
strlen, which is not the bug the test is trying to catch.

llvm-svn: 263282
2016-03-11 19:11:15 +00:00
Alexey Samsonov 54411d5042 Fix ASan test cases after r263177
llvm-svn: 263195
2016-03-11 05:04:49 +00:00
Reid Kleckner ad04914a53 [Windows] Fix UnmapOrDie and MmapAlignedOrDie
Now ASan can return virtual memory to the underlying OS. Portable
sanitizer runtime code needs to be aware that UnmapOrDie cannot unmap
part of previous mapping.

In particular, this required changing how we implement MmapAlignedOrDie
on Windows, which is what Allocator32 uses.

The new code first attempts to allocate memory of the given size, and if
it is appropriately aligned, returns early. If not, it frees the memory
and attempts to reserve size + alignment bytes. In this region there
must be an aligned address. We then free the oversized mapping and
request a new mapping at the aligned address immediately after. However,
a thread could allocate that virtual address in between our free and
allocation, so we have to retry if that allocation fails. The existing
thread creation stress test managed to trigger this condition, so the
code isn't totally untested.

Reviewers: samsonov

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

llvm-svn: 263160
2016-03-10 20:47:26 +00:00
Filipe Cabecinhas 721447c873 [test/asan/closed-fds] Properly quote log_path for shell invocation.
llvm-svn: 263106
2016-03-10 11:51:59 +00:00
Alexey Samsonov c8f2c957e0 [asan] Fix odr_c_test failure with gold linker
Summary:
Adds another global to asan's odr_c_test to help force the target global to
not lie at the start of bss with the gold linker where it is always
aligned.

Patch by Derek Bruening!

llvm-svn: 262678
2016-03-04 00:41:39 +00:00
Evgeniy Stepanov aafe4b63d9 [asan] Fix new[]/delete mismatch in tests.
This code is actually never executed because all RUN lines trigger an
earlier heap-use-after-free, but there is still a compiler warning.

llvm-svn: 262276
2016-03-01 00:38:39 +00:00
Maxim Ostapenko d0257b7bf1 [asan] Fix UB in test/asan/TestCases/Linux/recvfrom.cc testcase.
llvm-svn: 262210
2016-02-29 08:56:26 +00:00
Maxim Ostapenko 8d8f919cf5 [asan] Re-enable test/asan/TestCases/Linux/recvfrom.cc testcase.
This testcase failed on sanitizer-x86_64-linux buildbot in large parallel build due to race on
port 1234 between AddressSanitizer-i386-linux and AddressSanitizer-x86_64-linux instances of recvfrom.cc.
This patch tries to resolve the issue by relying on kernel to choose available port instead of hardcoding
its number in testcase.

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

llvm-svn: 262204
2016-02-29 07:47:35 +00:00
Maxim Ostapenko 50ca4464c4 [sanitizer] Fix third parameter in COMMON_INTERCEPTOR_WRITE_RANGE in recv and recvfrom interceptors.
Pass res instead of len as third parameter to COMMON_INTERCEPTOR_WRITE_RANGE,
because otherwise we can write to unrelated memory (in MSan) or get wrong report (in ASan).

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

llvm-svn: 261898
2016-02-25 17:07:38 +00:00
Maxim Ostapenko 640d1fc46c [asan] Disable recvfrom test failing on the bots.
llvm-svn: 261870
2016-02-25 14:58:07 +00:00
Maxim Ostapenko 1f4cea0467 [asan] Disable recvfrom testcase on Android due to buildbot failure.
Trying to fix following error on Android:

FAIL: AddressSanitizer-arm-android :: TestCases/Linux/recvfrom.cc (47 of 350)
...
Command Output (stderr):
--
/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/projects/compiler-rt/test/asan/TestCases/Linux/recvfrom.cc:22:22: error: variable has incomplete type 'struct sockaddr_in'
  struct sockaddr_in serveraddr; // server's addr
                     ^
/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/projects/compiler-rt/test/asan/TestCases/Linux/recvfrom.cc:22:10: note: forward declaration of 'sockaddr_in'
  struct sockaddr_in serveraddr; // server's addr
         ^
/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/projects/compiler-rt/test/asan/TestCases/Linux/recvfrom.cc:29:38: error: use of undeclared identifier 'INADDR_ANY'
  serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);
                                     ^
/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/projects/compiler-rt/test/asan/TestCases/Linux/recvfrom.cc:30:25: error: use of undeclared identifier 'htons'
  serveraddr.sin_port = htons(kPortNum);
                        ^
/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/projects/compiler-rt/test/asan/TestCases/Linux/recvfrom.cc:45:22: error: variable has incomplete type 'struct sockaddr_in'
  struct sockaddr_in serveraddr; // server's addr
                     ^
/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/projects/compiler-rt/test/asan/TestCases/Linux/recvfrom.cc:45:10: note: forward declaration of 'sockaddr_in'
  struct sockaddr_in serveraddr; // server's addr
         ^
/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/projects/compiler-rt/test/asan/TestCases/Linux/recvfrom.cc:69:25: error: use of undeclared identifier 'htons'
  serveraddr.sin_port = htons(kPortNum);

llvm-svn: 261855
2016-02-25 10:55:52 +00:00
Maxim Ostapenko 7389936f57 [sanitizer] Move recvmsg and recv interceptors to sanitizer_common.
This patch moves recv and recvfrom interceptors from MSan and TSan to
sanitizer_common to enable them in ASan.

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

llvm-svn: 261841
2016-02-25 08:44:25 +00:00
Alexey Samsonov 4d35491a12 [tests] Run test that uses gnu asm syntax on Posix only.
llvm-svn: 261609
2016-02-23 04:10:53 +00:00
Alexey Samsonov 4e796d0c9f [tests] Remove "supported-target" in favor of "target-arch" lit features.
Test cases definitely should not care about the complete set of architectures
supported by compiler-rt - they should only care about current
architecture that the test suite was configured for.

Introduce new lit feature to reflect this, and convert tests to use it.

llvm-svn: 261603
2016-02-23 01:58:56 +00:00
Mike Aizatsky 361a7bb338 [sancov] requiring dynamic asan.
llvm-svn: 261362
2016-02-19 20:47:25 +00:00
Mike Aizatsky 731942565b [sancov] using static asan
We are not able to recover coverage points from dynamically linked
binaries at this point without symbols in @plt tables.

llvm-svn: 261352
2016-02-19 18:46:30 +00:00
Reid Kleckner 12813b0def [Windows] Simplify more tests now that Clang supports EH
Remove TestCases/Windows/throw_catch.cc, since it is redundant with the
portable test TestCases/throw_catch.cc.

llvm-svn: 261342
2016-02-19 17:36:54 +00:00
Reid Kleckner 00203bc60b [Windows] Add 10s timeout to some WaitForSingleObject calls
I ran the test suite yesterday and when I came back this morning the
queue_user_work_item.cc test was hung. This could be why the
sanitizer-windows buildbot keeps randomly timing out. I updated all the
usages of WaitForSingleObject involving threading events. I'm assuming
the API can reliably wait for subprocesses, which is what the majority
of call sites use it for.

While I'm at it, we can simplify some EH tests now that clang can
compile C++ EH.

llvm-svn: 261338
2016-02-19 17:30:38 +00:00
Reid Kleckner 973dacf691 Un-XFAIL the last C++ EH test, it was fixed by r261258
llvm-svn: 261263
2016-02-18 21:24:30 +00:00
Reid Kleckner 7c8e2c37ba Clang on Windows supports exceptions, un XFAIL the passing tests
llvm-svn: 261236
2016-02-18 18:33:58 +00:00
Kostya Serebryany d4590c7304 [sanitizer-coverage] implement -fsanitize-coverage=trace-pc. This is similar to trace-bb, but has a different API. We already use the equivalent flag in GCC for Linux kernel fuzzing. We may be able to use this flag with AFL too
llvm-svn: 261159
2016-02-17 21:34:43 +00:00
Alexey Samsonov 2af1e3e963 PR26606: Make abort_on_error.cc test more portable.
llvm-svn: 261157
2016-02-17 21:25:12 +00:00
Jonas Hahnfeld ccb0e464be [compiler-rt] Fix test failures when switching default C++ library
1. Add two explicit -stdlib=libstdc++ in conjunction with -static-libstdc++
2. Pass -nostdinc++ when adding include paths for libc++ built for tsan. This
   prevents clang finding the headers twice which would confuse #include_next

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

llvm-svn: 260883
2016-02-15 11:28:15 +00:00
Alexey Samsonov eb649bcfb9 [LSan] Print more helpful error message if LSan crashes during leak detection.
llvm-svn: 260717
2016-02-12 20:20:51 +00:00
Mike Aizatsky 92cbbfcd89 [sancov] improved object files handling.
Updating sancov invocation on html_cov_dump.

sancov change: http://reviews.llvm.org/D17169

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

llvm-svn: 260629
2016-02-12 00:29:24 +00:00
Alexey Samsonov d077c29c80 [ASan] Disable test that uses profile runtime on Windows.
llvm-svn: 260561
2016-02-11 18:26:57 +00:00
Reid Kleckner ceda883e4d [Windows] Fill in read/write information in SignalContext
Implements https://github.com/google/sanitizers/issues/653

llvm-svn: 260539
2016-02-11 16:44:35 +00:00
Reid Kleckner 031bbd062b Un-XFAIL a passing test on Windows
llvm-svn: 260481
2016-02-11 02:02:56 +00:00
Reid Kleckner ddcf07d51c Move mmap_limit_mp test to Posix
This test isn't posix specific, but it doesn't pass on Windows and is
XFAILed. I suspect that this test, which is expected to fail, is causing
the hangs I'm seeing on our WinASan builder.  Moving it to Posix seems
to be the cleanest way to avoid running it on Windows.

llvm-svn: 260480
2016-02-11 02:02:52 +00:00
Kostya Serebryany 8c4b9ff921 [asan] update the scariness score: tweak a few weights and add tests
llvm-svn: 260327
2016-02-09 23:46:43 +00:00
Evgeniy Stepanov 52f6c262d9 [asan] Implement SEGV read vs write detection for ARM and AArch64.
llvm-svn: 260163
2016-02-08 22:50:25 +00:00
Kostya Serebryany e4ddfd14f1 [asan] re-commit r259961, this time making the test Linux-Only
llvm-svn: 260128
2016-02-08 19:21:08 +00:00
Maxim Ostapenko 3dd0ec12d7 [asan] XFAIL local_alias.cc testcase on android in order to fix sanitizer-x86_64-linux buildbot.
llvm-svn: 260090
2016-02-08 12:58:05 +00:00
Maxim Ostapenko 08a70542b1 [asan] XFAIL local alias related tests on Mips due to https://llvm.org/bugs/show_bug.cgi?id=26525.
llvm-svn: 260079
2016-02-08 09:50:57 +00:00
Maxim Ostapenko 9ab99ab985 [asan] Introduce new approach for ODR violation detection based on odr indicator symbols.
This is a compiler-rt part of this http://reviews.llvm.org/D15642 patch. Here,
we add a new approach for ODR violation detection.
Instead of using __asan_region_is_poisoned(g->beg, g->size_with_redzone) on
global address (that would return false now due to using private alias), we can
use new globally visible indicator symbol to perform the check.

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

llvm-svn: 260076
2016-02-08 08:39:59 +00:00
Nico Weber d64186f5da Revert r259961, r259978, r259981.
The "sanitizer-windows" buildbot has been failing for two days because of this:

FAILED: cl.exe asan_report.cc
asan_scariness_score.h(60) : error C2536:
  '__asan::ScarinessScore::__asan::ScarinessScore::descr' :
      cannot specify explicit initializer for arrays
asan_scariness_score.h(60) : see declaration of '__asan::ScarinessScore::descr'

llvm-svn: 260059
2016-02-07 21:41:37 +00:00
Kostya Serebryany bafa729e26 [asan] trying to fix the non-x86 bots
llvm-svn: 259981
2016-02-06 04:50:30 +00:00
Kostya Serebryany c02ed2a8e2 [asan] properly report an un-aligned global variable instead of just crashing
llvm-svn: 259979
2016-02-06 03:22:24 +00:00
Kostya Serebryany cfc83bc707 [asan] disabled one subtest in scariness_score_test.cc that may fail when running under GNU make. Add more subtests
llvm-svn: 259978
2016-02-06 02:37:39 +00:00
Kostya Serebryany 23a6822976 [asan] add an experimental feature that prints the scariness score of the error message. To enable it use ASAN_OPTIONS=print_scariness=1
llvm-svn: 259961
2016-02-06 00:29:44 +00:00
Kostya Serebryany 0e05d6eb9c [asan] fix the non-x86 build
llvm-svn: 259745
2016-02-04 02:33:48 +00:00
Kostya Serebryany 2b9be25066 [asan] When catching a signal caused by a memory access, print if it's a READ or a WRITE. This touches win/mac files which I have not tested, if a win/mac bot fails I'll try to quick-fix
llvm-svn: 259741
2016-02-04 02:02:09 +00:00
Maxim Ostapenko 4a3c7fa441 [asan] Fix internal CHECK failure on double free in recovery mode.
This patches fixes https://github.com/google/sanitizers/issues/639

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

llvm-svn: 259473
2016-02-02 07:32:24 +00:00
Anna Zaks 2c5c33dc38 [asan] Fixup r258849 by updating warning in the test
The error message has been changed in code as of r258849 (http://reviews.llvm.org/D16546). Update the test as well.

llvm-svn: 259452
2016-02-02 02:01:21 +00:00
Mike Aizatsky 343322bb93 putting requires on one line - ppc still executes my tests.
llvm-svn: 259012
2016-01-28 02:24:35 +00:00
Mike Aizatsky b4c48d1e15 [sancov] run sancov test on x86_64 linux only
llvm-svn: 259006
2016-01-28 00:35:17 +00:00
Mike Aizatsky ecaeb1d93b [sancov] running sancov test on linux only
llvm-svn: 259004
2016-01-28 00:27:13 +00:00
Mike Aizatsky 2654299d6a [sanitizers] generating html report on coverage dump
Subscribers: tberghammer, danalbert, srhines

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

llvm-svn: 258999
2016-01-27 23:51:36 +00:00