@@ -3,10 +3,11 @@ Fuzz-testing Bitcoin Core
3
3
4
4
A special test harness ` test_bitcoin_fuzzy ` is provided to provide an easy
5
5
entry point for fuzzers and the like. In this document we'll describe how to
6
- use it with AFL.
6
+ use it with AFL and libFuzzer .
7
7
8
- Building AFL
9
- -------------
8
+ ## AFL
9
+
10
+ ### Building AFL
10
11
11
12
It is recommended to always use the latest version of afl:
12
13
```
17
18
export AFLPATH=$PWD
18
19
```
19
20
20
- Instrumentation
21
- ----------------
21
+ ### Instrumentation
22
22
23
23
To build Bitcoin Core using AFL instrumentation (this assumes that the
24
24
` AFLPATH ` was set as above):
@@ -39,8 +39,7 @@ compiling using `afl-clang-fast`/`afl-clang-fast++` the resulting
39
39
features "persistent mode" and "deferred forkserver" can be used. See
40
40
https://github.com/mcarpenter/afl/tree/master/llvm_mode for details.
41
41
42
- Preparing fuzzing
43
- ------------------
42
+ ### Preparing fuzzing
44
43
45
44
AFL needs an input directory with examples, and an output directory where it
46
45
will place examples that it found. These can be anywhere in the file system,
@@ -60,8 +59,7 @@ Example inputs are available from:
60
59
61
60
Extract these (or other starting inputs) into the ` inputs ` directory before starting fuzzing.
62
61
63
- Fuzzing
64
- --------
62
+ ### Fuzzing
65
63
66
64
To start the actual fuzzing use:
67
65
```
@@ -70,3 +68,21 @@ $AFLPATH/afl-fuzz -i ${AFLIN} -o ${AFLOUT} -m52 -- test/test_bitcoin_fuzzy
70
68
71
69
You may have to change a few kernel parameters to test optimally - ` afl-fuzz `
72
70
will print an error and suggestion if so.
71
+
72
+ ## libFuzzer
73
+
74
+ A recent version of ` clang ` , the address sanitizer and libFuzzer is needed (all
75
+ found in the ` compiler-rt ` runtime libraries package).
76
+
77
+ To build the ` test/test_bitcoin_fuzzy ` executable run
78
+
79
+ ```
80
+ ./configure --disable-ccache --with-sanitizers=fuzzer,address CC=clang CXX=clang++
81
+ make
82
+ ```
83
+
84
+ The fuzzer needs some inputs to work on, but the inputs or seeds can be used
85
+ interchangably between libFuzzer and AFL.
86
+
87
+ See https://llvm.org/docs/LibFuzzer.html#running on how to run the libFuzzer
88
+ instrumented executable.
0 commit comments