Repository navigation
Description
Channel::new (command/src/channel.rs) takes buffer_size and max_buffer_size and stores both
without ever comparing them:
pub fn new(sock: MioUnixStream, buffer_size: u64, max_buffer_size: u64) -> Channel<Tx, Rx> {
let buffer_size = buffer_size as usize;
let max_buffer_size = max_buffer_size as usize;
Channel {
front_buf: Buffer::with_capacity(buffer_size),
back_buf: Buffer::with_capacity(buffer_size),
initial_buffer_size: buffer_size,
max_buffer_size,
...If buffer_size > max_buffer_size, front_buf is allocated already larger than the cap it is
supposed to respect. try_read_delimited_message then trips its own
debug_assert! — "front buffer capacity must never exceed max_buffer_size" — on the very first parse,
before any wire data is even examined.
generate_nonblocking has the same shape.
It is reachable from configuration, not only from a direct API call
command/src/config.rs carries command_buffer_size and max_command_buffer_size as independent
options, and I found no cross-validation between them. An operator who sets command_buffer_size
larger than max_command_buffer_size in their TOML reaches the same state on the real master↔worker
channel.
So the blast radius is: a debug, test or fuzz build panics on the first command-channel parse; a
release build, where the assertion is compiled out, runs with a buffer that silently violates the
bound the rest of the code reasons about — including the growth logic that checks against
max_buffer_size.
This is operator-triggered, not attacker-on-the-wire. It is a misconfiguration that should be
rejected at load time and instead becomes a runtime invariant violation.
How it was found
By a new cargo-fuzz target for the command channel's framing. It did not come from the wire-input
grammar the target was written for — it came from the construction parameters the harness itself
generates. Before the harness clamped those to what every real caller already does, the unconstrained
generator produced ReaderChannel::generate_nonblocking(45, 32) and tripped the assertion immediately.
The target's generator is now clamped to buffer_size <= max_buffer_size so it can explore its
intended wire-framing scope rather than rediscovering this on every run. That clamp is a harness
decision, not a fix, and it should be revisited once this is resolved.
Suggested resolution
The natural place is both ends, and they answer different questions.
At Channel::new/generate_nonblocking: either clamp buffer_size to max_buffer_size, or make
construction fallible and reject the pair. A clamp is cheaper and matches what the type already
promises about its own capacity; a rejection surfaces the operator's mistake instead of silently
honouring something they did not ask for.
At config load: validate command_buffer_size <= max_command_buffer_size and fail with a message
naming both values. This is where an operator can actually act on the error, and it is consistent with
how other cross-field configuration constraints in this file are handled.
Doing only the first hides the misconfiguration; doing only the second leaves the API able to
construct an invalid channel.
What I verified, and what I did not
Verified by reading command/src/channel.rs and command/src/config.rs at
595920e91c4528f0554410b904b45d543c88e467: the absence of any relation check in Channel::new, that
Buffer::with_capacity is given buffer_size directly, and that command_buffer_size and
max_command_buffer_size are carried as independent options through FileConfig into Config.
Not verified: no runtime reproduction through an actual TOML file and a real master↔worker
handshake was attempted. The path above is read from the code; the fuzz harness reproduced it through
the constructor directly, not through configuration loading.
Activity
fix(command): reject and structurally clamp command_buffer_size > max…
docs(command): name max_command_buffer_size as the channel wire-lengt…
docs(command): name max_command_buffer_size as the channel wire-lengt…
docs(command): name max_command_buffer_size as the channel wire-lengt…
fix(command): reject and structurally clamp command_buffer_size > max…
fix(command): reject and structurally clamp command_buffer_size > max…
docs(command): record why the client channel ignores command_buffer_size
docs(command): record why the client channel ignores command_buffer_size
docs(command): record why the client channel ignores command_buffer_size
docs(command): name max_command_buffer_size as the channel wire-lengt…
docs(command): record why the client channel ignores command_buffer_size
docs(command): record why the client channel ignores command_buffer_size
docs(command): record why the client channel ignores command_buffer_s…
fix(command): keep the old main serving when an upgrade fails late