Repository navigation
test(fuzz): fuzz the command channel's length-delimited framing - #1420
Conversation
command/src/channel.rs carries the control-plane's length-delimited wire format and has four historical framing defects (5af7dae, 7b8dce9, 2c6832b, 7299c28) but no fuzz target, unlike its two direct analogues (fuzz_frame_parser, fuzz_hpack_decoder). Add fuzz_command_channel, driving Channel::try_read_delimited_message and write_delimited_message through their public, purely in-memory entry points (front_buf/back_buf only, the MioUnixStream pair generate_nonblocking requires is never read or written) against truncated frames, an under-delimiter/zero/oversize/usize::MAX declared length, frames split across arbitrary chunk boundaries, and valid frames followed by garbage. Asserts structural properties beyond "no crash": a read_message() call never increases pending data; a successful decode consumes exactly the declared frame length (peeked independently, so this half is partly tautological against a defect shared with the peek's own primitives, noted in the target's doc comment); MessageLengthUnderDelimiter always drops exactly delimiter_size() bytes to resync; MessageTooLarge never consumes bytes or grows the buffer before rejecting; a global byte-conservation invariant (available_data == total_fed - total_consumed), counted independently by the harness rather than read back from the code under test, holds at every step; and a write/read round trip decodes back to the same id. Reintroducing 5af7dae's missing short-frame rejection reproduces a panic in under a second (run #295, 6-byte minimized input) at the debug_assert channel.rs:589 -- cargo-fuzz always builds with -Cdebug-assertions, so that is the panic site the target actually hits, not the original 2026-05-20 raw slice-index panic. A separate from-scratch --release build with assertions compiled out (this workspace's profile.release sets no override) confirmed the same missing check still panics, at channel.rs:607, with that original report's own message verbatim: "slice index starts at 8 but ends at 0". Rust's slice-range check is a language-level invariant, not a debug-only gate, so this is a reachable-input DoS in every build profile. The minimized input is committed as a permanent regression seed. Restoring the fix replays clean and two independent >45s sessions (700k-1.1M execs each) found nothing further. 2c6832b is a pure allocation-amortization change no oracle here distinguishes. 7299c28 is not the same kind of gap: it fixed a real stuck-read correctness defect in Channel::readable() (closes #1050) that this target cannot reach because readable() is the socket I/O shell outside its sans-io scope -- not because the defect was benign. That shell currently has no dedicated regression test of its own either. Surfaced, but did not fix (out of scope here), a live construction-time gap: Channel::new never validates buffer_size <= max_buffer_size, which trips try_read_delimited_message's own debug_assert (channel.rs:528) on the first parse -- the harness's own construction parameters are clamped to avoid it and the finding is documented in fuzz/README.md sec 2.5 for the orchestrator to triage separately. Not yet wired into the fuzz CI job, the extended-fuzz sweep, or e2e/src/tests/fuzz_tests.rs -- proposed, not added. Updates fuzz/README.md, doc/testing.md, and CHANGELOG.md in the same changeset per the docs-are-code convention. Signed-off-by: Florentin Dubois <[email protected]>
|
The CI wiring this PR deliberately does not add, written down so it is a decision rather than an Per-PR, in - name: Fuzz fuzz_command_channel (300s)
working-directory: fuzz
run: cargo +nightly fuzz run fuzz_command_channel -- -max_total_time=300Nightly, in target: [fuzz_frame_parser, fuzz_hpack_decoder, fuzz_udp_flow, fuzz_tcp_clienthello, fuzz_command_channel]And Two things to settle before wiring itThe Running it is not the same as gating on it. The committed corpus seed means a regression of |
command/src/channel.rscarries the control plane's wire format: 8-byte little-endian length prefix,prostdecode, over amio::net::UnixStream.try_read_delimited_messageoperates purely on anin-memory buffer — bounds and length validation, decode, consumption — with
readable()/writable()as the I/O shell around it. That boundary is already drawn where the house sans-io pattern draws it.
It has four framing-correctness fixes in its history —
5af7daea,7b8dce97,2c6832b9,7299c285— against eleven
#[test]s in a 1226-line file this project's own documentation names assecurity-sensitive. Its two direct analogues,
fuzz_frame_parserandfuzz_hpack_decoder, arefuzzed. It was not.
This adds
fuzz/fuzz_targets/fuzz_command_channel.rs. Test-only:git diff --statagainstcommand/,lib/,bin/,e2e/andsim/is empty.The oracle is more than "did not panic"
Seven properties, chosen so a defect has somewhere to show up other than a crash:
MessageLengthUnderDelimiteralways drops exactlydelimiter_size()bytes — the precise resyncguarantee
5af7daea's fix andcommand_channel_security_tests.rsboth name.MessageTooLargeconsumes nothing and does not grow the buffer's capacity before rejecting —7b8dce97's allocation-pressure class.NothingReadconsumes nothing.available_data() == total_fed − total_consumedat every step.write_delimited_message.Property 6 is the strongest: both counters are summed by the harness itself and never read back from
the code under test, so it catches double-consume or silent loss even where a per-call check would not.
Property 2 is partly tautological and says so in the module doc: it peeks the declared length using
the same
delimiter_size()andfrom_le_bytesproduction uses, so a defect inside those primitiveswould be invisible to it. The byte-accounting half is still a real check on the consume step.
Proving it bites, and what it catches in a release build
Reintroducing
5af7daea's missingmessage_len < delimiter_size()guard, the target finds a 6-byteinput —
[0, 0, 0, 0, 5, 9], an all-zero delimiter declaringmessage_len = 0— at run #295, under asecond. A review reproduced this independently from an empty corpus with no seed, finding a crash at
~run #538 in under a second.
That panic fires on a
debug_assert!a later hardening pass added to the same path, not on theoriginal 2026-05-24 raw slice-index panic. Which raises the obvious question: does this target only
find things because assertions are on?
No, and it was checked rather than argued.
cargo-fuzzinjects-Cdebug-assertionsunconditionally, so
cargo fuzz runalways has them. Separately, a genuine release build withassertions compiled out — this workspace's
[profile.release]sets onlylto,codegen-unitsanddebug— still panics on the same input:That is the original defect, firing because Rust's slice range check is a language-level memory-safety
invariant rather than a debug gate. Reachable-input DoS in every build profile. This was reproduced
first-hand for this description, not taken from the review.
The minimised input is committed as a permanent regression seed following the existing corpus naming
convention.
What this target does not cover, stated precisely
2c6832b9is pure allocation amortisation — it removes an innermin(..., needed)cap with the samefinal ceiling either way — so no oracle here could distinguish it. Fine.
7299c285is not that, and an earlier revision of this description said it was. Its own commitmessage says it "Closes #1050 where the channel silently stopped reading when the buffer was full" — a
real stuck-read defect in
Channel::readable()'s socket-read loop. This target cannot reach it becausereadable()is the socket I/O shell deliberately outside its scope, not because the defect wasbenign.
And a further overclaim corrected in the same pass:
buffer_grows_with_doubling_strategyunit-testsgrow_size()in isolation, notreadable()'s use of it — so that defect class currently has nodedicated regression test at all. Whether this target should grow a socket-facing harness to reach
readable()is left as an open question rather than answered by omission.A live defect found, filed not fixed
Before the harness's construction generator was clamped, it produced
ReaderChannel::generate_nonblocking(45, 32)and trippedtry_read_delimited_message's owndebug_assert!on the first parse.Channel::newnever validatesbuffer_size <= max_buffer_size,and
command/src/config.rshas no cross-validation betweencommand_buffer_sizeandmax_command_buffer_size— so an operator's TOML reaches the same state on the real master↔workerchannel.
Filed as #1416. The generator is now clamped to
buffer_size <= max_buffer_size, which is whatevery real caller already does, so the target explores wire framing instead of rediscovering this every
run. That clamp is a harness decision, not a fix, and should be revisited once #1416 is resolved. A
review confirmed it is scoped to exactly that relation and narrows nothing else.
No CI job is added
Proposed in a comment below, for a separate decision. Note the existing
fuzzjob's 45-minute timeoutand its "4 × 300s" budget comment would need revisiting for a fifth target. And
mainhasrequired_status_checks.contexts: [], so adding a job makes it run but not gate.Validation
Refs #1416.