SBN_ProcessSubsFromPeer: cap SubCnt at SBN_MAX_SUBS_PER_PEER#93
Open
nurdymuny wants to merge 2 commits into
Open
SBN_ProcessSubsFromPeer: cap SubCnt at SBN_MAX_SUBS_PER_PEER#93nurdymuny wants to merge 2 commits into
nurdymuny wants to merge 2 commits into
Conversation
A peer can send an SBN protocol message with a 16-bit SubCnt field up to 65535. The receiver's loop calls Unpack_Data + ProcessSubFromPeer SubCnt times; ProcessSubFromPeer correctly rejects writes past SBN_MAX_SUBS_PER_PEER (so no memory corruption), but the receiver still spins on the loop until the inner reject fires. A single malformed subscription packet from a compromised peer pins a flight CPU for ~65k iterations and floods the EVS log with errors. Reject the message up front when SubCnt exceeds the per-peer subscription cap.
scj-hunt v0.10 catalog flagged this function at the same 10.0 score as ProcessSubsFromPeer (the one in the existing commit) — same shape, identical Unpack_UInt16 → unbounded for-loop pattern. The Unsubs handler ignores ProcessUnsubFromPeer's return value to 'unsub as much as I can' (comment line 629), so unlike the Subs path there's no internal early-exit on the cap. A peer-controlled SubCnt of 65535 ties up the receiving CPU even more directly than the Subs case did. Same fix shape, same error code path.
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.
Summary
Cap
SubCntfrom a peer-supplied subscription message atSBN_MAX_SUBS_PER_PEERbefore entering the dispatch loop. Closes #92.Why
SBN_ProcessSubsFromPeerreadsSubCnt(uint16, peer-controlled) and loops up toSubCnttimes callingUnpack_Data+ProcessSubFromPeer. The inner function correctly rejects writes pastSBN_MAX_SUBS_PER_PEER(so no memory corruption), but the outer loop still spins up to 65535 iterations per malformed packet. A compromised or glitching peer can pin a receiving CPU and flood the EVS log with a single packet, repeated.Diff
Mirrors the existing version-hash mismatch early-return one block up in the same function.
Tests
SubCnt=0x4000(>SBN_MAX_SUBS_PER_PEER=256 by default), confirmed the function returns SBN_ERROR immediately with a single log line instead of spinning 16k iterations.Linked
Closes #92.