From bf4d06c508e4a7b1bd77da1a2d927ec32d63f603 Mon Sep 17 00:00:00 2001 From: Evan Richter Date: Sat, 11 Jun 2022 21:10:57 -0500 Subject: [PATCH] mayhem integration --- .github/workflows/mayhem.yml | 60 ++++++++++++++++++++++++++++++++++++ mayhem/.dockerignore | 3 ++ mayhem/Dockerfile | 22 +++++++++++++ mayhem/hosts.mayhemfile | 7 +++++ 4 files changed, 92 insertions(+) create mode 100644 .github/workflows/mayhem.yml create mode 100644 mayhem/.dockerignore create mode 100644 mayhem/Dockerfile create mode 100644 mayhem/hosts.mayhemfile diff --git a/.github/workflows/mayhem.yml b/.github/workflows/mayhem.yml new file mode 100644 index 0000000..a234981 --- /dev/null +++ b/.github/workflows/mayhem.yml @@ -0,0 +1,60 @@ +name: Mayhem +on: + push: + pull_request: + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + name: 'build mayhem fuzzing container' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Log in to the Container registry + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + with: + context: . + file: mayhem/Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + outputs: + image: ${{ steps.meta.outputs.tags }} + + mayhem: + needs: build + name: 'fuzz ${{ matrix.mayhemfile }}' + runs-on: ubuntu-latest + strategy: + matrix: + mayhemfile: + - mayhem/hosts.mayhemfile + + steps: + - uses: actions/checkout@v2 + + - name: Start analysis for ${{ matrix.mayhemfile }} + uses: ForAllSecure/mcode-action@v1 + with: + mayhem-token: ${{ secrets.MAYHEM_TOKEN }} + args: --image ${{ needs.build.outputs.image }} --file ${{ matrix.mayhemfile }} --duration 300 + sarif-output: sarif diff --git a/mayhem/.dockerignore b/mayhem/.dockerignore new file mode 100644 index 0000000..078639e --- /dev/null +++ b/mayhem/.dockerignore @@ -0,0 +1,3 @@ +/target +.git +mayhem/Dockerfile diff --git a/mayhem/Dockerfile b/mayhem/Dockerfile new file mode 100644 index 0000000..83a8420 --- /dev/null +++ b/mayhem/Dockerfile @@ -0,0 +1,22 @@ +# Build Stage +FROM ghcr.io/evanrichter/cargo-fuzz:latest as builder + +## Add source code to the build stage. +ADD . /src +WORKDIR /src + +RUN echo building instrumented harnesses && \ + bash -c "pushd fuzz && cargo +nightly -Z sparse-registry fuzz build && popd" && \ + mv fuzz/target/x86_64-unknown-linux-gnu/release/hosts /hosts && \ + echo done + +RUN echo building non-instrumented harnesses && \ + export RUSTFLAGS="--cfg fuzzing -Clink-dead-code -Cdebug-assertions -C codegen-units=1" && \ + bash -c "pushd fuzz && cargo +nightly -Z sparse-registry build --release && popd" && \ + mv fuzz/target/release/hosts /hosts_no_inst && \ + echo done + +# Package Stage +FROM rustlang/rust:nightly + +COPY --from=builder /hosts /hosts_no_inst / diff --git a/mayhem/hosts.mayhemfile b/mayhem/hosts.mayhemfile new file mode 100644 index 0000000..a83ebe9 --- /dev/null +++ b/mayhem/hosts.mayhemfile @@ -0,0 +1,7 @@ +project: zeronsd +target: hosts + +cmds: + - cmd: /hosts + - cmd: /hosts_no_inst @@ + libfuzzer: false