From 3b0522299a073a9a77c8e31213505dad4d7eec2c Mon Sep 17 00:00:00 2001 From: Jade Lovelace Date: Mon, 16 Jan 2023 22:28:14 -0800 Subject: [PATCH 1/2] aflplusplus: 2.64c -> 4.05c Co-authored-by: Mindavi aflplusplus: fix tests, fix clang path substitution aflplusplus: fix some small issues and detect invalid use of LLVM_BINDIR better aflplusplus: add llvmPackages bintools as buildInput Now aflplusplus can auto-detect it. aflplusplus: make qemu test work aflplusplus: disable fortify hardening, package does this itself Prevents warnings from being logged. aflplusplus: use better separators for sed aflplusplus: remove broken path check aflplusplus: python -> python3, define llvmPackages outside of pkg def aflplusplus: fix invalid qemu test path --- pkgs/tools/security/aflplusplus/default.nix | 90 +++++++--- .../security/aflplusplus/libdislocator.nix | 5 +- .../security/aflplusplus/libtokencap.nix | 4 +- pkgs/tools/security/aflplusplus/qemu.nix | 169 ++++++++++++------ pkgs/top-level/all-packages.nix | 6 +- 5 files changed, 187 insertions(+), 87 deletions(-) diff --git a/pkgs/tools/security/aflplusplus/default.nix b/pkgs/tools/security/aflplusplus/default.nix index 11b276ca05d2..08db2e37812b 100644 --- a/pkgs/tools/security/aflplusplus/default.nix +++ b/pkgs/tools/security/aflplusplus/default.nix @@ -1,6 +1,8 @@ { lib, stdenv, stdenvNoCC, fetchFromGitHub, callPackage, makeWrapper -, clang, llvm, gcc, which, libcgroup, python, perl, gmp +, clang, llvm, gcc, which, libcgroup, python3, perl, gmp , file, wine ? null, fetchpatch +, cmocka +, llvmPackages }: # wine fuzzing is only known to work for win32 binaries, and using a mixture of @@ -17,38 +19,51 @@ let libtokencap = callPackage ./libtokencap.nix { inherit aflplusplus; }; aflplusplus = stdenvNoCC.mkDerivation rec { pname = "aflplusplus"; - version = "2.65c"; + version = "4.05c"; src = fetchFromGitHub { owner = "AFLplusplus"; repo = "AFLplusplus"; rev = version; - sha256 = "1np2a3kypb2m8nyv6qnij18yzn41pl8619jzydci40br4vxial9l"; + sha256 = "sha256-c4GFOuCwIOFkwIxXtwE3VTVlWW7lS8h+GMN70fZbgDI="; }; enableParallelBuilding = true; # Note: libcgroup isn't needed for building, just for the afl-cgroup # script. nativeBuildInputs = [ makeWrapper which clang gcc ]; - buildInputs = [ llvm python gmp ] - ++ lib.optional (wine != null) python.pkgs.wrapPython; + buildInputs = [ llvm python3 gmp llvmPackages.bintools ] + ++ lib.optional (wine != null) python3.pkgs.wrapPython; + # Flag is already set by package and causes some compiler warnings. + # warning: "_FORTIFY_SOURCE" redefined + hardeningDisable = [ "fortify" ]; postPatch = '' - # Replace the CLANG_BIN variables with the correct path - substituteInPlace llvm_mode/afl-clang-fast.c \ + # Don't care about this. + rm Android.bp + + # Replace the CLANG_BIN variables with the correct path. + # Replace "gcc" and friends with full paths in afl-gcc. + # Prevents afl-gcc picking up any (possibly incorrect) gcc from the path. + # Replace LLVM_BINDIR with a non-existing path to give a hard error when it's used. + substituteInPlace src/afl-cc.c \ --replace "CLANGPP_BIN" '"${clang}/bin/clang++"' \ --replace "CLANG_BIN" '"${clang}/bin/clang"' \ - --replace 'getenv("AFL_PATH")' "(getenv(\"AFL_PATH\") ? getenv(\"AFL_PATH\") : \"$out/lib/afl\")" - - # Replace "gcc" and friends with full paths in afl-gcc - # Prevents afl-gcc picking up any (possibly incorrect) gcc from the path - substituteInPlace src/afl-gcc.c \ --replace '"gcc"' '"${gcc}/bin/gcc"' \ --replace '"g++"' '"${gcc}/bin/g++"' \ - --replace '"gcj"' '"gcj-UNSUPPORTED"' \ - --replace '"clang"' '"clang-UNSUPPORTED"' \ - --replace '"clang++"' '"clang++-UNSUPPORTED"' + --replace 'getenv("AFL_PATH")' "(getenv(\"AFL_PATH\") ? getenv(\"AFL_PATH\") : \"$out/lib/afl\")" + + substituteInPlace src/afl-ld-lto.c \ + --replace 'LLVM_BINDIR' '"/nixpkgs-patched-does-not-exist"' + + # Remove the rest of the line + sed -i 's|LLVM_BINDIR = .*|LLVM_BINDIR = |' utils/aflpp_driver/GNUmakefile + substituteInPlace utils/aflpp_driver/GNUmakefile \ + --replace 'LLVM_BINDIR = ' 'LLVM_BINDIR = ${clang}/bin/' + + substituteInPlace GNUmakefile.llvm \ + --replace "\$(LLVM_BINDIR)/clang" "${clang}/bin/clang" ''; env.NIX_CFLAGS_COMPILE = toString [ @@ -56,15 +71,19 @@ let "-Wno-error=use-after-free" ]; - makeFlags = [ "PREFIX=$(out)" ]; + makeFlags = [ + "PREFIX=$(out)" + "USE_BINDIR=0" + ]; buildPhase = '' + runHook preBuild + common="$makeFlags -j$NIX_BUILD_CORES" - make all $common - make radamsa $common - make -C gcc_plugin CC=${gcc}/bin/gcc CXX=${gcc}/bin/g++ $common - make -C llvm_mode $common + make distrib $common make -C qemu_mode/libcompcov $common make -C qemu_mode/unsigaction $common + + runHook postBuild ''; postInstall = '' @@ -75,7 +94,7 @@ let cp qemu_mode/unsigaction/unsigaction*.so $out/lib/afl/ # Install the custom QEMU emulator for binary blob fuzzing. - cp ${aflplusplus-qemu}/bin/${qemu-exe-name} $out/bin/afl-qemu-trace + ln -s ${aflplusplus-qemu}/bin/${qemu-exe-name} $out/bin/afl-qemu-trace # give user a convenient way of accessing libcompconv.so, libdislocator.so, libtokencap.so cat > $out/bin/get-afl-qemu-libcompcov-so < $out/bin/get-libdislocator-so < all.patch - ''; + src = fetchFromGitHub { + owner = "AFLplusplus"; + repo = "qemuafl"; + rev = "a8af9cbde71e333ce72a46f15e655d0b82ed0939"; + sha256 = "sha256-veT9Vne9arB1kbQDAKGZ/skse5C5KNAiMBj2JWkS4tQ="; + fetchSubmodules = true; + }; nativeBuildInputs = [ - python3 perl pkg-config flex bison autoconf texinfo + python3 + perl + pkg-config + flex + bison + meson + texinfo + ninja ]; buildInputs = [ - zlib glib pixman libuuid + zlib + glib + pixman + libuuid ]; enableParallelBuilding = true; - patches = [ - # patches extracted from aflplusplus source - "../all.patch" - # nix-specific patches to make installation more well-behaved - ./qemu-no-etc-install.patch - ]; + dontUseMesonConfigure = true; # meson's configurePhase isn't compatible with qemu build + preBuild = "cd build"; + preConfigure = '' + # this script isn't marked as executable b/c it's indirectly used by meson. Needed to patch its shebang + chmod +x ./scripts/shaderinclude.pl + patchShebangs . + ''; configureFlags = - [ "--disable-system" - "--enable-linux-user" - "--disable-gtk" - "--disable-sdl" - "--disable-vnc" - "--disable-kvm" - "--target-list=${cpuTarget}" - "--enable-pie" + [ + "--target-list=${stdenv.hostPlatform.uname.processor}-linux-user" "--sysconfdir=/etc" "--localstatedir=/var" + "--meson=meson" + "--disable-system" + "--enable-linux-user" + "--enable-pie" + "--audio-drv-list=" + "--disable-blobs" + "--disable-bochs" + "--disable-brlapi" + "--disable-bsd-user" + "--disable-bzip2" + "--disable-cap-ng" + "--disable-cloop" + "--disable-curl" + "--disable-curses" + "--disable-dmg" + "--disable-fdt" + "--disable-gcrypt" + "--disable-glusterfs" + "--disable-gnutls" + "--disable-gtk" + "--disable-guest-agent" + "--disable-iconv" + "--disable-libiscsi" + "--disable-libnfs" + "--disable-libssh" + "--disable-libusb" + "--disable-linux-aio" + "--disable-live-block-migration" + "--disable-lzo" + "--disable-nettle" + "--disable-numa" + "--disable-opengl" + "--disable-parallels" + "--disable-plugins" + "--disable-qcow1" + "--disable-qed" + "--disable-rbd" + "--disable-rdma" + "--disable-replication" + "--disable-sdl" + "--disable-seccomp" + "--disable-sheepdog" + "--disable-smartcard" + "--disable-snappy" + "--disable-spice" + "--disable-system" + "--disable-tools" + "--disable-tpm" + "--disable-usb-redir" + "--disable-vde" + "--disable-vdi" + "--disable-vhost-crypto" + "--disable-vhost-kernel" + "--disable-vhost-net" + "--disable-vhost-scsi" + "--disable-vhost-user" + "--disable-vhost-vdpa" + "--disable-vhost-vsock" + "--disable-virglrenderer" + "--disable-virtfs" + "--disable-vnc" + "--disable-vnc-jpeg" + "--disable-vnc-png" + "--disable-vnc-sasl" + "--disable-vte" + "--disable-vvfat" + "--disable-xen" + "--disable-xen-pci-passthrough" + "--disable-xfsctl" + "--without-default-devices" ]; meta = with lib; { - homepage = "https://www.qemu.org/"; + homepage = "https://github.com/AFLplusplus/qemuafl"; description = "Fork of QEMU with AFL++ instrumentation support"; license = licenses.gpl2Plus; maintainers = with maintainers; [ ris ]; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 1dd37af855d5..c9d1df3e63d4 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -1394,9 +1394,9 @@ with pkgs; }; aflplusplus = callPackage ../tools/security/aflplusplus { - clang = clang_9; - llvm = llvm_9; - python = python3; + clang = clang_14; + llvm = llvm_14; + llvmPackages = llvmPackages_14; wine = null; }; From 24f8a54893c76b87d0de4eb16e6c95aae151aa63 Mon Sep 17 00:00:00 2001 From: Rick van Schijndel Date: Tue, 6 Jun 2023 22:56:19 +0200 Subject: [PATCH 2/2] aflplusplus: 4.05c -> 4.06c Changelog: https://github.com/AFLplusplus/AFLplusplus/releases/tag/4.06c Also update to llvm 15, and update the qemu that's used for aflplusplus. --- pkgs/tools/security/aflplusplus/default.nix | 4 ++-- pkgs/tools/security/aflplusplus/qemu.nix | 4 ++-- pkgs/top-level/all-packages.nix | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkgs/tools/security/aflplusplus/default.nix b/pkgs/tools/security/aflplusplus/default.nix index 08db2e37812b..6102eb0b3f39 100644 --- a/pkgs/tools/security/aflplusplus/default.nix +++ b/pkgs/tools/security/aflplusplus/default.nix @@ -19,13 +19,13 @@ let libtokencap = callPackage ./libtokencap.nix { inherit aflplusplus; }; aflplusplus = stdenvNoCC.mkDerivation rec { pname = "aflplusplus"; - version = "4.05c"; + version = "4.06c"; src = fetchFromGitHub { owner = "AFLplusplus"; repo = "AFLplusplus"; rev = version; - sha256 = "sha256-c4GFOuCwIOFkwIxXtwE3VTVlWW7lS8h+GMN70fZbgDI="; + sha256 = "sha256-Gb1nYDBnwLS+m8e1UD0WLIrnp8KRgliGQVvQD22JXrQ="; }; enableParallelBuilding = true; diff --git a/pkgs/tools/security/aflplusplus/qemu.nix b/pkgs/tools/security/aflplusplus/qemu.nix index 107db2d75bc3..6be5afb54dc3 100644 --- a/pkgs/tools/security/aflplusplus/qemu.nix +++ b/pkgs/tools/security/aflplusplus/qemu.nix @@ -30,8 +30,8 @@ stdenv.mkDerivation { src = fetchFromGitHub { owner = "AFLplusplus"; repo = "qemuafl"; - rev = "a8af9cbde71e333ce72a46f15e655d0b82ed0939"; - sha256 = "sha256-veT9Vne9arB1kbQDAKGZ/skse5C5KNAiMBj2JWkS4tQ="; + rev = "0569eff8a12dec73642b96757f6b5b51a618a03a"; + sha256 = "sha256-nYWHyRfOH2p9znRxjxsiyw11uZuMBiuJfEc7FHM5X7M="; fetchSubmodules = true; }; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index c9d1df3e63d4..ecaf207cb4d2 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -1394,9 +1394,9 @@ with pkgs; }; aflplusplus = callPackage ../tools/security/aflplusplus { - clang = clang_14; - llvm = llvm_14; - llvmPackages = llvmPackages_14; + clang = clang_15; + llvm = llvm_15; + llvmPackages = llvmPackages_15; wine = null; };