[llvm] r268088 - [libFuzzer] enable detect_leaks=1, add proper docs

Kostya Serebryany via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 29 11:49:56 PDT 2016


Author: kcc
Date: Fri Apr 29 13:49:55 2016
New Revision: 268088

URL: http://llvm.org/viewvc/llvm-project?rev=268088&view=rev
Log:
[libFuzzer] enable detect_leaks=1, add proper docs

Modified:
    llvm/trunk/docs/LibFuzzer.rst
    llvm/trunk/lib/Fuzzer/FuzzerFlags.def
    llvm/trunk/lib/Fuzzer/FuzzerInternal.h
    llvm/trunk/lib/Fuzzer/test/fuzzer-leak.test

Modified: llvm/trunk/docs/LibFuzzer.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/LibFuzzer.rst?rev=268088&r1=268087&r2=268088&view=diff
==============================================================================
--- llvm/trunk/docs/LibFuzzer.rst (original)
+++ llvm/trunk/docs/LibFuzzer.rst Fri Apr 29 13:49:55 2016
@@ -147,7 +147,8 @@ will be added to the corpus directory.
 By default, the fuzzing process will continue indefinitely – at least until
 a bug is found.  Any crashes or sanitizer failures will be reported as usual,
 stopping the fuzzing process, and the particular input that triggered the bug
-will be written to disk (typically as ``crash-<sha1>`` or ``timeout-<sha1>``).
+will be written to disk (typically as ``crash-<sha1>``, ``leak-<sha1>``,
+or ``timeout-<sha1>``).
 
 
 Parallel Fuzzing
@@ -246,6 +247,9 @@ The most important command line options
   Indicate output streams to close at startup. Be careful, this will also
   remove diagnostic output from the tools in use; for example the messages
   AddressSanitizer_ sends to ``stderr``/``stdout`` will also be lost.
+``-detect-leaks``
+  If 1 (default) and if LeakSanitizer is enabled
+  try to detect memory leaks during fuzzing (i.e. not only at shut down).
 
    - 0 (default): close neither ``stdout`` nor ``stderr``
    - 1 : close ``stdout``
@@ -631,16 +635,22 @@ the program arguments that you can read
 Leaks
 -----
 
-Code that has been built with AddressSanitizer_ will report memory leaks,
-but only when the process exits.  If you suspect memory leaks in the code
-under test, you will therefore need to use the ``-runs=N`` or
-``-max_total_time=N`` command line options to ensure that the fuzzing
-process completes and gives AddressSanitizer_ a chance to report leaks.
-Because the leak is only reported at the end of the process, this also means
-that it is not clear which input triggered the leak.  To narrow this down,
-re-run each input file in the corpus separately through the target function.
+Binaries built with AddressSanitizer_ or LeakSanitizer_ will try to detect
+memory leaks at the process shutdown.
+For in-process fuzzing this is inconvenient
+since the fuzzer needs to report a leak with a reproducer as soon as the leaky
+mutation is found. However, running full leak detection after every mutation
+is expensive.
+
+By default (``-detect_leaks=1``) libFuzzer will count the number of
+``malloc`` and ``free`` calls when executing every mutation.
+If the numbers don't match (which by itself doesn't mean there is a leak)
+libFuzzer will invoke the more expensive LeakSanitizer_
+pass and if the actual leak is found, it will be reported with the reproducer
+and the process will exit.
 
-If your target has massive leaks you will eventually run out of RAM.
+If your target has massive leaks and the leak detection is disabled
+you will eventually run out of RAM.
 To protect your machine from OOM death you may use
 e.g. ``ASAN_OPTIONS=hard_rss_limit_mb=2000`` (with AddressSanitizer_).
 
@@ -806,6 +816,7 @@ Trophies
 .. _SanitizerCoverageTraceDataFlow: http://clang.llvm.org/docs/SanitizerCoverage.html#tracing-data-flow
 .. _DataFlowSanitizer: http://clang.llvm.org/docs/DataFlowSanitizer.html
 .. _AddressSanitizer: http://clang.llvm.org/docs/AddressSanitizer.html
+.. _LeakSanitizer: http://clang.llvm.org/docs/LeakSanitizer.html
 .. _Heartbleed: http://en.wikipedia.org/wiki/Heartbleed
 .. _FuzzerInterface.h: https://github.com/llvm-mirror/llvm/blob/master/lib/Fuzzer/FuzzerInterface.h
 .. _3.7.0: http://llvm.org/releases/3.7.0/docs/LibFuzzer.html

Modified: llvm/trunk/lib/Fuzzer/FuzzerFlags.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerFlags.def?rev=268088&r1=268087&r2=268088&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerFlags.def (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerFlags.def Fri Apr 29 13:49:55 2016
@@ -79,7 +79,7 @@ FUZZER_FLAG_INT(handle_term, 1, "If 1, t
 FUZZER_FLAG_INT(close_fd_mask, 0, "If 1, close stdout at startup; "
     "if 2, close stderr; if 3, close both. "
     "Be careful, this will also close e.g. asan's stderr/stdout.")
-FUZZER_FLAG_INT(detect_leaks, 0, "If 1, and if LeakSanitizer is enabled "
+FUZZER_FLAG_INT(detect_leaks, 1, "If 1, and if LeakSanitizer is enabled "
     "try to detect memory leaks during fuzzing (i.e. not only at shut down).")
 
 FUZZER_DEPRECATED_FLAG(exit_on_first)

Modified: llvm/trunk/lib/Fuzzer/FuzzerInternal.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerInternal.h?rev=268088&r1=268087&r2=268088&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerInternal.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerInternal.h Fri Apr 29 13:49:55 2016
@@ -304,7 +304,7 @@ public:
     bool OutputCSV = false;
     bool PrintNewCovPcs = false;
     bool PrintFinalStats = false;
-    bool DetectLeaks = false;
+    bool DetectLeaks = true;
   };
   Fuzzer(UserCallback CB, MutationDispatcher &MD, FuzzingOptions Options);
   void AddToCorpus(const Unit &U) {

Modified: llvm/trunk/lib/Fuzzer/test/fuzzer-leak.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/fuzzer-leak.test?rev=268088&r1=268087&r2=268088&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/fuzzer-leak.test (original)
+++ llvm/trunk/lib/Fuzzer/test/fuzzer-leak.test Fri Apr 29 13:49:55 2016
@@ -11,7 +11,7 @@ LEAK_IN_CORPUS: ERROR: libFuzzer: initia
 
 
 RUN: not LLVMFuzzer-LeakTest -runs=100000 -detect_leaks=0 2>&1 | FileCheck %s --check-prefix=LEAK_AFTER
-RUN: not LLVMFuzzer-LeakTest -runs=100000                 2>&1 | FileCheck %s --check-prefix=LEAK_AFTER
+RUN: not LLVMFuzzer-LeakTest -runs=100000                 2>&1 | FileCheck %s --check-prefix=LEAK_DURING
 LEAK_AFTER: Done 100000 runs in
 LEAK_AFTER: ERROR: LeakSanitizer: detected memory leaks
 LEAK_AFTER-NOT: DEATH:




More information about the llvm-commits mailing list