Fuzz testing http1 and http2 adaptors in skupper-router
Basics
For a glossary of fuzzing terms please see - https://github.com/google/fuzzing/blob/master/docs/glossary.md
libFuzzer(https://llvm.org/docs/LibFuzzer.html) and AFL(https://github.com/google/AFL) are popular fuzzing engines that can be used for fuzz testing the http1 and the http2 adaptors.
OSS-Fuzz (https://github.com/google/oss-fuzz) supports both libFuzzer and AFL.
skupper-router/tests/fuzz/CMakeLists.txt
The CMakeLists.txt by defaults the fuzzing engine to AFL.
set(FUZZER AFL CACHE STRING "Fuzzing engine to use")
You can change the default fuzzing engine to libFuzzer like this -
set(FUZZER LibFuzzer CACHE STRING "Fuzzing engine to use")
The StandaloneFuzzTargetMain is set as the FUZZING_LIBRARY when regression testing is required (FUZZ_REGRESSION_TESTS=ON)
The regression tests are run as part of the skupper-router test suite in github CI.
The corpus files used by the regression tests are generated by running the fuzzer of your choice inside the container built using the Containerfile which is found in the skupper-router/tests/fuzz folder.
Containerfile
skupper-router/tests/fuzzContainerfile creates an environment where you can run the fuzzer of your choice. You will need to have seed corpus files which the fuzzer will use and build upon to create numerous additional corpus files. If the code crashes, the input that led to the crash is saved. The crash files and the corpus files are downloaded from the container and used in regression testing.
By default the Containerfile clones skupper-router from its github repository. If you are working in your own git repo you will have to modify the git clone command in the Containerfile to use your git repo and branch. For example:
# RUN git clone --depth 1 https://github.com/skupperproject/skupper-router.git
RUN git clone --depth 1 --branch my-branch https://github.com/myrepo/skupper-router.git
Building and running Containerfile
To build the Containerfile from the skupper-router/tests/fuzz/folder
podman build -t oss-fuzz/skupper-router --file=Containerfile .
To run the container
podman run --net host -i -t oss-fuzz/skupper-router
Notice in the Containerfile the two commented ENTRYPOINT lines.
Once you are inside the container, run the AFL fuzzer as seen in the commented ENTRYPOINT lines. For example, to run the http2 fuzzing -
LD_LIBRARY_PATH=/usr/local/lib/clang/18/lib/x86_64-unknown-linux-gnu/ AFL_MAP_SIZE=10000000 AFL_DEBUG=1 AFL_SKIP_CPUFREQ=1 AFL_I_DONT_CARE_ABOUT_MISSING_CRASHES=1 afl-fuzz -i /src/skupper-router/tests/fuzz/fuzz_http2_decoder/corpus/ -o findings_dir /src/skupper-router/build/tests/fuzz/fuzz_http2_decoder
See the comments in the Containerfile for more examples.
Let the fuzzer run for about an hour. Since the fuzzer runs infinitely, to stop the fuzzer, press Ctrl + C. Check for the findings_dir for crashes and additional corpus files. Download the crash and corpus files from the container and run them locally against your code to help fix the crashes.