Bind encapsulation sessions to owning TCP socket#584
Open
MrAlaskan wants to merge 1 commit into
Open
Conversation
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.
Background
This change fixes a session binding issue in the Ethernet/IP encapsulation layer (see #565).
Before this patch, session validation only checked whether a
session_handlewas present ing_registered_sessions[]. It did not verify that the handle belonged to the TCP socket currently sending the request.As a result, if an attacker could learn a valid session handle, the attacker could reuse that handle from a different TCP connection.
Vulnerability Summary
Affected logic:
CheckRegisteredSessions()accepted any non-empty session slot as valid.HandleReceivedSendRequestResponseDataCommand()relied on that result forSendRRData.HandleReceivedSendUnitDataCommand()relied on that result forSendUnitData.HandleReceivedUnregisterSessionCommand()closed a session by handle without confirming that the requesting TCP connection owned the session.Impact:
UnregisterSessionthat can disconnect a valid client.Root Cause
The project already stores a session-to-socket mapping:
HandleReceivedRegisterSessionCommand()saves the owner socket ing_registered_sessions[session_index].However, later checks only verified that the entry was not
kEipInvalidSocket. They did not verify:g_registered_sessions[session_handle - 1] == current_socketThat missing ownership check created the vulnerability.
Fix Strategy
The fix keeps the current data structure and tightens validation logic.
CheckRegisteredSessions()so a session is valid only when the stored owner socket matches the current socket.HandleReceivedUnregisterSessionCommand()so a session can only be unregistered by the TCP connection that owns it.This is intentionally a minimal fix. It does not redesign session management; it only enforces the ownership rule that was already implied by the existing session-to-socket mapping.
Source Changes
Updated files:
source/src/enet_encap/encap.csource/src/enet_encap/encap.hKey logic changes:
HandleReceivedExplictTcpData()now passessocketintoHandleReceivedUnregisterSessionCommand(),HandleReceivedSendRequestResponseDataCommand(), andHandleReceivedSendUnitDataCommand().CheckRegisteredSessions()now requires the session slot to match the current TCP socket.HandleReceivedUnregisterSessionCommand()now rejects attempts to unregister a session owned by another socket.encap.hwas updated to match the new function signature forHandleReceivedSendRequestResponseDataCommand().