diff --git a/infra/base-images/base-builder/Dockerfile b/infra/base-images/base-builder/Dockerfile index ce8dad1cc8db..eabeb55c9f0c 100644 --- a/infra/base-images/base-builder/Dockerfile +++ b/infra/base-images/base-builder/Dockerfile @@ -132,9 +132,9 @@ COPY precompile_honggfuzz /usr/local/bin/ RUN precompile_honggfuzz RUN cd $SRC && \ - git clone https://github.com/google/centipede.git && \ + git clone -n https://github.com/google/centipede.git && \ cd centipede && \ - git checkout eb91dd2157710e6c82579f8be19d7fab9423b781 && \ + git checkout 2a2c78a2c161d99f5962b9710bce61feb00acc3d && \ rm -rf .git COPY precompile_centipede /usr/local/bin/ diff --git a/infra/base-images/base-builder/compile_centipede b/infra/base-images/base-builder/compile_centipede index 1f72a2075a84..7e60b2b2017c 100755 --- a/infra/base-images/base-builder/compile_centipede +++ b/infra/base-images/base-builder/compile_centipede @@ -27,9 +27,15 @@ cp "$BIN_DIR/libcentipede_runner.pic.a" "$LIB_FUZZING_ENGINE" export DFTRACING_FLAGS='-fsanitize-coverage=trace-loads' export CENTIPEDE_FLAGS=`cat "$SRC/centipede/clang-flags.txt" | tr '\n' ' '` -export LIBRARIES_FLAGS="-Wno-unused-command-line-argument -ldl -lrt -lpthread $SRC/centipede/weak.o" +export LIBRARIES_FLAGS="-lc++ -Wno-unused-command-line-argument" export CFLAGS="$CFLAGS $DFTRACING_FLAGS $CENTIPEDE_FLAGS $LIBRARIES_FLAGS" export CXXFLAGS="$CXXFLAGS $DFTRACING_FLAGS $CENTIPEDE_FLAGS $LIBRARIES_FLAGS" +# For Meson. +export LDFLAGS='/src/centipede/weak.o' + +# For Centipede's ld +export CENTIPEDE_BIN="$SRC/centipede/bin" +export PATH="$CENTIPEDE_BIN":$PATH echo 'done.' diff --git a/infra/base-images/base-builder/precompile_centipede b/infra/base-images/base-builder/precompile_centipede index 6af9d562f15b..3cc92bd76b7e 100755 --- a/infra/base-images/base-builder/precompile_centipede +++ b/infra/base-images/base-builder/precompile_centipede @@ -32,6 +32,15 @@ bazel --bazelrc=/tmp/centipede.bazelrc build -c opt :all # The weak symbols provides fake implementations for intermediate binaries. $CXX "$SRC/centipede/weak_sancov_stubs.cc" -c -o "$SRC/centipede/weak.o" +# Centipede's ld, which always appends weak.o as a parameter. +export CENTIPEDE_BIN="$SRC/centipede/bin" +mkdir -p $CENTIPEDE_BIN +cat << EOF > ${CENTIPEDE_BIN}/ld +#!/bin/bash +/usr/bin/ld \$@ -ldl -lrt -lpthread -lc++ /src/centipede/weak.o +EOF +chmod 777 ${CENTIPEDE_BIN}/ld + echo 'Removing extra stuff leftover to avoid bloating image.' rm -rf /clang-*.tgz /clang diff --git a/infra/build/functions/build_project.py b/infra/build/functions/build_project.py index 23ec94810f55..ec21c87030ea 100755 --- a/infra/build/functions/build_project.py +++ b/infra/build/functions/build_project.py @@ -42,7 +42,7 @@ GCB_LOGS_BUCKET = 'oss-fuzz-gcb-logs' DEFAULT_ARCHITECTURES = ['x86_64'] -DEFAULT_ENGINES = ['libfuzzer', 'afl', 'honggfuzz'] +DEFAULT_ENGINES = ['libfuzzer', 'afl', 'honggfuzz', 'centipede'] DEFAULT_SANITIZERS = ['address', 'undefined'] LATEST_VERSION_FILENAME = 'latest.version' diff --git a/infra/build/functions/test_data/expected_build_steps.json b/infra/build/functions/test_data/expected_build_steps.json index 37c13e0d0f90..065c76c7bbbf 100644 --- a/infra/build/functions/test_data/expected_build_steps.json +++ b/infra/build/functions/test_data/expected_build_steps.json @@ -213,6 +213,288 @@ "rm -r /workspace/out/afl-address-x86_64" ] }, + { + "name": "gcr.io/cloud-builders/docker", + "env": [ + "ARCHITECTURE=x86_64", + "FUZZING_ENGINE=centipede", + "FUZZING_LANGUAGE=c++", + "HOME=/root", + "OUT=/workspace/out/centipede-address-x86_64", + "SANITIZER=address" + ], + "args": [ + "run", + "--platform", + "linux/amd64", + "-v", + "/workspace:/workspace", + "--privileged", + "--cap-add=all", + "-e", + "ARCHITECTURE=x86_64", + "-e", + "FUZZING_ENGINE=centipede", + "-e", + "FUZZING_LANGUAGE=c++", + "-e", + "HOME=/root", + "-e", + "OUT=/workspace/out/centipede-address-x86_64", + "-e", + "SANITIZER=address", + "-t", + "gcr.io/oss-fuzz/test-project", + "bash", + "-c", + "rm -r /out && cd /src && cd /src && mkdir -p /workspace/out/centipede-address-x86_64 && compile || (echo \"********************************************************************************\nFailed to build.\nTo reproduce, run:\npython infra/helper.py build_image test-project\npython infra/helper.py build_fuzzers --sanitizer address --engine centipede --architecture x86_64 test-project\n********************************************************************************\" && false)" + ], + "id": "compile-centipede-address-x86_64" + }, + { + "name": "gcr.io/cloud-builders/docker", + "env": [ + "ARCHITECTURE=x86_64", + "FUZZING_ENGINE=centipede", + "FUZZING_LANGUAGE=c++", + "HOME=/root", + "OUT=/workspace/out/centipede-address-x86_64", + "SANITIZER=address" + ], + "args": [ + "run", + "--platform", + "linux/amd64", + "-v", + "/workspace:/workspace", + "--privileged", + "--cap-add=all", + "-e", + "ARCHITECTURE=x86_64", + "-e", + "FUZZING_ENGINE=centipede", + "-e", + "FUZZING_LANGUAGE=c++", + "-e", + "HOME=/root", + "-e", + "OUT=/workspace/out/centipede-address-x86_64", + "-e", + "SANITIZER=address", + "-t", + "gcr.io/oss-fuzz-base/base-runner", + "bash", + "-c", + "test_all.py || (echo \"********************************************************************************\nBuild checks failed.\nTo reproduce, run:\npython infra/helper.py build_image test-project\npython infra/helper.py build_fuzzers --sanitizer address --engine centipede --architecture x86_64 test-project\npython infra/helper.py check_build --sanitizer address --engine centipede --architecture x86_64 test-project\n********************************************************************************\" && false)" + ], + "id": "build-check-centipede-address-x86_64" + }, + { + "name": "gcr.io/oss-fuzz-base/base-runner", + "env": [ + "ARCHITECTURE=x86_64", + "FUZZING_ENGINE=centipede", + "FUZZING_LANGUAGE=c++", + "HOME=/root", + "OUT=/workspace/out/centipede-address-x86_64", + "SANITIZER=address" + ], + "args": [ + "bash", + "-c", + "targets_list > /workspace/targets.list.address" + ] + }, + { + "name": "gcr.io/oss-fuzz/test-project", + "args": [ + "bash", + "-c", + "cd /workspace/out/centipede-address-x86_64 && zip -r test-project-address-202001010000.zip *" + ] + }, + { + "name": "gcr.io/oss-fuzz-base/uploader", + "args": [ + "/workspace/srcmap.json", + "test_url" + ] + }, + { + "name": "gcr.io/oss-fuzz-base/uploader", + "args": [ + "/workspace/out/centipede-address-x86_64/test-project-address-202001010000.zip", + "test_url" + ] + }, + { + "name": "gcr.io/oss-fuzz-base/uploader", + "args": [ + "/workspace/targets.list.address", + "test_url" + ] + }, + { + "name": "gcr.io/cloud-builders/curl", + "args": [ + "-H", + "Content-Type: text/plain", + "-X", + "PUT", + "-d", + "test-project-address-202001010000.zip", + "test_url" + ] + }, + { + "name": "gcr.io/oss-fuzz/test-project", + "args": [ + "bash", + "-c", + "rm -r /workspace/out/centipede-address-x86_64" + ] + }, + { + "name": "gcr.io/cloud-builders/docker", + "env": [ + "ARCHITECTURE=x86_64", + "FUZZING_ENGINE=centipede", + "FUZZING_LANGUAGE=c++", + "HOME=/root", + "OUT=/workspace/out/centipede-none-x86_64", + "SANITIZER=none" + ], + "args": [ + "run", + "--platform", + "linux/amd64", + "-v", + "/workspace:/workspace", + "--privileged", + "--cap-add=all", + "-e", + "ARCHITECTURE=x86_64", + "-e", + "FUZZING_ENGINE=centipede", + "-e", + "FUZZING_LANGUAGE=c++", + "-e", + "HOME=/root", + "-e", + "OUT=/workspace/out/centipede-none-x86_64", + "-e", + "SANITIZER=none", + "-t", + "gcr.io/oss-fuzz/test-project", + "bash", + "-c", + "rm -r /out && cd /src && cd /src && mkdir -p /workspace/out/centipede-none-x86_64 && compile || (echo \"********************************************************************************\nFailed to build.\nTo reproduce, run:\npython infra/helper.py build_image test-project\npython infra/helper.py build_fuzzers --sanitizer none --engine centipede --architecture x86_64 test-project\n********************************************************************************\" && false)" + ], + "id": "compile-centipede-none-x86_64" + }, + { + "name": "gcr.io/cloud-builders/docker", + "env": [ + "ARCHITECTURE=x86_64", + "FUZZING_ENGINE=centipede", + "FUZZING_LANGUAGE=c++", + "HOME=/root", + "OUT=/workspace/out/centipede-none-x86_64", + "SANITIZER=none" + ], + "args": [ + "run", + "--platform", + "linux/amd64", + "-v", + "/workspace:/workspace", + "--privileged", + "--cap-add=all", + "-e", + "ARCHITECTURE=x86_64", + "-e", + "FUZZING_ENGINE=centipede", + "-e", + "FUZZING_LANGUAGE=c++", + "-e", + "HOME=/root", + "-e", + "OUT=/workspace/out/centipede-none-x86_64", + "-e", + "SANITIZER=none", + "-t", + "gcr.io/oss-fuzz-base/base-runner", + "bash", + "-c", + "test_all.py || (echo \"********************************************************************************\nBuild checks failed.\nTo reproduce, run:\npython infra/helper.py build_image test-project\npython infra/helper.py build_fuzzers --sanitizer none --engine centipede --architecture x86_64 test-project\npython infra/helper.py check_build --sanitizer none --engine centipede --architecture x86_64 test-project\n********************************************************************************\" && false)" + ], + "id": "build-check-centipede-none-x86_64" + }, + { + "name": "gcr.io/oss-fuzz-base/base-runner", + "env": [ + "ARCHITECTURE=x86_64", + "FUZZING_ENGINE=centipede", + "FUZZING_LANGUAGE=c++", + "HOME=/root", + "OUT=/workspace/out/centipede-none-x86_64", + "SANITIZER=none" + ], + "args": [ + "bash", + "-c", + "targets_list > /workspace/targets.list.none" + ] + }, + { + "name": "gcr.io/oss-fuzz/test-project", + "args": [ + "bash", + "-c", + "cd /workspace/out/centipede-none-x86_64 && zip -r test-project-none-202001010000.zip *" + ] + }, + { + "name": "gcr.io/oss-fuzz-base/uploader", + "args": [ + "/workspace/srcmap.json", + "test_url" + ] + }, + { + "name": "gcr.io/oss-fuzz-base/uploader", + "args": [ + "/workspace/out/centipede-none-x86_64/test-project-none-202001010000.zip", + "test_url" + ] + }, + { + "name": "gcr.io/oss-fuzz-base/uploader", + "args": [ + "/workspace/targets.list.none", + "test_url" + ] + }, + { + "name": "gcr.io/cloud-builders/curl", + "args": [ + "-H", + "Content-Type: text/plain", + "-X", + "PUT", + "-d", + "test-project-none-202001010000.zip", + "test_url" + ] + }, + { + "name": "gcr.io/oss-fuzz/test-project", + "args": [ + "bash", + "-c", + "rm -r /workspace/out/centipede-none-x86_64" + ] + }, { "name": "gcr.io/cloud-builders/docker", "env": [ diff --git a/infra/ci/build.py b/infra/ci/build.py index 8e573ae68f20..18a22c95d6d0 100755 --- a/infra/ci/build.py +++ b/infra/ci/build.py @@ -33,7 +33,7 @@ CANARY_PROJECT = 'skcms' DEFAULT_ARCHITECTURES = ['x86_64'] -DEFAULT_ENGINES = ['afl', 'honggfuzz', 'libfuzzer'] +DEFAULT_ENGINES = ['afl', 'honggfuzz', 'libfuzzer', 'centipede'] DEFAULT_SANITIZERS = ['address', 'undefined']