Skip to content

SBN_ProcessSubsFromPeer: cap SubCnt at SBN_MAX_SUBS_PER_PEER#93

Open
nurdymuny wants to merge 2 commits into
nasa:devfrom
nurdymuny:fix/sub-count-bound
Open

SBN_ProcessSubsFromPeer: cap SubCnt at SBN_MAX_SUBS_PER_PEER#93
nurdymuny wants to merge 2 commits into
nasa:devfrom
nurdymuny:fix/sub-count-bound

Conversation

@nurdymuny

Copy link
Copy Markdown

Summary

Cap SubCnt from a peer-supplied subscription message at SBN_MAX_SUBS_PER_PEER before entering the dispatch loop. Closes #92.

Why

SBN_ProcessSubsFromPeer reads SubCnt (uint16, peer-controlled) and loops up to SubCnt times calling Unpack_Data + ProcessSubFromPeer. The inner function correctly rejects writes past SBN_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

 fsw/src/sbn_subs.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
if (SubCnt > SBN_MAX_SUBS_PER_PEER)
{
    EVSSendErr(SBN_PROTO_EID,
               "peer CpuID %d sent SubCnt=%u, exceeds SBN_MAX_SUBS_PER_PEER=%u",
               Peer->ProcessorID, (unsigned)SubCnt,
               (unsigned)SBN_MAX_SUBS_PER_PEER);
    return SBN_ERROR;
}

Mirrors the existing version-hash mismatch early-return one block up in the same function.

Tests

  • Manual: hand-built a subscription message with 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.
  • Existing well-formed subscription messages still dispatch normally.

Linked

Closes #92.

nurdymuny added 2 commits June 9, 2026 06:50
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.
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.

SBN_ProcessSubsFromPeer: peer-supplied SubCnt is unbounded

2 participants