Skip to content

command: an oversized declared frame length is neither consumed nor signalled, so the command-channel session wedges permanently instead of being dropped #1428

Closed

Description

@FlorentinDUBOIS

try_read_delimited_message (command/src/channel.rs) has two peer-controlled-length rejection
branches. One re-syncs the stream. The other does not, and nothing downstream compensates.

All line numbers below are at 595920e91c4528f0554410b904b45d543c88e467.

The two branches, side by side

command/src/channel.rs:566-578 — the under-delimiter branch, with the comment that states the
contract:

// Drop the bogus delimiter bytes before returning so the channel
// can re-sync on the peer's next frame. Without this, every
// subsequent `read_message()` re-reads the same bad header from
// the front buffer and the worker burns CPU on the same error
// until the peer disconnects.
if message_len < delimiter_size() {
    self.front_buf.consume(delimiter_size());
    return Err(ChannelError::MessageLengthUnderDelimiter { .. });
}

command/src/channel.rs:553-559 — the oversize branch, twelve lines earlier, same shape, no
consume, no readiness change, no log:

if message_len > self.max_buffer_size {
    return Err(ChannelError::MessageTooLarge {
        message_len,
        capacity: self.front_buf.capacity(),
        max: self.max_buffer_size,
    });
}

The delimiter stays at the head of front_buf permanently. Every later parse on that channel
re-reads the same eight bytes and returns the same error.

Its own justification comment, command/src/channel.rs:545-552, already asserts the behaviour the
code does not have:

Reject as MessageTooLarge so the read loop disconnects cleanly instead of running the
doubling growth strategy on attacker-supplied numbers.

The first half is true and load-bearing (7b8dce97: reject before Buffer::grow runs on
attacker-supplied numbers). The emphasised half is not: nothing disconnects. It is the same false
claim as the doc paragraph below, sitting three lines above the branch that fails to honour it.

Nothing downstream turns that into a close

  • read_message_nonblocking (command/src/channel.rs:471-479) propagates it with ?. No log.
  • extract_messages (bin/src/command/sessions.rs:588-606) discards it with a bare Err(_) at
    line 590 and returns as soon as the capacity stops changing — which is immediately, since the
    oversize guard returns before the grow block. No log.
  • ClientSession::ready (:165) and WorkerSession::ready (:549) close only on
    readiness.is_error() || is_hup(). A parse error touches neither bit.
  • wants_to_tick (:612-615) keys on the same two bits plus pending write data, so the session is
    not even re-scheduled.

So the peer is never dropped and the failure is never logged — the channel is simply wedged.

What I checked and did NOT find, so the consequence is not overstated

I expected a 100%-CPU spin and there isn't one. Both candidate loops terminate:

  • extract_messages's loop exits because old_capacity == new_capacity (the oversize guard
    returns before front_buf can grow), so it returns an empty Vec each tick.
  • the worker's read_channel_messages_and_notify (lib/src/server.rs:1316-1361) has a continue
    guarded by (interest & readiness).is_readable() — under a comment that literally reads "if the
    message was too large, we grow the buffer and retry to read if possible"
    — but every exit path
    from Channel::readable clears READABLE from interest or readiness first, so it breaks.

The real consequence is a permanent per-connection wedge, not CPU burn:

  1. The poisoned header sits at the head of front_buf forever.
  2. Bytes the peer keeps sending pile up behind it. front_buf doubles to max_buffer_size, then
    Channel::readable hits self.interest.remove(Ready::READABLE) (:335) and every later
    readable() returns Err(Connection(None)) for the life of the process.
  3. The session is never removed from CommandHub::clients / workers. Its fd and up to
    max_command_buffer_size (2 MB by default) of buffer are pinned forever.
  4. bin/src/command/server.rs:620-622 accepts without any connection cap, so the wedged sessions
    accumulate one per connection, each costing one fd and one buffer, from an 8-byte write.
  5. doc/configure_admin_ops.md §5.2 claims "when the cap is exceeded the supervisor logs and drops
    the offending peer's session". Neither half happens today.

Reachability: hardening, not a remote DoS

The command socket is a unix socket chmod'd 0o600 immediately after bind
(bin/src/command/mod.rs:98-101), and there is no TCP control-plane listener in the tree. Reaching
it as a client means already being the uid that runs sōzu, or root. So this is not
remotely triggerable and it is not a privilege boundary crossing.

The second reachable side is the master↔worker socketpair, which the same code serves in both
directions. A worker is the component that parses untrusted network traffic; a worker compromised
or corrupted through that surface can wedge its WorkerSession in the master with one 8-byte
write, silently and permanently. That is a post-compromise lateral step, not a primary vector.

So: a hardening / robustness fix and a correctness fix for the documented contract. Not a CVE.

Why it is obviously unintentional

Beyond the sibling branch twelve lines away, the codebase already decided this exact question — on
the write side. is_transient_overflow (bin/src/command/sessions.rs:409-422) splits
MessageTooLarge in two and says so:

MessageTooLarge covers two different situations: a frame that fits under the channel ceiling but
not in what is left of the buffer — transient, the request is parked and written after the next
drain — and a frame bigger than the ceiling itself, which no amount of draining will ever
admit
. Parking the second would hang its task forever, so it stays a hard error

and the hard-error arms (:477-481, :511-519) do error!(...) followed by
self.channel.readiness = Ready::ERROR, i.e. log and drop the session. The read side is the same
judgement — a declared length above the ceiling can never be satisfied — and never got the same
treatment.

Also worth noting: write_delimited_message (command/src/channel.rs:691) refuses to emit a
frame above the ceiling (:714). No conforming sōzu peer can put such a delimiter on the wire, so
seeing one means the peer is corrupt, desynchronised or hostile — which is an argument for
dropping it rather than for trying to re-frame on the bytes behind it.

The fuzz target cannot find this — it asserts the defect

fuzz/fuzz_targets/fuzz_command_channel.rs (#1420) reaches the case: its delimiter pool is biased
toward max_buffer_size + 1 and usize::MAX. But its oracle pins the current behaviour:

Err(ChannelError::MessageTooLarge { .. }) => {
    assert_eq!(consumed_this_call, 0, "MessageTooLarge must not consume any bytes");

That property exists to protect 7b8dce97's allocation-pressure fix (reject before growing), and
it is correct as far as it goes — but it encodes "consumes nothing" as the whole contract, with
nothing saying the caller must then be told to close. A fuzzer whose oracle asserts the defect will
never report it. Worth revisiting alongside this.

Two candidate resolutions, and why I think one is clearly right

Consume the delimiter and continue, mirroring the sibling branch, is the obvious symmetry — and
I think it is wrong here. The two cases are not analogous. message_len < delimiter_size() is a
value no writer can produce for any payload, so those eight bytes are provably not a real header and
skipping exactly them re-aligns the stream. An oversized message_len carries no such proof: the
declared length may be honest, in which case the bytes behind the header are payload, and re-framing
on them decodes peer-chosen bytes as a fresh Request on the control plane. Trading a wedged
session for attacker-influenced command framing is a bad trade.

Treat it as fatal for that peer — log it, mark the channel Ready::ERROR, let
ClientSession::ready / WorkerSession::ready drop the session — matches the write-side stance
quoted above, reuses the existing close machinery (including worker_automatic_restart), keeps the
7b8dce97 "reject before growing / consume nothing" property the fuzz oracle guards, and makes
§5.2 true instead of aspirational.

What I verified, and what I did not

Verified by reading command/src/channel.rs, bin/src/command/sessions.rs,
bin/src/command/server.rs, bin/src/command/mod.rs and lib/src/server.rs at 595920e9, and by
a unit test driving a real nonblocking Channel pair over a socketpair: after an oversized
delimiter, two consecutive read_message() calls return the identical MessageTooLarge against an
unchanged front_buf.available_data(), and readiness.is_error() is false.

test channel::tests::oversized_declared_length_marks_the_channel_for_closing ... FAILED

thread '...' panicked at command/src/channel.rs:1378:9:
an oversized declaration must mark the channel errored so the supervisor drops the session;
without it the same delimiter is re-parsed forever, the error is swallowed by
`extract_messages`'s `Err(_)` arm, and the session wedges holding its fd and buffer

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 161 filtered out

Everything before that assertion passed: MessageTooLarge came back with message_len = 10001 and
max = 10000, front_buf.available_data() was unchanged across both calls, and the second call
returned the identical error. The only thing missing is the close signal.

Not verified: no end-to-end reproduction against a running sōzu master with a real CLI
connection or a real worker; the fd/memory accumulation in point 4 is read from the accept path and
the session maps, not measured. And I did not check whether any released version behaves
differently.

Activity

  1. added 8 commits that reference this issue on Sep 22, 2026
    50ee52f
    b78b7a6
    950ea9e
    f66e502
    56e3221
    cf0aea7
    9c51573
    970b92c
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