From 64bc5d5bdbe12e4e603a46763e959f68a6ad5212 Mon Sep 17 00:00:00 2001 From: Mrmaxmeier <3913977+Mrmaxmeier@users.noreply.github.com> Date: Sun, 23 Oct 2022 01:58:33 +0200 Subject: [PATCH] CI: speedups and fixes (#855) * scripts/clippy.sh: remove cargo clean step Clippy used to only report warnings in code that was not part of the incremental cache. This has changed since and I believe we can safely drop the `cargo clean` step. * Revert "ci: install z3 to avoid building from source" This reverts commit 6ff1c4088811040dcfdbd12273f0baf507a4308b. This doesn't do anything as we're using `static-link-z3` explicitly. * refactor test_all_fuzzers nyx tests were not included in `time_record` before this * nyx fuzzer: move modprobe logic out of setup_libxml2.sh --- .github/workflows/build_and_test.yml | 2 +- fuzzers/nyx_libxml2_parallel/Makefile.toml | 14 +++++++- fuzzers/nyx_libxml2_parallel/setup_libxml2.sh | 4 --- fuzzers/nyx_libxml2_standalone/Makefile.toml | 14 +++++++- .../nyx_libxml2_standalone/setup_libxml2.sh | 6 ---- scripts/clippy.sh | 6 ---- scripts/test_all_fuzzers.sh | 32 +++++++------------ 7 files changed, 39 insertions(+), 39 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index ad56997968..593af41023 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -156,7 +156,7 @@ jobs: - uses: lyricwulf/abc@v1 with: # todo: remove afl++-clang when nyx support samcov_pcguard - linux: llvm llvm-dev clang nasm ninja-build gcc-arm-linux-gnueabi g++-arm-linux-gnueabi libgtk-3-dev afl++-clang pax-utils z3 libz3-dev + linux: llvm llvm-dev clang nasm ninja-build gcc-arm-linux-gnueabi g++-arm-linux-gnueabi libgtk-3-dev afl++-clang pax-utils # update bash for macos to support `declare -A` command` macos: llvm libpng nasm coreutils z3 bash - name: pip install diff --git a/fuzzers/nyx_libxml2_parallel/Makefile.toml b/fuzzers/nyx_libxml2_parallel/Makefile.toml index ee7fc262c6..ded65f8afd 100644 --- a/fuzzers/nyx_libxml2_parallel/Makefile.toml +++ b/fuzzers/nyx_libxml2_parallel/Makefile.toml @@ -28,6 +28,18 @@ script=''' ./setup_libxml2.sh ''' +[tasks.enable_kvm_vmware_hypercall] +script_runner = "@shell" +script=''' +if [ ! -e /sys/module/kvm/parameters/enable_vmware_backdoor ] || + ! grep -qF Y /sys/module/kvm/parameters/enable_vmware_backdoor; then + sudo modprobe -r kvm-intel # or kvm-amd for AMD + sudo modprobe -r kvm + sudo modprobe kvm enable_vmware_backdoor=y + sudo modprobe kvm-intel +fi; +''' + # Run the fuzzer [tasks.run] linux_alias = "run_unix" @@ -39,7 +51,7 @@ script_runner = "@shell" script=''' cargo run ''' -dependencies = [ "libxml2" ] +dependencies = [ "libxml2", "enable_kvm_vmware_hypercall" ] # Clean up [tasks.clean] diff --git a/fuzzers/nyx_libxml2_parallel/setup_libxml2.sh b/fuzzers/nyx_libxml2_parallel/setup_libxml2.sh index 9100a0e7fc..42ddafdca0 100755 --- a/fuzzers/nyx_libxml2_parallel/setup_libxml2.sh +++ b/fuzzers/nyx_libxml2_parallel/setup_libxml2.sh @@ -23,7 +23,3 @@ python3 "../../libafl_nyx/packer/packer/nyx_packer.py" \ --purge || exit python3 ../../libafl_nyx/packer/packer/nyx_config_gen.py /tmp/nyx_libxml2/ Kernel || exit -sudo modprobe -r kvm-intel # or kvm-amd for AMD -sudo modprobe -r kvm -sudo modprobe kvm enable_vmware_backdoor=y -sudo modprobe kvm-intel diff --git a/fuzzers/nyx_libxml2_standalone/Makefile.toml b/fuzzers/nyx_libxml2_standalone/Makefile.toml index ee79b6703c..904359f285 100644 --- a/fuzzers/nyx_libxml2_standalone/Makefile.toml +++ b/fuzzers/nyx_libxml2_standalone/Makefile.toml @@ -28,6 +28,18 @@ script=''' ./setup_libxml2.sh ''' +[tasks.enable_kvm_vmware_hypercall] +script_runner = "@shell" +script=''' +if [ ! -e /sys/module/kvm/parameters/enable_vmware_backdoor ] || + ! grep -qF Y /sys/module/kvm/parameters/enable_vmware_backdoor; then + sudo modprobe -r kvm-intel # or kvm-amd for AMD + sudo modprobe -r kvm + sudo modprobe kvm enable_vmware_backdoor=y + sudo modprobe kvm-intel +fi; +''' + # Run the fuzzer [tasks.run] linux_alias = "run_unix" @@ -39,7 +51,7 @@ script_runner = "@shell" script=''' cargo run ''' -dependencies = [ "libxml2" ] +dependencies = [ "libxml2", "enable_kvm_vmware_hypercall" ] # Clean up [tasks.clean] diff --git a/fuzzers/nyx_libxml2_standalone/setup_libxml2.sh b/fuzzers/nyx_libxml2_standalone/setup_libxml2.sh index 9100a0e7fc..f32d980992 100755 --- a/fuzzers/nyx_libxml2_standalone/setup_libxml2.sh +++ b/fuzzers/nyx_libxml2_standalone/setup_libxml2.sh @@ -21,9 +21,3 @@ python3 "../../libafl_nyx/packer/packer/nyx_packer.py" \ -file "/tmp/input" \ --fast_reload_mode \ --purge || exit - -python3 ../../libafl_nyx/packer/packer/nyx_config_gen.py /tmp/nyx_libxml2/ Kernel || exit -sudo modprobe -r kvm-intel # or kvm-amd for AMD -sudo modprobe -r kvm -sudo modprobe kvm enable_vmware_backdoor=y -sudo modprobe kvm-intel diff --git a/scripts/clippy.sh b/scripts/clippy.sh index 092600f3d0..e3da4a6c5c 100755 --- a/scripts/clippy.sh +++ b/scripts/clippy.sh @@ -2,12 +2,6 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd "$SCRIPT_DIR/.." || exit 1 -# Clippy checks -if [ "$1" != "--no-clean" ]; then - # Usually, we want to clean, since clippy won't work otherwise. - echo "[+] Cleaning up previous builds..." - cargo clean -p libafl -fi RUST_BACKTRACE=full cargo +nightly clippy --all --all-features --release --tests -- -Z macro-backtrace \ -D clippy::all \ -D clippy::pedantic \ diff --git a/scripts/test_all_fuzzers.sh b/scripts/test_all_fuzzers.sh index cba530e14e..93b151b8d4 100755 --- a/scripts/test_all_fuzzers.sh +++ b/scripts/test_all_fuzzers.sh @@ -10,6 +10,9 @@ backtrace_fuzzers=$(find ./fuzzers/backtrace_baby_fuzzers -mindepth 1 -maxdepth libafl=$(pwd) +# build with a shared target dir for all fuzzers. this should speed up +# compilation a bit, and allows for easier artifact management (caching and +# cargo clean). export CARGO_TARGET_DIR="$libafl/target" mkdir -p "$CARGO_TARGET_DIR" @@ -34,23 +37,8 @@ declare -A time_record || (echo "declare -A not avaliable, please update your ba # shellcheck disable=SC2116 for fuzzer in $(echo "$fuzzers" "$backtrace_fuzzers"); do - # for nyx examples - if [[ $fuzzer == *"nyx_"* ]]; then - - # only test on linux - if [[ $(uname -s) == "Linux" ]]; then - cd "$fuzzer" || exit 1 - if [ "$1" != "--no-fmt" ]; then - echo "[*] Checking fmt for $fuzzer" - cargo fmt --all -- --check || exit 1 - echo "[*] Running clippy for $fuzzer" - cargo clippy || exit 1 - else - echo "[+] Skipping fmt and clippy for $fuzzer (--no-fmt specified)" - fi - cargo make build - cd - || exit - fi + # skip nyx test on non-linux platforms + if [[ $fuzzer == *"nyx_"* ]] && [[ $(uname -s) != "Linux" ]]; then continue fi @@ -67,10 +55,14 @@ do echo "[+] Skipping fmt and clippy for $fuzzer (--no-fmt specified)" fi - if [ -e ./Makefile.toml ]; then + if [ -e ./Makefile.toml ] && grep -qF "skip_core_tasks = true" Makefile.toml; then + echo "[*] Building $fuzzer (running tests is not supported in this context)" + cargo make build || exit 1 + echo "[+] Done building $fuzzer" + elif [ -e ./Makefile.toml ]; then echo "[*] Testing $fuzzer" cargo make test || exit 1 - echo "[+] Done testing $fuzzer" + echo "[+] Done testing $fuzzer" else echo "[*] Building $fuzzer" cargo build || exit 1 @@ -82,7 +74,7 @@ do # Save disk space cargo clean -p "$(basename "$fuzzer")" cargo clean --release -p "$(basename "$fuzzer")" 2> /dev/null - # Leaving these in the cache results in lots of duplicate build artefacts + # Leaving these in the cache results in lots of duplicate build artifacts # (many different feature flag combinations, ...), so let's prune them. for clean_pkgid in libafl libafl_targets libafl_sugar; do cargo clean -p "$clean_pkgid" 2> /dev/null