-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #1613: Added fuzz testing for the http2 decoder. Fixes for two …
…issues that the fuzz tester found.
- Loading branch information
1 parent
7462d96
commit de72015
Showing
71 changed files
with
524 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
add_definitions(${C_STANDARD_FLAGS} ${COMPILE_WARNING_FLAGS}) | ||
|
||
option(FUZZ_REGRESSION_TESTS "Run fuzz tests with regression test driver" ON) | ||
option(FUZZ_LONG_TESTS "Run fuzz tests that take a long time" OFF) | ||
set(FUZZER AFL CACHE STRING "Fuzzing engine to use") # Set AFL as the default fuzzer | ||
set(FUZZING_LIB_LibFuzzer FuzzingEngine) | ||
set(FUZZING_LIB_AFL -fsanitize=fuzzer) | ||
|
||
add_library(StandaloneFuzzTargetMain STATIC StandaloneFuzzTargetMain.c StandaloneFuzzTargetInit.c) | ||
|
||
if (FUZZ_REGRESSION_TESTS) | ||
message(STATUS "FUZZ_REGRESSION_TESTS") | ||
set(FUZZING_LIBRARY StandaloneFuzzTargetMain) | ||
else () | ||
message(STATUS "NO FUZZ_REGRESSION_TESTS") | ||
set(FUZZING_LIBRARY ${FUZZING_LIB_${FUZZER}}) | ||
endif () | ||
|
||
macro(add_fuzz_test test) | ||
add_executable (${test} ${ARGN}) | ||
target_link_libraries (${test} ${FUZZING_LIBRARY} skupper-router) | ||
set_target_properties(fuzz_http2_decoder PROPERTIES LINKER_LANGUAGE CXX) | ||
|
||
if(FUZZ_REGRESSION_TESTS) | ||
file(GLOB_RECURSE files ${CMAKE_CURRENT_SOURCE_DIR}/${test}/*) | ||
unset(file_lines) | ||
foreach(f IN LISTS files) | ||
set(file_lines "${file_lines}${f}\n") | ||
endforeach() | ||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${test}-files" "${file_lines}") | ||
add_test(${test} ${TEST_WRAP} ${test} "@${CMAKE_CURRENT_BINARY_DIR}/${test}-files") | ||
else(FUZZ_REGRESSION_TESTS) | ||
add_test(${test} ${TEST_WRAP} ${test} "${CMAKE_CURRENT_SOURCE_DIR}/${test}") | ||
endif(FUZZ_REGRESSION_TESTS) | ||
endmacro(add_fuzz_test test) | ||
|
||
add_fuzz_test(fuzz_http2_decoder fuzz_http2_decoder.c) | ||
#add_fuzz_test(fuzz_http1_decoder fuzz_http1_decoder.c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Copyright 2017 Google Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
################################################################################ | ||
|
||
FROM gcr.io/oss-fuzz-base/base-builder | ||
RUN apt-get update | ||
|
||
# Ensure we work from right python version | ||
# Minimum python version required by qpid-proton and skupper-router is Python 3.9 | ||
RUN apt-get install -y python3.9 python3.9-dev && \ | ||
ln --force -s /usr/bin/python3.9 /usr/local/bin/python3 && \ | ||
apt-get install -y python3-pip | ||
RUN apt-get install -y libuv1-dev wget cmake emacs python3-dev libwebsockets-dev libtool zlib1g-dev cmake libsasl2-dev libssl-dev sasl2-bin libnghttp2-dev | ||
|
||
# LibwebSockets library is required by skupper-router | ||
# We are using v4.2-stable instead v4.3-stable because of this lws compilation error - https://github.com/warmcat/libwebsockets/issues/3163 | ||
RUN git clone https://github.com/warmcat/libwebsockets.git --branch v4.2-stable | ||
WORKDIR /src | ||
RUN mkdir libwebsockets/build && cd libwebsockets/build && cmake .. -DLWS_LINK_TESTAPPS_DYNAMIC=ON -DLWS_WITH_LIBUV=OFF -DLWS_WITHOUT_BUILTIN_GETIFADDRS=ON -DLWS_WITHOUT_BUILTIN_SHA1=ON -DLWS_WITH_STATIC=OFF -DLWS_IPV6=ON -DLWS_WITH_HTTP2=OFF -DLWS_WITHOUT_CLIENT=OFF -DLWS_WITHOUT_SERVER=OFF -DLWS_WITHOUT_TESTAPPS=ON -DLWS_WITHOUT_TEST_SERVER=ON -DLWS_WITHOUT_TEST_SERVER_EXTPOLL=ON -DLWS_WITHOUT_TEST_PING=ON -DLWS_WITHOUT_TEST_CLIENT=ON && make install | ||
|
||
RUN git clone https://github.com/apache/qpid-proton.git | ||
WORKDIR /src/qpid-proton | ||
RUN mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=OFF -DENABLE_LINKTIME_OPTIMIZATION=OFF -DBUILD_TLS=ON -DSSL_IMPL=openssl -DBUILD_TOOLS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_TESTING=OFF && make install | ||
|
||
WORKDIR /src | ||
RUN git clone https://github.com/ganeshmurthy/skupper-router.git --branch FUZZ-TESTING | ||
|
||
WORKDIR /src/skupper-router | ||
|
||
# refresh the build directory if it exists already | ||
RUN rm build -rf || true | ||
|
||
# /usr/local/bin/compile compiles libFuzzer or AmericanFuzzyLop(afl), then calls /src/build.sh and sets correct environment variables for it | ||
RUN echo cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=OFF -DFUZZ_REGRESSION_TESTS=OFF -DCMAKE_C_FLAGS=-DQD_MEMORY_DEBUG -DRUNTIME_CHECK=asan > /src/build.sh | ||
|
||
# build and run the test. Choose AFL for fuzzer | ||
RUN mkdir build | ||
WORKDIR /src/skupper-router/build | ||
RUN FUZZING_LANGUAGE='' FUZZING_ENGINE=afl /usr/local/bin/compile | ||
WORKDIR /src/skupper-router/build/tests/fuzz | ||
RUN make | ||
|
||
# This starts the AFL fuzzer that runs in an infinite loop. Let it run for about 30 minutes and press Ctrl + C to kill it. | ||
# The AFL program displays the stats on stdout upon termination. | ||
# Uncomment ONE of the following lines to start the AFL fuzzer for the http2 or the http1 decoder. Before starting the AFL fuzzer, make sure you have some seed datta in the respective corpus folders. | ||
#ENTRYPOINT 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; bash | ||
#ENTRYPOINT 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_http1_decoder/corpus/ -o findings_dir /src/skupper-router/build/tests/fuzz/fuzz_http1_decoder; bash | ||
CMD ["/bin/bash"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# 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. | ||
|
||
##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 | ||
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
*/ | ||
#include <qpid/dispatch/alloc_pool.h> | ||
#include <qpid/dispatch/log.h> | ||
|
||
void qd_log_initialize(void); | ||
void qd_error_initialize(void); | ||
|
||
#include "libFuzzingEngine.h" | ||
|
||
int LLVMFuzzerInitialize(int *argc, char ***argv) | ||
{ | ||
qd_alloc_initialize(); | ||
qd_log_initialize(); | ||
qd_error_initialize(); | ||
return 0; | ||
} | ||
|
Oops, something went wrong.