transport: fix dial-timeout teardown UAF/segfault (aliased inbound streams) + zquic v1.7.61 - #282
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Crash from the live devnet (newly visible because v0.2.55 fixed the spiral that was killing nodes first):
Root cause (UAF / double-free)
dispatchOutboundPeerStreamsstores raw pointers into the outbound dial'sClient(ist.raw.client = &client,ist.conn = &client.conn) insh.inbound_streams.detectOutboundConnectionClosefreed 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 inClient.deiniton a recycledrecv_reorderpointer. Pre-existing.Fix
sh.inbound_streamsandremoveInboundStreamAtConnGoneevery stream aliasing the dying client before freeing it (non-deref variant — the conn is dead). Removes the dangling pointers at the source.Client.deinit(one-timedeinitializedguard) — defense-in-depth against any double-deinit.Adversarially traced (double-free of the aliased client, not partial-init garbage). Build clean; 504/506 tests.