594 Commits

Author SHA1 Message Date
Marcos Pividori
2ee8a5f7b7 [libFuzzer] Use long long to ensure 64 bits.
We should always use unsigned long long to ensure 64 bits. On Windows, unsigned
long is 4 bytes. This was the reason why value-profile-cmp4.test was failing on
Windows.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294390 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:03:31 +00:00
Marcos Pividori
7a5e009266 [libFuzzer] Use custom target instead of list of binaries for tests.
Update cmake to use a custom target TestBinaries instead of a list of targets.
This simplifies cmake, and fix some errors. This way, we don't have to propagate
the values into parents directories. We only need to use add_dependencies.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294389 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:03:26 +00:00
Marcos Pividori
f80dc2a04d [libFuzzer] Properly use Handle instead of FD on Windows.
For Windows, sanitizers work with Handles, not with posix file descriptors,
because they use the windows-specific API. So we need to convert the fds to
handles before passing them to the sanitizer library.
After this change, close_fd_mask is fixed for Windows (this fix some tests too).

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294388 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:03:18 +00:00
Marcos Pividori
255eed0380 [libFuzzer] Change Uninstrumented test name.
On Windows, executables with the word "uninst" included in their names are
associated with administrator privileges.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294387 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:03:13 +00:00
Marcos Pividori
ec59eb9d58 [libFuzzer] fuzzer-jobs requires posix.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294386 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:03:07 +00:00
Marcos Pividori
1ff471105f [libFuzzer] Update fuzzer.test to properly set environment variables.
Use env to set environment variables, so it works on Windows and Linux.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294385 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:03:03 +00:00
Marcos Pividori
155c4aab57 [libFuzzer] Don't add newline character when using echo in tests.
Add the option "-n", so we don't add a new line character at the end of the file
when using echo. (on Windows this means 2 characters).

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294384 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:02:59 +00:00
Marcos Pividori
fbc422e6ba [libFuzzer] Disable ulimit test on windows.
Differential Revision: https://reviews.llvm.org/D29535

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294383 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:02:54 +00:00
Marcos Pividori
44933aa735 [libFuzzer] Remove ? wildcard on tests.
We can not use the wildcard ? on Windows.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294382 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:02:50 +00:00
Marcos Pividori
6cf9872a5e [libFuzzer] Update fuzzer-segv to set environment variables.
Use env to set environment variables, so it works on Linux and Windows.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294381 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:02:45 +00:00
Marcos Pividori
75241a8855 [libFuzzer] Properly configure tests for Windows.
This configuration is necessary, and is included in all tests suites.
We need to execute: `config.test_format = lit.formats.ShTest(False)`
Otherwise, lit will try to use bash, which generates many problems.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294380 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:02:41 +00:00
Marcos Pividori
ddc6c083cf [libFuzzer] Simplify dump_coverage test.
Environment variables are handled differently on Windows. In this case it is not
necessary to use environment variables. So, I simplify the test to work on
Windows.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294379 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:02:36 +00:00
Marcos Pividori
a8f8ed08cc [libFuzzer] Update Load test to work on 32 bits.
We should ensure the size of the variable `a` is 8 bytes. Otherwise, this
generates a stack buffer overflow inside the memcpy call in 32 bits machines.
(We write more bytes than the size of a, when it is 4 bytes)

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294378 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:02:32 +00:00
Marcos Pividori
f78e1b3b9d [libFuzzer] Update test to consider different exceptions.
Differential Revision: https://reviews.llvm.org/D29531

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294377 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:02:25 +00:00
Marcos Pividori
8c0ca40461 [libFuzzer] Temporarily fix Shmem for Windows.
In this diff, I add stubs for shared memory on Windows. Now we can compile and
use libFuzzer without support for shared memory.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294376 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:02:12 +00:00
Kostya Serebryany
ffcfd0c3bc [libFuzzer] replace std::random_shuffle with std::shuffle as std::random_shuffle is being deprecated in C++17. Also simplify fuzzer::Random. NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294366 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-07 22:37:34 +00:00
Kostya Serebryany
522017cf0d [libFuzzer] make code less clever to avoid fallthrough in switch (and in turn avoid compiler warnings). NFC. Suggested by Christian Holler.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294239 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-06 21:21:37 +00:00
Kostya Serebryany
66d69563f7 [libFuzzer] properly hide the memcmp interceptor from msan
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294061 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-03 22:51:38 +00:00
Mike Aizatsky
0022fc7373 [libfuzzer] chromium-related compilation fixes
Reviewers: kcc

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294035 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-03 20:26:44 +00:00
Kostya Serebryany
5459106ddf [libFuzzer] reorganize the tracing code to make it easier to experiment with inlined coverage instrumentation. NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293928 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-02 19:56:01 +00:00
Marcos Pividori
ebf6feac60 [libFuzzer] Properly handle exceptions with UnhandledExceptionFilter.
Use SetUnhandledExceptionFilter instead of AddVectoredExceptionHandler.

According to the documentation on Structured Exception Handling, this is the
order for the Exception Dispatching:
+ If the process is being debugged, the system notifies the debugger.
+ The Vectored Exception Handler is called.
+ The system attempts to locate a frame-based exception handler by searching the
 stack frames of the thread in which the exception occurred.
+ If no frame-based handler can be found, the UnhandledExceptionFilter filter is
 called.
+ Default handling based on the exception type.

So, similar to what we do for asan, we should use SetUnhandledExceptionFilter
instead of AddVectoredExceptionHandler, so user's code that is being fuzzed can
execute frame-based exception handlers before we catch them . We want to catch
unhandled exceptions, not all the exceptions.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293920 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-02 19:07:53 +00:00
Marcos Pividori
f7fdc84b39 [libFuzzer] Disable afl tests on non-posix systems.
AflDriver is not supported on non posix systems.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293830 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 22:40:50 +00:00
Marcos Pividori
b2df6a0c9b [libFuzzer] Disable equivalence tests on non posix systems.
We can not run this test until we implement shared memory on Windows.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293829 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 22:40:45 +00:00
Marcos Pividori
98399aa4b2 [libFuzzer] Isolate merge tests that require posix.
Differential Revision: https://reviews.llvm.org/D29420

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293828 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 22:40:40 +00:00
Marcos Pividori
b928b9b13e [libFuzzer] Add features windows and posix for lit tests.
Add 2 features: posix and windows.
Sometimes we want some specific tests only for posix and we use:
 REQUIRES: posix
Sometimes we want some specific tests only for windows and we use:
 REQUIRES: windows

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293827 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 22:40:34 +00:00
Marcos Pividori
adb057cab2 [libFuzzer] Accept different extensions.
Differential Revision: https://reviews.llvm.org/D29417

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293826 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 22:40:29 +00:00
Marcos Pividori
1d98b650ef [libFuzzer] Fix test because cmd prompt does not expand wildcard.
Commands should expand the wildcards on Windows, the cmd prompt doesn't.
Because of that sancov was not finding the needed file.
To deal with this, we use ls and xargs from gnu win utils.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293825 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 22:39:55 +00:00
Marcos Pividori
12cb357da1 [libFuzzer] Do not use llvm-objdump for disassembling a DSO.
When disassembling a DSO, for calls to functions from the PLT, llvm-objdump only
prints the offset from the PLT, like: <.plt+0x30>.

While objdump and dumpbin print the function name, like:
<__sanitizer_cov_trace_pc_guard@plt>

When analyzing the coverage in libFuzzer we dissasemble and look for the calls
to __sanitizer_cov_trace_pc_guard.

So, this fails when using llvm-objdump on a DSO.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293791 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 17:59:23 +00:00
Marcos Pividori
90e4124e52 [libFuzzer] Properly check if we can use dumpbin.
The flag "/sumary" is necessary, otherwise it returns a non-zero value.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293790 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 17:59:19 +00:00
Kostya Serebryany
63c362484c [libFuzzer] increase the default size for shmem
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293722 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 00:07:47 +00:00
Marcos Pividori
2c531bbcf6 [libFuzzer] Implement TmpDir() for Windows.
Differential Revision: https://reviews.llvm.org/D28977

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293516 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-30 18:14:53 +00:00
Kostya Serebryany
dec0b05633 [libfuzzer] include errno.h. On Ubuntu 14.04 we got away w/o it, but other systems seem to require it
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293389 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-28 18:56:05 +00:00
Kostya Serebryany
001f56735f [libFuzzer] make shmem more robust in the presence of signals
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293339 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-27 22:41:30 +00:00
Kostya Serebryany
49c910dae1 [libFuzzer] simplify the value profiling callback further: don't use (idx MOD prime) on the hot path where it is useless anyway
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293239 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-27 00:39:12 +00:00
Kostya Serebryany
eff755f3da [libFuzzer] make sure (again) that __builtin_popcountl is compiled into popcnt
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293237 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-27 00:20:55 +00:00
Kostya Serebryany
bcc64b878f [libFuzzer] simplify the value profile code and disable asan/msan on it
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293236 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-27 00:09:59 +00:00
Kostya Serebryany
6c2c7c89da [libFuzzer] remove a bit of stale code
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293129 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-26 01:45:54 +00:00
Kostya Serebryany
c43e0682f2 [libFuzzer] further simplify __sanitizer_cov_trace_pc_guard
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293128 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-26 01:34:58 +00:00
Kostya Serebryany
df040aa50b [libFuzzer] simplify the code for __sanitizer_cov_trace_pc_guard and make sure it is not asan/msan-instrumented
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293125 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-26 01:04:54 +00:00
Kostya Serebryany
13aa2bfeaf [libFuzzer] don't call GetPreviousInstructionPc on the hot path -- only when dumping the PCs
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293117 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-26 00:22:08 +00:00
Kostya Serebryany
72e0240a06 [libFuzzer] mutate empty input using the regular mutators (instead of a custom dummy one). This way when we mutate an empty input there is a chance we will get a dictionary word
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292843 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-23 22:52:13 +00:00
Kostya Serebryany
fc4ec25a17 [libFuzzer] make sure we use the feedback from std::string operator ==
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292835 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-23 22:11:04 +00:00
Kostya Serebryany
f7ac01d0a0 [libFuzzer] deflake a test
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292813 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-23 18:44:40 +00:00
Marcos Pividori
6ea436d7ac [libFuzzer] Add missing dependency for tests.
Dependency on TestBinaries was erroneously removed on r292735.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292765 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-22 21:55:46 +00:00
Marcos Pividori
7728ff0f87 [libFuzzer] Specify the CRT considered (MT or MD) for tests on Windows.
Differential Revision: https://reviews.llvm.org/D28439

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292749 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-22 02:28:12 +00:00
Marcos Pividori
2858ad7ec2 [libFuzzer] Fix test with shared libraries on Windows.
We need to set BINARY_DIR to: ${CMAKE_BINARY_DIR}/lib/Fuzzer/test , so the dll
is placed in the same directory than the test LLVMFuzzer-DSOTest, and is found
when executing that test.
As we are using CMAKE_CXX_CREATE_SHARED_LIBRARY to link the dll, we can't modify
the output directory for the import library. It will be created in the same
directory than the dll (in BINARY_DIR), no matter which value we set to
LIBRARY_DIR. So, if we set LIBRARY_DIR to a different directory than BINARY_DIR,
when linking LLVMFuzzer-DSOTest, cmake will look for the import library
LLVMFuzzer-DSO1.lib in LIBRARY_DIR, and won't find it, since it was created in
BINARY_DIR. So, for Windows, we need that LIBRARY_DIR and BINARY_DIR are the
same directory.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292748 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-22 02:28:08 +00:00
Marcos Pividori
61d2c04941 [libFuzzer] AlrmHandler is executed in a different thread for Windows.
Don't check for InFuzzingThread() on Windows, since the AlarmHandler() is
always executed by a different thread from a thread pool.
If we don't add these changes, the alarm handler will never execute.
Note that we decided to ignore possible problem in the synchronization.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292746 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-22 01:58:59 +00:00
Marcos Pividori
9c2ee32cbf [libFuzzer] Leak Sanitizer is not supported for Windows.
Differential Revision: https://reviews.llvm.org/D28709

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292745 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-22 01:58:55 +00:00
Marcos Pividori
44ad5c2d2c [libFuzzer] Fix OutOfMemory tests to work on 32 bits.
I add 2 changes to make the tests work on 32 bits and on 64 bits.
I change the size allocated to 0x20000000 and add the flag: -rss_limit_mb=300.
Otherwise the output for 32 bits and 64 bits is different.
For 64 bits the value 0xff000000 doesn't exceed kMaxAllowedMallocSize.
For 32 bits, kMaxAllowedMallocSize is set to 0xc0000000, so the call to
Allocate() will fail earlier printing "WARNING: AddressSanitizer failed to
allocate ..." , and wont't call malloc hooks.
So, we need to consider a size smaller than 2GB (so malloc doesn't fail on
32bits) and greater that the value provided by -rss_limit_mb.
Because of that I use: 0x20000000.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292744 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-22 01:58:50 +00:00
Marcos Pividori
ed3dca071a [libFuzzer] Avoid undefined behavior, properly discard output to stdout/stderr.
Fix libFuzzer when setting -close_fd_mask to a non-zero value.
In previous implementation, libFuzzer closes the file descriptors for
stdout/stderr. This has some disavantages:

For `fuzzer-fdmask.test`, we write directly to stdout and stderr using the
file streams stdout and stderr, after the file descriptors are closed, which is
undefined behavior. In Windows, in particular, this was making the test fail.

Also, if we close stdout and we open a new file in libFuzzer, we get the file
descriptor 1, which could generate problem if some code assumes file descriptors
refers to stdout and works directly writing to the file descriptor 1, but it
will be writing to the opened file (for example using std::cout).

Instead of closing the file descriptors, I redirect the output to /dev/null on
linux and nul on Windows.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292743 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-22 01:58:45 +00:00