Skip to content

transport: fix dial-timeout teardown UAF/segfault (aliased inbound streams) + zquic v1.7.61 - #282

Merged
ch4r10t33r merged 1 commit into
mainfrom
fix/dial-timeout-uaf-segfault
Jun 28, 2026
Merged

transport: fix dial-timeout teardown UAF/segfault (aliased inbound streams) + zquic v1.7.61#282
ch4r10t33r merged 1 commit into
mainfrom
fix/dial-timeout-uaf-segfault

Conversation

@ch4r10t33r

Copy link
Copy Markdown
Collaborator

Crash from the live devnet (newly visible because v0.2.55 fixed the spiral that was killing nodes first):

dial handshake timed out after 20000ms; stalled_phase=initial
Segmentation fault at 0x1 → free → io.zig Client.deinit → QuicOutbound.deinit → driveTrampoline

Root cause (UAF / double-free)

dispatchOutboundPeerStreams stores raw pointers into the outbound dial's Client (ist.raw.client = &client, ist.conn = &client.conn) in sh.inbound_streams. detectOutboundConnectionClose freed the client without sweeping those streams, so on dial-timeout/close the pointers dangle into recycled memory; a later teardown double-frees/derefs the client → segfault in Client.deinit on a recycled recv_reorder pointer. Pre-existing.

Fix

  • Fix B (this repo): sweep sh.inbound_streams and removeInboundStreamAtConnGone every stream aliasing the dying client before freeing it (non-deref variant — the conn is dead). Removes the dangling pointers at the source.
  • Fix A (zquic v1.7.61): idempotent Client.deinit (one-time deinitialized guard) — defense-in-depth against any double-deinit.

Adversarially traced (double-free of the aliased client, not partial-init garbage). Build clean; 504/506 tests.

…ound streams + zquic v1.7.61

A timed-out / closed outbound dial freed its Client, but dispatchOutboundPeerStreams
had stored raw pointers INTO that client (ist.raw.client = &client, ist.conn =
&client.conn) in sh.inbound_streams. detectOutboundConnectionClose freed the
client WITHOUT sweeping those streams → dangling pointers into recycled memory →
a later teardown double-frees/derefs the client → Segmentation fault at 0x1 in
Client.deinit (recycled recv_reorder pointer). Live: 'dial handshake timed out
after 20000ms' then segfault. Pre-existing; newly hit at load once nodes survive
long enough (v0.2.55 fixed the spiral that was killing them first).

Fix B (this repo): in detectOutboundConnectionClose, BEFORE freeing the outbound
client, sweep sh.inbound_streams and removeInboundStreamAtConnGone every stream
whose ist.raw.client aliases the dying client (non-deref variant — conn is dead).
Fix A (zquic v1.7.61): idempotent Client.deinit guard (defense-in-depth).

Adversarially traced. Build clean; 504/506 tests.
@ch4r10t33r
ch4r10t33r merged commit f9bc78e into main Jun 28, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant