Skip to content

Hardening: only dispatch UDP messages that are valid on UDP - #229

Open
ralphlange wants to merge 1 commit into
epics-base:masterfrom
ralphlange:fix-udp-command-filter
Open

ralphlange wants to merge 1 commit into
epics-base:masterfrom
ralphlange:fix-udp-command-filter

Conversation

@ralphlange

Copy link
Copy Markdown
Contributor

Response handler tables are shared between TCP and the UDP. TCP handlers operate on a connection (channels, IOIDs, security session, ...) and down-cast the transport with an unchecked static_pointer_cast.

A single unsolicited datagram carrying e.g. CMD_CREATE_CHANNEL makes the server create a channel through that invalid pointer. It reliably segfaults in ServerChannelRequesterImpl::getPeerInfo().

Restrict processBuffer() to the messages that are actually defined for UDP (beacon, echo, search, search response, origin tag) and drop the rest.

Also drop truncated CMD_ORIGIN_TAG messages:
decodeAsIPv6Address() does not check the buffer, so a shorter message reads past the end of the receive buffer and trips the ByteBuffer assertion. epicsAssert() suspends the calling thread - the IOC stops answering searches on that interface.

Found while investigating #228.

Response handler tables are shared between TCP and the UDP.
TCP handlers operate on a connection (channels, IOIDs, security session, ...)
and down-cast the transport with an unchecked static_pointer_cast.

A single unsolicited datagram carrying e.g. CMD_CREATE_CHANNEL
makes the server create a channel through that invalid pointer.
It reliably segfaults in ServerChannelRequesterImpl::getPeerInfo().

Restrict processBuffer() to the messages that are actually defined for
UDP (beacon, echo, search, search response, origin tag) and drop the
rest.

Also drop truncated CMD_ORIGIN_TAG messages:
decodeAsIPv6Address() does not check the buffer, so a shorter message
reads past the end of the receive buffer and trips the ByteBuffer assertion.
epicsAssert() suspends the calling thread - the IOC stops answering searches
on that interface.

Found while investigating epics-base#228.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ralphlange ralphlange added the bug label Sep 18, 2026
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 10 complexity · 0 duplication

Metric Results
Complexity 10
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@AppVeyorBot

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants