Skip to content

test: fuzz the daemon's trust boundary with cargo-fuzz and ClusterFuzzLite - #707

Merged
vladimirrott merged 8 commits into
mainfrom
test/fuzzing
Oct 29, 2026
Merged

vladimirrott merged 8 commits into
mainfrom
test/fuzzing

Conversation

@vladimirrott

Copy link
Copy Markdown
Member

Adds cargo-fuzz targets for the daemon's trust boundary and runs them on pull requests with ClusterFuzzLite. OpenSSF Scorecard's Fuzzing check scores 0 today; it detects ClusterFuzzLite and libfuzzer_sys, and this tree carries both.

Targets (fuzz/)

Target What it asserts 45-60 s on this head
validators every validated_* result has no control character, no leading - where it would read as an option, and stays inside its length bound and character set 836,930 runs, no crash
action_spec build_action_spec over arbitrary JSON never panics, a command names a program, and no argument contains NUL 786,275 runs, no crash
daemon_request decoding a DaemonRequest from arbitrary bytes never panics 613,014 runs, no crash
frame_recv the frame reader agrees with an independent reading of the length prefix 275,127 runs, no crash

The seeds come from the existing unit tests. The NUL assertion is not decorative: built against v0.27.0, action_spec fails within seconds with SetKernelArguments: NUL in argument "--append=nom\0", the gap that GHSA-76v3-hw9r-58pm item 3 describes and 0.28.0 fixed.

The daemon exposes its private pieces to the fuzz crate only under #[cfg(fuzzing)], so neither a normal build nor the public API changes. fuzz/ has its own workspace and lockfile, so the root Cargo.lock is untouched.

CI

.clusterfuzzlite/ builds the targets and .github/workflows/cflite_pr.yml runs them for five minutes on pull requests that touch crates/ or the fuzz setup: actions pinned by SHA, contents: read, a 45-minute limit. scripts/shellcheck-files.sh and e2e.yml now cover .clusterfuzzlite/build.sh. The image build was proven locally; the run_fuzzers step only exists on GitHub, so this PR is its first run.

docs/contributing/fuzzing.md covers running a target and adding one.

My host cannot link sysknife-shell, so the commits went in with hooks off. I ran the hook's steps by hand.

🤖 Generated with Claude Code

vladimirrott and others added 5 commits October 28, 2026 19:51
The fuzz crate has to call the `validated_*` functions, which sit in a
`pub(crate)` module, and the request decode, whose `DaemonRequest` enum is
private to the dispatcher. A `pub mod fuzzing` re-exports the validators, and
`fuzz_decode_request` repeats the connection loop's two-step decode
(`from_slice` into a `Value`, then `from_value` into the enum).

Both exist only under `#[cfg(fuzzing)]`, which cargo-fuzz sets for its builds.
A normal or release build does not contain them, so the daemon's public API
does not grow and no Cargo feature is added. The crate's lint table declares
the cfg so `unexpected_cfgs` stays quiet under `-D warnings`.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UpyrhbDTW1gBwzGAC44GYU
`fuzz/` is a cargo-fuzz crate with four targets:

- `validators`: every `validated_*` function in `actions/validate.rs`, picked
  by the first input byte. A validator must not panic, and whatever it accepts
  must satisfy its contract: no control character, no leading `-` where the
  value would land in option position, the documented length bound and
  character set, and the shape its doc comment promises.
- `action_spec`: `build_action_spec(name, &params)` over arbitrary JSON.
- `daemon_request`: the request decode the connection loop performs.
- `frame_recv`: `FramedStream::recv`, checked against an independent reading
  of the length-prefix wire format.

Seed corpora come from the existing unit-test cases (`validate.rs` string
literals, `build_action_spec` calls, request frames, the framing tests), and
each target with keywords has a libFuzzer dictionary.

The crate is its own workspace, so the repository's `Cargo.toml` and
`Cargo.lock` do not change and `--workspace` builds never compile libFuzzer's
C++ runtime. `fuzz/Cargo.lock` pins its dependencies.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UpyrhbDTW1gBwzGAC44GYU
`.clusterfuzzlite/` (Dockerfile, build.sh, project.yaml, language: rust) builds
the cargo-fuzz targets, and `cflite_pr.yml` runs them for 300 seconds on pull
requests that touch `crates/`, `fuzz/` or the fuzz setup. Both actions are
pinned by full SHA with a `# v1` comment (google/clusterfuzzlite publishes only
that moving tag), the workflow holds `contents: read` and nothing else, and the
job has a 45 minute timeout. The Dockerfile base image is pinned by digest, as
the root Dockerfile is. The base image's nightly (rustc 1.91) is older than
sqlx 0.9 accepts (rustc 1.94), so the Dockerfile installs a dated nightly and
selects it; the build failed on the stock toolchain before that.

The Dockerfile copies the whole build context, which is the repository root, so
`.dockerignore` now lets `fuzz/` and `.clusterfuzzlite/` through. The root
Dockerfile copies named paths only and does not see the change.

`build.sh` is a tracked shell script, so `.clusterfuzzlite` joins the ShellCheck
roots and the e2e workflow's path triggers, which is what
`tests/release/shellcheck-coverage.test.sh` requires.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UpyrhbDTW1gBwzGAC44GYU
`docs/contributing/fuzzing.md` covers what each target checks, how to run one
on your machine (corpus directories, dictionaries, the ASan setting that avoids
a false `odr-violation` in the bundled SQLite), how to replay a crash, how the
crate, the `#[cfg(fuzzing)]` hooks and the pinned nightly are wired, and how to
add a validator or a target. `testing.md` links to it from the test pyramid and a short section, and
the CHANGELOG gets an Unreleased entry.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UpyrhbDTW1gBwzGAC44GYU
Comment thread fuzz/fuzz_targets/action_spec.rs Dismissed
vladimirrott and others added 3 commits October 28, 2026 20:20
fuzz/ is its own workspace and builds against sysknife-daemon,
sysknife-types, sysknife-core and sysknife-proto by path, so its
lockfile records their versions. The 0.28.0 bump left it at 0.27.0 and
ClusterFuzzLite's `--locked` build refused, and version-sites flagged
fuzz/Cargo.toml as an unregistered manifest.

release-versions.json gains dependent_lockfiles: bump_version.sh
refreshes each through `cargo metadata --manifest-path`, and the check
requires every release crate such a lockfile holds to be at the release
version (it need not hold all of them, unlike Cargo.lock). fuzz/Cargo.toml
is listed in not_a_version_site: it is never published.

release-version-bump.test.sh now requires a bump to move the fuzz lock
and the check to name a stale one. Skipping the fuzz lock in the bump,
or in the check, turns it red. fuzz/Cargo.lock is refreshed by cargo to
0.28.0; only the four sysknife crates moved.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
mdbook-links found testing.md pointing at a page the book did not build,
then fuzzing.md pointing outside the book's source tree.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vladimirrott
vladimirrott merged commit fabc203 into main Oct 29, 2026
14 checks passed
@vladimirrott
vladimirrott deleted the test/fuzzing branch October 29, 2026 02:55
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.

2 participants