Skip to content

fuzz with AFL++ - #87

Draft
yuval-block wants to merge 6 commits into
fuzz-targetsfrom
fuzz-afl
Draft

yuval-block wants to merge 6 commits into
fuzz-targetsfrom
fuzz-afl

Conversation

@yuval-block

@yuval-block yuval-block commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Adds a cargo-afl frontend over the shared targets and runs it through nix:

nix run .#fuzz-afl -- afl_lattice_laws -V 600

The AFL++ runtime, afl-fuzz and the targets are built in derivations and
the app only runs them against a corpus in the checkout.

There is a binary per target, afl_lattice_laws and afl_scrub, and the
workflow fuzzes each in a job of its own.

Fuzzing is randomized, so it runs from a daily workflow rather than as a
flake check. That workflow first runs fuzz-afl-verify, which confirms
AFL++ finds the crash_test panic.

🤖 Generated with Claude Code

@yuval-block yuval-block mentioned this pull request Nov 12, 2026
@github-code-quality

github-code-quality Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

fuzz-targets 227c7b5 fuzz-afl b7a40f4 +/-
100% 100% 0%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 13, 2026 06:48 UTC

@github-actions

Copy link
Copy Markdown
range-diff for force push 1996cadd6e → 897673259c November 13, 2026 03:21 UTC: 2 unchanged, 1 dropped, 3 added; 3 → 5 commits; same base 3e7c10e5fa

reproduce: git range-diff 3e7c10e..1996cad 3e7c10e..8976732

1:  72dbc3519a +353  -0 5f = 1:  72dbc3519a +353  -0 5f fuzz: AFL++ frontend via cargo-afl
2:  7936acd7c8 +157  -0 1f = 2:  7936acd7c8 +157  -0 1f nix: fuzz with AFL++
3:  1996cadd6e   +0  -0 0f < -:  ----------             fuzz with AFL++
-:  ----------             > 3:  341796ad9c  +32 -24 1f nix: verify AFL++ from an app, not a check
-:  ----------             > 4:  7ef1f7b075  +44  -0 1f ci: fuzz with AFL++ on a schedule
-:  ----------             > 5:  897673259c   +0  -0 0f fuzz with AFL++

nothingmuch and others added 6 commits November 13, 2026 06:50
AFL++ is a mutation engine with its own scheduling and its own take on
coverage, so it finds inputs the others do not. The targets wrap the
shared library, in a workspace of their own.

    cd fuzz/afl && cargo afl build && cargo afl fuzz -i in -o out target/debug/afl_lattice_laws

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Package cargo-afl, which nixpkgs lacks. Build the AFL++ runtime and
afl-fuzz with it in one derivation, and the AFL++ targets against that
runtime in another, then add an app that runs a target with afl-fuzz
against a corpus in the checkout:

    nix run .#fuzz-afl -- afl_lattice_laws -V 600

Only the corpus and afl-fuzz's output live outside the store, so a run
does not depend on whatever compiler and libraries the calling shell has.

cargo-afl builds the runtime from AFL++ sources bundled in
cargo-afl-common, which it finds by that crate's build-time
CARGO_MANIFEST_DIR, a path that is gone once cargo-afl is built. The
runtime derivation seeds cargo-afl's build directory with those sources
from the crate itself instead. An empty .git there makes cargo-afl skip
its own copy, so it does not need patching.

The check, in the nightly aggregate, builds the targets with crash_test's
panic compiled in and confirms AFL++ finds it within a minute, which it
only does with working coverage feedback. AFL_BENCH_UNTIL_CRASH stops
afl-fuzz at the first crash rather than waiting out the minute.

On macOS, afl-fuzz needs more System V shared memory than the defaults
allow, and raising them takes root, so AFL++ is built against POSIX
shared memory there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Whether AFL++ solves crash_test within its time limit depends on its
random choices, so fuzz-afl-verify could pass or fail with no change to
its inputs. A check that flakes like that blames whichever commit happens
to be built, and a hard-to-find regression would point at the wrong one.

Run it as an app instead, so CI can run it on a schedule:

    nix run .#fuzz-afl-verify

The time limit goes from 60s to 600s, since an app is not bounded by a
check's budget, and afl-fuzz arguments after -- override it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Once a day, confirm AFL++ still finds the planted crash_test panic, then
fuzz the lattice laws for half an hour. afl-fuzz exits cleanly even when
it finds crashes, so a separate step fails the run if any were saved, and
uploads them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add an afl_scrub bin for the shared scrub target, and fuzz it on the
schedule too. The workflow runs each target as its own matrix job, so a
crash in one does not stop the other.

With two targets, the app gives each its own output directory under
fuzz/afl/out: afl-fuzz keeps its queue and crashes there, and a run of
one target must not pick up another's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds a cargo-afl frontend over the shared targets and runs it through nix:

    nix run .#fuzz-afl -- afl_lattice_laws -V 600

The AFL++ runtime, afl-fuzz and the targets are built in derivations and
the app only runs them against a corpus in the checkout.

Fuzzing is randomized, so it runs from a daily workflow rather than as a
flake check. That workflow first runs fuzz-afl-verify, which confirms
AFL++ finds the crash_test panic.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
range-diff for force push 897673259c → b7a40f47a5 November 13, 2026 06:29 UTC: 5 unchanged, 1 added; 5 → 6 commits; base 3e7c10e5fa → f23a1484f3 (diverged, 2 ahead and 1 behind)

reproduce: git range-diff 3e7c10e..8976732 f23a148..b7a40f4

1:  72dbc3519a +353  -0 5f = 1:  706963e1e5 +353  -0 5f fuzz: AFL++ frontend via cargo-afl
2:  7936acd7c8 +157  -0 1f = 2:  e7011674b1 +157  -0 1f nix: fuzz with AFL++
3:  341796ad9c  +32 -24 1f = 3:  9700342d3b  +32 -24 1f nix: verify AFL++ from an app, not a check
4:  7ef1f7b075  +44  -0 1f = 4:  5d0b4b6e1e  +44  -0 1f ci: fuzz with AFL++ on a schedule
-:  ----------             > 5:  f9963def1f  +29  -8 4f fuzz: scrub with AFL++
5:  897673259c   +0  -0 0f = 6:  b7a40f47a5   +0  -0 0f fuzz with AFL++

1 similar comment
@github-actions

Copy link
Copy Markdown
range-diff for force push 897673259c → b7a40f47a5 November 13, 2026 06:29 UTC: 5 unchanged, 1 added; 5 → 6 commits; base 3e7c10e5fa → f23a1484f3 (diverged, 2 ahead and 1 behind)

reproduce: git range-diff 3e7c10e..8976732 f23a148..b7a40f4

1:  72dbc3519a +353  -0 5f = 1:  706963e1e5 +353  -0 5f fuzz: AFL++ frontend via cargo-afl
2:  7936acd7c8 +157  -0 1f = 2:  e7011674b1 +157  -0 1f nix: fuzz with AFL++
3:  341796ad9c  +32 -24 1f = 3:  9700342d3b  +32 -24 1f nix: verify AFL++ from an app, not a check
4:  7ef1f7b075  +44  -0 1f = 4:  5d0b4b6e1e  +44  -0 1f ci: fuzz with AFL++ on a schedule
-:  ----------             > 5:  f9963def1f  +29  -8 4f fuzz: scrub with AFL++
5:  897673259c   +0  -0 0f = 6:  b7a40f47a5   +0  -0 0f fuzz with AFL++

Comment thread nix/fuzz/afl.nix
type = "app";
meta.description = "Run an AFL++ target: nix run .#fuzz-afl -- <target> [afl-fuzz args]";
program = lib.getExe (
pkgs.writeShellApplication {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fuzz-afl app needs mkdir and ls from caller

writeShellApplication sets no runtimeInputs, so the wrapper's mkdir and ls (lines 116-117) resolve from the caller's PATH; with PATH=/nonexistent it exits 127 before starting afl-fuzz.

oak · automated · b7a40f4

Comment thread nix/fuzz/afl.nix
printf seed >"$scratch/in/seed"
# afl-fuzz's exit status says nothing useful here; what it left
# in its output directory does.
${lib.getExe aflplusplus} -i "$scratch/in" -o "$scratch/out" -V 600 "$@" -- ${verifyTargets}/bin/afl_crash_test || true

@bc1cindy bc1cindy Nov 14, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't find crash_test within this 600 s budget on x86_64 Linux at b7a40f4 (libFuzzer and honggfuzz take seconds), and 1 h of afl_scrub (82M execs) saves 0 crashes while the other two hit the #84 check within a minute

the 600 s miss is this host, not the search: core_pattern pipes to apport here, so a crash takes ~1.1 s and AFL++'s 20 ms timeout files it as a timeout (verify saved 5), and AFL_I_DONT_CARE_ABOUT_MISSING_CRASHES hides AFL++'s warning about that. with -t 3000 verify finds crash_test in 10 s. afl_scrub still saves 0 crashes and 0 timeouts with -t 3000 (2 min), so there it does look like the search

afl_lattice_laws: 162M execs, nothing

AFL++ commands
nix run .#fuzz-afl-verify
nix run .#fuzz-afl-verify -- -t 3000
nix run .#fuzz-afl -- afl_scrub -V 3600
nix run .#fuzz-afl -- afl_lattice_laws -V 3600

Comment thread nix/fuzz/afl.nix
# afl-fuzz's exit status says nothing useful here; what it left
# in its output directory does.
${lib.getExe aflplusplus} -i "$scratch/in" -o "$scratch/out" -V 600 "$@" -- ${verifyTargets}/bin/afl_crash_test || true
crashes=("$scratch"/out/default/crashes/id:*)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Distributed AFL args cause false 'no crash'

The app advertises [afl-fuzz args], but -S/-M make AFL++ save crashes under out/<instance>/crashes while the script checks only out/default; it then prints AFL++ did not find the crash and exits non-zero despite a saved crash.

oak · automated · b7a40f4

Comment thread nix/fuzz/afl.nix
inherit pnameSuffix RUSTFLAGS;
nativeBuildInputs = [ cargo-afl ];
XDG_DATA_HOME = "${aflplusplus}/share";
buildPhaseCargoCommand = "cargo afl build --release --bins";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fuzz targets are built for the host CPU

cargo afl build appends -C target-cpu=native, so the fuzz targets are compiled for the builder's CPU and the derivation output depends on the machine that built it.

oak · automated · b7a40f4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants