| 1 |
# Fuzzers |
| 2 |
|
| 3 |
These are fuzzers designed for use with `libFuzzer` or `afl`. They can |
| 4 |
be used to run on Google's OSS-Fuzz (https://github.com/google/oss-fuzz/). |
| 5 |
|
| 6 |
The convention used here is that the initial values for each parser fuzzer |
| 7 |
are taken from the $NAME.in directory. |
| 8 |
|
| 9 |
Crash reproducers from OSS-Fuzz are put into $NAME.repro directory for |
| 10 |
regression testing with top dir 'make check' or 'make check-valgrind'. |
| 11 |
|
| 12 |
|
| 13 |
# Running a fuzzer using clang |
| 14 |
|
| 15 |
Use the following commands on top dir: |
| 16 |
``` |
| 17 |
export CC=clang |
| 18 |
# address sanitizer: |
| 19 |
#export CFLAGS="-O1 -g -fno-omit-frame-pointer -gline-tables-only -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=undefined,integer,nullability -fsanitize=address -fsanitize-address-use-after-scope -fsanitize-coverage=trace-pc-guard,trace-cmp" |
| 20 |
export CFLAGS="-O1 -fno-omit-frame-pointer -gline-tables-only -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=undefined -fsanitize=address -fsanitize-address-use-after-scope -fsanitize=fuzzer-no-link" |
| 21 |
# undefined sanitizer; |
| 22 |
export CFLAGS="-O1 -fno-omit-frame-pointer -gline-tables-only -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=bool,array-bounds,float-divide-by-zero,function,integer-divide-by-zero,return,shift,signed-integer-overflow,vla-bound,vptr -fno-sanitize-recover=bool,array-bounds,float-divide-by-zero,function,integer-divide-by-zero,return,shift,signed-integer-overflow,vla-bound,vptr -fsanitize=fuzzer-no-link" |
| 23 |
export LIB_FUZZING_ENGINE="-lFuzzer -lstdc++" |
| 24 |
./configure --enable-fuzzing --without-metalink --without-zlib --disable-pcre --without-libuuid --enable-assert |
| 25 |
make clean |
| 26 |
make -j$(nproc) |
| 27 |
cd fuzz |
| 28 |
|
| 29 |
# run wget_options_fuzzer |
| 30 |
UBSAN_OPTIONS=print_stacktrace=1 ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer \ |
| 31 |
./run-clang.sh wget_options_fuzzer |
| 32 |
``` |
| 33 |
|
| 34 |
If you see a crash, then a crash corpora is written that can be used for further |
| 35 |
investigation. E.g. |
| 36 |
``` |
| 37 |
==2410==ERROR: AddressSanitizer: heap-use-after-free on address 0x602000004e90 at pc 0x00000049cf9c bp 0x7fffb5543f70 sp 0x7fffb5543720 |
| 38 |
... |
| 39 |
Test unit written to ./crash-adc83b19e793491b1c6ea0fd8b46cd9f32e592fc |
| 40 |
``` |
| 41 |
|
| 42 |
To reproduce the crash: |
| 43 |
``` |
| 44 |
./wget_options_fuzzer < ./crash-adc83b19e793491b1c6ea0fd8b46cd9f32e592fc |
| 45 |
``` |
| 46 |
|
| 47 |
You can also copy/move that file into wget_options_fuzzer.repro/ |
| 48 |
and re-build the project without fuzzing for a valgrind run, if you like that better. |
| 49 |
Just a `./configure` and a `make check-valgrind` should reproduce it. |
| 50 |
|
| 51 |
|
| 52 |
# Running a fuzzer using AFL |
| 53 |
|
| 54 |
Use the following commands on top dir: |
| 55 |
|
| 56 |
``` |
| 57 |
$ export LIB_FUZZING_ENGINE="" |
| 58 |
$ CC=afl-clang-fast ./configure --enable-fuzzing |
| 59 |
$ make -j$(nproc) clean all |
| 60 |
$ cd fuzz |
| 61 |
$ ./run-afl.sh wget_options_fuzzer |
| 62 |
``` |
| 63 |
|
| 64 |
# Fuzz code coverage using the corpus directories *.in/ |
| 65 |
|
| 66 |
Code coverage reports currently work best with gcc+lcov+genhtml. |
| 67 |
|
| 68 |
In the top directory: |
| 69 |
``` |
| 70 |
CC=gcc CFLAGS="-O0 -g" ./configure |
| 71 |
make fuzz-coverage |
| 72 |
xdg-open lcov/index.html |
| 73 |
``` |
| 74 |
|
| 75 |
To work on corpora for better coverage, `cd fuzz` and use e.g. |
| 76 |
`./view-coverage.sh wget_options_fuzzer`. |
| 77 |
|
| 78 |
|
| 79 |
# Creating wget_options_fuzzer.dict |
| 80 |
|
| 81 |
``` |
| 82 |
for i in `../src/wget --help|tr ' ' '\n'|grep ^--|cut -c 3-|sort`;do echo \"$i\"; done >wget_options_fuzzer.dict |
| 83 |
``` |