Prevent stream ID reuse while outgoing RE-CONFIG is pending#37
Draft
timwu20 wants to merge 6 commits intoalgesten:mainfrom
Draft
Prevent stream ID reuse while outgoing RE-CONFIG is pending#37timwu20 wants to merge 6 commits intoalgesten:mainfrom
timwu20 wants to merge 6 commits intoalgesten:mainfrom
Conversation
Author
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.
Problem
sctp-proto allows reusing an SCTP stream ID immediately after closing it, without waiting for the RE-CONFIG (RFC 6525) acknowledgment from the remote peer. This causes the remote's SCTP stack to silently drop or queue data sent on the reused stream, because from the remote's perspective the stream is still in a reset-pending state.
Reproduction sequence
open_streamis called and sctp-proto allocates stream 1 (it looks available — not in the table)This is easy to trigger in practice when short-lived channels (identify, request-response) are closed quickly and new channels are opened immediately after, especially when there is significant data flowing on other streams which may delay the RE-CONFIG ACK.
Relevant RFC
RFC 6525, Section 5.1 (Outgoing SSN Reset Request):
Impact
This bug causes WebRTC data channel failures in production when a data channel is opened shortly after another channel on the same SCTP stream ID is closed. In Polkadot light client WebRTC connections, it kills the block-announces notification protocol, leaving the peer permanently unable to sync.
Fix
has_pending_reset_for_stream()helper that checksself.reconfigs(pending outgoing RE-CONFIGs awaiting acknowledgment) for any entry containing the requested stream IDopen_stream()to returnErrStreamResetPendingif the stream ID has an unacknowledged outgoing RE-CONFIGself.reconfigsalready tracks unacknowledged outgoing reconfigs and is typically 0-1 entriesChanges
src/association/mod.rs: Addedhas_pending_reset_for_stream()and guard inopen_stream()src/error.rs: AddedErrStreamResetPendingerror variantsrc/endpoint/endpoint_test.rs: Addedtest_assoc_open_stream_rejects_pending_reset_idTest plan
open_streamrejects a stream ID mid-reset and allows it after the RE-CONFIG is acknowledgedcargo clippyandcargo fmtclean