From fe1c7a34b797e2ff0c6b93bd66224ea87873d57c Mon Sep 17 00:00:00 2001 From: Stefan Zabka Date: Tue, 12 Mar 2024 01:00:35 +0100 Subject: [PATCH] Dockerfile: setup for building libafl_qemu in Docker (#1899) * fix(Dockerfile): add build_linux.rs to libafl_qemu and libafl_qemu_sys * fix(Dockerfile): workaround for llvm.sh failing on bookworm Revert this once https://github.com/llvm/llvm-project/issues/62475 has been resolved * fix(libafl_qemu): add unsafe to callbacks * chore(devcontainer): update devcontainer to work with newer VSCode versions * revert(libafl_qemu): revert unsafe keyword * fix(devcontainer): move settings and extension under customizations.vscode * fix(devcontainer): use postCreateCommand instead of initializeCommand --- .devcontainer/devcontainer.json | 21 +++++++++++++-------- Dockerfile | 16 +++++++++++----- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index e9e1e3a2f7..b507d1c9e9 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -6,22 +6,27 @@ "context": "..", // Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename. "dockerFile": "../Dockerfile", - // Set *default* container specific settings.json values on container create. - "settings": {}, - // Add the IDs of extensions you want installed when the container is created. - "extensions": [ - "matklad.rust-analyzer" - ], + "customizations": { + "vscode": { + // Add the IDs of extensions you want installed when the container is created. + "extensions": ["matklad.rust-analyzer", "microsoft.Docker"], + // Set *default* container specific settings.json values on container create. + "settings": { + "rust-analyzer.cargo.noDefaultFeatures": true + } + } + }, // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], // Uncomment the next line to run commands after the container is created - for example installing curl. - // "postCreateCommand": "apt-get update && apt-get install -y curl", + // Install development components that shouldn't be in the main Dockerfile + "postCreateCommand": "rustup component add --toolchain nightly rustfmt clippy llvm-tools-preview && cargo install --locked cargo-make", // Uncomment when using a ptrace-based debugger like C++, Go, and Rust "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" - ], + ] // Uncomment to use the Docker CLI from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker. // "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ], // Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root. diff --git a/Dockerfile b/Dockerfile index c6ee0219ce..865cdd0327 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,9 +19,15 @@ RUN sh -c 'echo set encoding=utf-8 > /root/.vimrc' \ RUN rustup component add rustfmt clippy RUN rustup default nightly -# Install clang 11, common build tools -RUN apt update && apt install -y build-essential gdb git wget python3-venv ninja-build lsb-release software-properties-common gnupg -RUN wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && ./llvm.sh 15 +# Install clang 18, common build tools +ENV LLVM_VERSION=18 +RUN apt update && apt install -y build-essential gdb git wget python3-venv ninja-build lsb-release software-properties-common gnupg cmake +# Workaround until https://github.com/llvm/llvm-project/issues/62475 is resolved +RUN set -ex &&\ + echo "deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-${LLVM_VERSION} main" > /etc/apt/sources.list.d/apt.llvm.org.list &&\ + wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc &&\ + apt update &&\ + apt-get install -y clang-${LLVM_VERSION} lldb-${LLVM_VERSION} lld-${LLVM_VERSION} clangd-${LLVM_VERSION} clang-tidy-${LLVM_VERSION} clang-format-${LLVM_VERSION} clang-tools-${LLVM_VERSION} llvm-${LLVM_VERSION}-dev lld-${LLVM_VERSION} lldb-${LLVM_VERSION} llvm-${LLVM_VERSION}-tools libomp-${LLVM_VERSION}-dev libc++-${LLVM_VERSION}-dev libc++abi-${LLVM_VERSION}-dev libclang-common-${LLVM_VERSION}-dev libclang-${LLVM_VERSION}-dev libclang-cpp${LLVM_VERSION}-dev libunwind-${LLVM_VERSION}-dev libclang-rt-${LLVM_VERSION}-dev libpolly-${LLVM_VERSION}-dev # Copy a dummy.rs and Cargo.toml first, so that dependencies are cached WORKDIR /libafl @@ -41,13 +47,13 @@ COPY libafl_frida/Cargo.toml libafl_frida/build.rs libafl_frida/ COPY scripts/dummy.rs libafl_frida/src/lib.rs COPY libafl_frida/src/gettls.c libafl_frida/src/gettls.c -COPY libafl_qemu/Cargo.toml libafl_qemu/build.rs libafl_qemu/ +COPY libafl_qemu/Cargo.toml libafl_qemu/build.rs libafl_qemu/build_linux.rs libafl_qemu/ COPY scripts/dummy.rs libafl_qemu/src/lib.rs COPY libafl_qemu/libafl_qemu_build/Cargo.toml libafl_qemu/libafl_qemu_build/ COPY scripts/dummy.rs libafl_qemu/libafl_qemu_build/src/lib.rs -COPY libafl_qemu/libafl_qemu_sys/Cargo.toml libafl_qemu/libafl_qemu_sys/build.rs libafl_qemu/libafl_qemu_sys/ +COPY libafl_qemu/libafl_qemu_sys/Cargo.toml libafl_qemu/libafl_qemu_sys/build.rs libafl_qemu/libafl_qemu_sys/build_linux.rs libafl_qemu/libafl_qemu_sys/ COPY scripts/dummy.rs libafl_qemu/libafl_qemu_sys/src/lib.rs COPY libafl_sugar/Cargo.toml libafl_sugar/