nstun: validate TCP acknowledgments before processing payload#279
Open
Alearner12 wants to merge 1 commit into
Open
nstun: validate TCP acknowledgments before processing payload#279Alearner12 wants to merge 1 commit into
Alearner12 wants to merge 1 commit into
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.
nstun: validate TCP acknowledgments before processing payload
Summary
This change makes nstun validate guest TCP acknowledgments before using them to
mutate send-side state or deliver segment payload.
SND.NXTbefore processing segment text.SYN-SENT.cumulative ACK.
push_to_guest()explicit to callers.Bug
The synchronized-state receive path previously processed segment payload before
validating
SEG.ACK. A guest could therefore attach payload to an ACK beyondSND.NXT; the payload could reach the host-facing receive path before theinvalid acknowledgment was reflected in send-side accounting.
The old ACK accounting then calculated an advance directly from the supplied
32-bit ACK and updated
ack_from_guestandtx_acked_offset. An ACK outside thecurrent send window could consequently move the flow beyond the data actually
sent or buffered.
SYN-SENTalso accepted acknowledgment state without applying the same sendwindow invariant. Separately, the retransmission timer compared sequence
numbers with ordinary integer ordering, which is incorrect when the sequence
space wraps at
UINT32_MAX.Fix
The receive path now classifies every ACK relative to
SND.UNAandSND.NXTbefore processing payload:
consumption is consistent with the transmit buffer.
a corrective ACK.
instead of partially committing state.
SYN-SENTrejects unacceptable acknowledgments before performing RST orSYN|ACK processing. An unacceptable ACK without RST produces the reset response
specified for that state, while an acceptable inbound SYN|ACK completes the
transition to
ESTABLISHED.The defensive buffer checks mean
push_to_guest()can synchronously destroy aflow. Its return value now reports that invalidation, and callers stop using the
flow immediately. Garbage collection snapshots active flow pointers before
running callbacks so callback-driven erasure does not invalidate the map
iteration itself.
Regression coverage
tests/tcp_state_test.cccovers:tests/tcp_process_test.ccexercises the actual TCP processing implementationwith external I/O stubbed. It verifies that:
ABCdoes not changeack_from_guest,seq_to_guest,tx_acked_offset, ortx_buffer.SYN-SENTpreserves the pending flow and emits an RSTwhose sequence number is copied from
SEG.ACK.ESTABLISHEDand emits theexpected final ACK.
push_to_guest()path reports destruction without callerssubsequently accessing the invalidated pointer.
Verification
Local verification performed:
make tcp_state_testmake tcp_process_testnstun/tcp.ccnstun/nstun.ccgit diff --checkThe full nsjail binary was not linked locally because this checkout does not
contain the
kafelsubmodule and network access was unavailable. The focusedtests and directly affected translation units compile successfully.