Commit Graph

324 Commits

Author SHA1 Message Date
Kostya Serebryany
137c3957ed [libFuzzer] add InsertRepeatedBytes and EraseBytes.
New mutation: InsertRepeatedBytes.
Updated mutation: EraseByte => EraseBytes.

This helps https://github.com/google/sanitizers/issues/710
where libFuzzer was not able to find a known bug.
Now it finds it in minutes.

Hopefully, the change is general enough to help other targets.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278687 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-15 17:48:28 +00:00
Dan Liew
a3e4fd51f1 [LibFuzzer] Fix -jobs=<N> where <N> > 1 and the number of workers is > 1 on macOS.
The original `ExecuteCommand()` called `system()` from the C library.
The C library implementation of this on macOS contains a mutex which
serializes calls to `system()`. This prevented the `-jobs=` flag
from running copies of the fuzzing binary in parallel which is
the opposite of what is intended.

To fix this on macOS an alternative implementation of `ExecuteCommand()`
is provided that can be used concurrently. This is provided in
`FuzzerUtilDarwin.cpp` which is guarded to only compile code on Apple
platforms. The existing implementation has been moved to a new file
`FuzzerUtilLinux.cpp` which is guarded to only compile code on Linux.

This commit includes a simple test to check that LibFuzzer is being
executed in parallel when requested.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278544 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-12 18:29:36 +00:00
Kostya Serebryany
3aa06bae18 [libFuzzer] make libFuzzer work with a bit older clang versions
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277941 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-06 21:28:56 +00:00
Kostya Serebryany
1efe1f7b69 [libFuzzer] don't print bogus error message
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277940 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-06 21:23:29 +00:00
Mike Aizatsky
7e8350b8b7 [libfuzzer] do not warn about missing pcbuffer functions: they are new.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277927 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-06 17:03:22 +00:00
Mike Aizatsky
4613003000 [sanitizers] trace buffer API to use user-allocated buffer.
Differential Revision: https://reviews.llvm.org/D23185

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277859 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-05 20:09:53 +00:00
Kostya Serebryany
1f0a7ed0f3 [libFuzzer] extend the messages printed by afl_driver
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276052 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-19 23:18:28 +00:00
Kostya Serebryany
3487192114 [libFuzzer] properly intercept memmem
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276006 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-19 18:29:06 +00:00
Kostya Serebryany
730992dc3b [libFuzzer] add hooks for strstr, strcasestr, strcasecmp, strncasecmp
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275648 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-15 23:27:19 +00:00
Kostya Serebryany
3d1f237171 [libFuzzer] add ThreadedLeakTest
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275582 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-15 17:19:43 +00:00
Dan Liew
1a68871c47 [LibFuzzer] Unbreak the build on macOS which was broken by r272858.
``afl_driver.cpp`` currently relies on weak symbols which doesn't
work properly under macOS. For now fix the build by providing a
dummy implementation of ``LLVMFuzzerInitialize(...)``. This is just
a temporary measure until we fix ``afl_driver.cpp`` for macOS.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274778 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-07 18:14:11 +00:00
Mike Aizatsky
f6653a309e [libFuzzer] Let user specify extra stats file.
Summary: If AFL_DRIVER_EXTRA_STATS_FILENAME is set and valid, write to it peak_rss_mb and slowest_unit_time_sec. These are both stats that libFuzzer can print but afl cannot.

Reviewers: kcc, aizatsky, metzman

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274273 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-30 20:43:06 +00:00
Mike Aizatsky
8bbe924637 [libfuzzer] moving is_ascii handler inside mutation dispatcher.
Summary: It also fixes a bug, when first random might not be ascii.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273611 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-23 20:44:48 +00:00
Vitaly Buka
07997a91ef [libFuzzer] Add standard license info and comment header to AFLDriverTest.cpp
Summary: Add license info and brief description of file to AFLDriverTest.cpp.

Reviewers: kcc, aizatsky

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273527 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-23 02:19:36 +00:00
Kostya Serebryany
ee71b6abb0 [libFuzzer] make the single-run output more reliable
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272998 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-17 13:07:06 +00:00
Kostya Serebryany
c0e47a82c1 [libFuzzer] use the new chainable malloc hooks instead of the old un-chainable ones, use atomic for malloc/free counters instead of a thread local counter in the main thread. This should make on-the-spot leak detection in libFuzzer more reliable
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272948 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-16 20:17:41 +00:00
Vitaly Buka
3cf4eef2a1 Fix test from D21194
Bot sets ASAN_OPTIONS=handle_abort=1 which prevents expected crash.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272866 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-16 01:52:48 +00:00
Vitaly Buka
eb7016ef82 Debugging D21194 issues on bot
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272863 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-16 01:26:46 +00:00
Vitaly Buka
35825a3ed7 Enable libFuzzer's afl_driver to append stderr to a file.
Summary:
[libFuzzer] Enable afl_driver to append stderr to a user specified file.

Append stderr of afl_driver to the file specified by the environmental variable
AFL_DRIVER_STDERR_DUPLICATE_FILENAME if it is set. This lets users see outputs
on crashes without rerunning crashing test cases (which won't work for crashes
that are difficult to reproduce). Before this patch, stderr would only be sent to afl-fuzz
and users would have no way of seeing it.

Reviewers: llvm-commits, aizatsky, kcc, vitalybuka

Subscribers: vitalybuka

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272858 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-16 00:14:42 +00:00
Dan Liew
7029af9787 [LibFuzzer] Fix `FuzzerMutate.ShuffleBytes2` unit test on OSX.
The ``FuzzerMutate.ShuffleBytes2`` unit test was failing on
OSX due to the implementation of ``std::random_shuffle()``
being different between libcxx and libstdc++.

@kcc has decided (see http://reviews.llvm.org/D21218) it is acceptable
for there to be different mutation behavior on different platforms so
this commit just adjusts the test to perform the minimum number of
iterations (that is a power of 2) to see all the mutations the unit test
is looking for.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272743 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-15 01:40:02 +00:00
Vitaly Buka
93cdb4b527 Revert "Enable libFuzzer's afl_driver to append stderr to a file."
Crashes with AddressSanitizer: SEGV on unknown address
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fuzzer/builds/9924/steps/annotate/logs/stdio

This reverts commit r272706.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272726 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-14 22:09:00 +00:00
Vitaly Buka
6ff3418b63 Enable libFuzzer's afl_driver to append stderr to a file.
Summary:
[libFuzzer] Enable afl_driver to append stderr to a user specified file.

Append stderr of afl_driver to the file specified by the environmental variable
AFL_DRIVER_STDERR_DUPLICATE_FILENAME if it is set. This lets users see outputs
on crashes without rerunning crashing test cases (which won't work for crashes
that are difficult to reproduce). Before this patch, stderr would only be sent to afl-fuzz
and users would have no way of seeing it.

Reviewers: llvm-commits, aizatsky, kcc, vitalybuka

Subscribers: vitalybuka

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272706 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-14 20:42:05 +00:00
Dan Liew
eac51a2bde [LibFuzzer] Disable the `fuzzer-trace-pc.test` test on non-linux platforms.
On OSX this test sometimes fails due to the
``LLVMFuzzer-FullCoverageSetTest-TracePC`` program going over the
default 2GiB memory limit. This shouldn't be happening and needs
investigating. For now just disable the test so we can set up an
OSX buildbot.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272696 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-14 19:15:13 +00:00
Dan Liew
a29300175d [LibFuzzer] Move tests in `fuzzer-traces.test` that require hooks to their own test.
The tests in ``fuzzer-traces-hooks.test`` only work on Linux because calls to hooks
(e.g. ``__sanitizer_weak_hook_memcmp()``) from inside the sanitizer
runtime are only implemented on Linux. Therefore these tests are set to
only run on Linux.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272600 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-14 00:11:34 +00:00
Dan Liew
bb05836e33 [LibFuzzer] Fix some unit test crashes on OSX.
This fixes the following unit tests:

FuzzerDictionary.ParseOneDictionaryEntry
FuzzerDictionary.ParseDictionaryFile

The issue appears to be mixing non-ASan-ified code (LibFuzzer) and
ASan-ified code (the unittest) as the tests would pass fine if
everything was built with ASan enabled.

I believe the issue is that different implementations of std::vector<>
are being used in LibFuzzer and outside LibFuzzer (in the unittests).
For Libcxx (I've not seen the issue manifest for libstdc++) we can disable
the ASanified std::vector<> by definining the ``_LIBCPP_HAS_NO_ASAN`` macro.
Doing this fixes the tests on OSX.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272374 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-10 05:33:07 +00:00
Kostya Serebryany
41a5827cd3 [libFuzzer] add one more OOM test, which we currently don't handle very well
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272240 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-09 01:20:35 +00:00
Kostya Serebryany
819b4d1da2 [libFuzzer] add 'weak' back to __sanitizer_malloc_hook and __sanitizer_free_hook
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272116 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-08 04:49:29 +00:00
Kostya Serebryany
fd9cb1a5c5 [libFuzzer] add a test that is built w/o coverage instrumentation but has the coverage rt (it should now fail with a descriptive message)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272090 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-08 01:46:13 +00:00
Dan Liew
1a1c8bea2d [LibFuzzer] Declare and use sanitizer functions in `fuzzer::ExternalFunctions`
This fixes linking problems on OSX.

Unfortunately it turns out we need to use an instance of the
``fuzzer::ExternalFunctions`` object in several places so this
commit also replaces all instances with a single global instance.

It also turns out initializing a global ``fuzzer::ExternalFunctions``
before main is entered (i.e. letting the object be initialised by the
global initializers) is not safe (on OSX the call to ``Printf()`` in the
CTOR crashes if it is called from a global initializer) so we instead
have a global ``fuzzer::ExternalFunctions*`` and initialize it inside
``FuzzerDriver()``.

Multiple unit tests depend also depend on the
``fuzzer::ExternalFunctions*`` global so a ``main()`` function has been
added that initializes it before running any tests.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272072 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-07 23:32:50 +00:00
Dan Liew
d3e1f7de2b [LibFuzzer] Split the fuzzer-oom.test into two tests.
This is necessary because the existing fuzzer-oom.test was Linux
specific due to its use of __sanitizer_print_memory_profile() which
is only available on Linux right now and so the test would fail on OSX.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272061 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-07 21:23:30 +00:00
Mike Aizatsky
b1953d8c1b [libfuzzer] custom crossover interface function.
Differential Revision: http://reviews.llvm.org/D21089

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272054 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-07 20:22:15 +00:00
Mike Aizatsky
c7f790d744 [libfuzzer] prune_corpus option for disabling pruning during the load.
Summary:
The option is very useful for testing, plus I intend to measure
its effect on fuzzer effectiveness.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272035 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-07 18:16:32 +00:00
Dan Liew
47f90f5156 [LibFuzzer] s/dataflow sanitizer/DataflowSanitizer/
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271980 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-07 04:44:49 +00:00
Dan Liew
ef07357b2f [LibFuzzer] Disable building and running LSan tests on Apple platforms because LSan is not currently supported.
Differential Revision: http://reviews.llvm.org/D20947

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271979 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-07 04:44:39 +00:00
Dan Liew
47f223bd24 [LibFuzzer] Provide stub implementation of __sanitizer_cov_trace_pc_indir
Calls to this function are currently injected by the
``SanitizerCoverageModule`` pass when the both the ``indirect-calls``
and ``trace-pc`` sanitizer coverage options are enabled and the code
being instrumented has indirect calls. Previously because LibFuzzer did
not define this function this would lead to link errors when building
some of the tests on OSX.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271938 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-06 20:27:09 +00:00
Mike Aizatsky
664513feca [libfuzzer] hiding custom mutator handling in MutationDispatcher.
Summary: Refactoring, no functional changes.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271740 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-03 21:34:29 +00:00
Mike Aizatsky
21e8db8cc1 [libfuzzer] splitting fuzzer.test
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271697 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-03 18:05:22 +00:00
Dan Liew
e8edd31970 [LibFuzzer] Disable compiling and running the LibFuzzer dataflow sanitizer tests on Apple platforms.
This fixes a broken part of the build on OSX as the dataflow sanitizer is not supported
on OSX yet.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271492 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-02 05:48:09 +00:00
Dan Liew
8bb56ccbc0 [LibFuzzer] Reimplement how the optional user functions are called.
The motivation for this change is to fix linking issues on OSX.
However this only partially fixes linking issues (the uninstrumented
tests and a few others  won't succesfully link yet).

This change introduces a struct of function pointers
(``fuzzer::ExternalFuntions``) which when initialised will point to the
optional functions if they are available.  Currently these
``LLVMFuzzerInitialize`` and ``LLVMFuzzerCustomMutator`` functions.

Two implementations of ``fuzzer::ExternalFunctions`` constructor are
provided one for Linux and one for OSX.

The OSX implementation uses ``dlsym()`` because the prior implementation
using weak symbols does not work unless the additional flags are passed
to the linker.

The Linux implementation continues to use weak symbols because the
``dlsym()`` approach does not work unless additional flags are passed
to the linker.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271491 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-02 05:48:02 +00:00
Kostya Serebryany
08b019eaf8 [libFuzzer] use __sanitizer_print_memory_profile to print the memory profile on OOM
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271465 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-02 01:33:11 +00:00
Kostya Serebryany
3886b25c4a [libFuzzer] when an invalid flag is given, warn, but don't crash
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271404 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-01 16:41:12 +00:00
Kostya Serebryany
a736e85343 [libFuzzer] fix a use-after-free (!) in libFuzzer caused by r270905: that CL caused a push_back in the main corpus invalidating the vector<> iterators in rare cases.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271186 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-29 15:58:57 +00:00
Kostya Serebryany
8c598528c3 [libFuzzer] fix a failure that occurs when running individual inputs
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271095 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-28 04:19:46 +00:00
Kostya Serebryany
dc4065fcc1 [libFuzzer] use __sanitizer_set_report_fd with -close_fd_mask. This allows us to keep asan reports when closing target's stderr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271053 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-27 21:46:22 +00:00
Richard Smith
0513d1e203 Fix compilation with GCC, which treats this as a constructor name not a type
name. (GCC is correct here per the latest language DRs.)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271044 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-27 21:05:35 +00:00
Dan Liew
70172d9997 [LibFuzzer] Refactor declaration of tests in CMake.
Add a new CMake function (``add_libfuzzer_test()``) to simplify
declaration of executables for testing LibFuzzer and use it to
reorganise how tests are declared.

Note that configuration of the lit configuration files has been moved
as late as possible because we are going to need to disable some tests
for some platforms and we will need to propagate this information into
the lit configuration.

Note the code for custom mains was removed because no tests are
currently written for this and Kostya seems happy to remove this.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270958 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-27 03:14:40 +00:00
Kostya Serebryany
3e20a7ae17 [libFuzzer] make check-fuzzer a bit faster
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270947 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-27 01:12:21 +00:00
Kostya Serebryany
6effb7148b [libFuzzer] make OOM-handling more portable. Instead of sending a signal to the main fuzzing thread, print the message in the getrusage thread and exit.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270945 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-27 00:54:15 +00:00
Kostya Serebryany
d59f71d0d3 [libFuzzer] more refactoring: make sure CurrentUnitData is awlays a valid pointer to read from
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270942 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-27 00:21:33 +00:00
Kostya Serebryany
b987d27af9 [libFuzzer] more refactoring around CurrentUnit. Also add a threading test on which we currently have a race (when reporting bugs from multiple threads)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270929 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-26 22:17:32 +00:00