Skip to content

command: Channel::new accepts buffer_size > max_buffer_size, so a misconfigured command_buffer_size violates the channel's own capacity invariant on the first parse #1416

Closed

Description

@FlorentinDUBOIS

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

  1. added 4 commits that reference this issue on Sep 22, 2026
    8e326b3
    caf3edb
    4a75efd
    0f95fd4
  2. added 5 commits that reference this issue on Sep 22, 2026
    5d334e7
    7a223a8
    5e0218d
    f856920
    8595776
  3. added a commit that references this issue on Sep 22, 2026
    5f49716
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions