Skip to content

mux-h2: flush_pending_control_frames' hung-up-while-draining stage clears zero.storage without the reassembly guard its three sibling stages carry #1423

Closed

Description

@FlorentinDUBOIS

ConnectionH2::flush_pending_control_frames has four stages that touch self.zero.storage. Three of
them are guarded. The first is not.

// stage 1 — no guard
if self.frontend_hung_up_while_draining() {
    self.stream_table.set_expect_write(None);
    self.zero.storage.clear();
    ...
}

// ... later stages, all guarded:
    && !self.header_block_reassembly_in_progress();      // WINDOW_UPDATE
    && !self.header_block_reassembly_in_progress()        // deferred initial GOAWAY
    && !self.header_block_reassembly_in_progress()        // RST_STREAM

self.zero is both the HEADERS+CONTINUATION reassembly accumulator — header_block_fragment is a
(start, len) window into it that must survive multiple readable() passes until END_HEADERS — and
the control-frame write scratch. Clearing it mid-reassembly corrupts the accumulating field block
while the recorded length keeps growing, so the bytes still HPACK-decode and the failure mode is
silently wrong header values, not a crash.

This is the fourth instance of the same class

Each of those added the guard to the stage it fixed. None of them looked at the stage above.

Reachability

frontend_hung_up_while_draining() requires only self.drain.draining() plus a HUP or ERROR readiness
event. Neither excludes a connection parked in H2State::ContinuationHeader or ContinuationFrame.
Two ordinary paths reach it:

Neither needs a hostile peer. The second is a normal operator-initiated drain racing an ordinary
client.

Suggested fix, and the reason to look wider than one line

Adding && !self.header_block_reassembly_in_progress() to stage 1 would match its three siblings. But
four instances of one class, each fixed in isolation, is the argument for something stronger than a
fifth guard.

The reassembly accumulator and the control-frame scratch are two roles with incompatible lifetimes
sharing one buffer. As long as they do, every future code path that reuses self.zero is one forgotten
guard away from silent header corruption, and the guard is invisible at the point where someone adds a
new stage.

The H2 sans-io extraction's reassembly step is the natural moment to separate them: a dedicated
accumulator with a real owned lifetime, and a caller-supplied scratch region for control-frame
serialisation. Then the collision is not guarded against — it is unrepresentable.

LIFECYCLE.md invariant 24 now names this hazard explicitly, with the three PRs above as provenance,
so at least a reviewer has something citable until that lands.

What I verified, and what I did not

Verified by reading flush_pending_control_frames in full: stage 1's self.zero.storage.clear() under
frontend_hung_up_while_draining() with no reassembly guard, and the && !self.header_block_reassembly_in_progress()
conjunct present on each of the three stages below it, in the same function.

Not verified: no runtime reproduction was attempted. Reaching it needs a peer that sends an
incomplete CONTINUATION and then hangs up during a drain; the reasoning above says that is sufficient,
but nobody has run it. A regression test in the shape of
a_legitimate_continuation_survives_a_graceful_goaway — which pins #1401 — would be the natural place
to prove it, and would be the red for whoever fixes this.

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