Repository navigation
stream-tcp-inline: align overlap rewrite with pruned segment head - v1 - #16744
Open
victorjulien wants to merge 1 commit into
Open
victorjulien wants to merge 1 commit into
victorjulien wants to merge 1 commit into
Conversation
StreamTcpInlineSegmentReplacePacket and StreamTcpInlineSegmentCompare derive the overlap from the segment's original seq. Once the stream head has slid past it, the stored data starts at base_seq and is shorter, so the derived offsets are shifted. ReplacePacket then reads from base_seq - seg->seq bytes too far into the stored data: in IPS mode a retransmit at or after base_seq that overlaps such a segment (handled by DoHandleDataOverlap) is rewritten from the wrong stream offsets, so the forwarded payload differs from the inspected stream. The compare clamps internally, but its no-overlap gates also use the unclamped segment end, and for a packet ending at or before base_seq the clamped start and unclamped end make `range` wrap. Only a debug-only guard covered that. Clamp the segment seq to base_seq in both functions before deriving the overlap, and apply the no-overlap gates in the clamped coordinates so `range` cannot wrap and straddling retransmits are not skipped. The exact-match fast path now only applies to unpruned segments. ReplacePacket also returns early when the segment carries no data, and the BUG_ON claiming a segment can never sit entirely before base_seq is dropped (it can while in use; the NULL data check handles it). Unit tests cover a pruned-head segment: an aligned rewrite, a partial rewrite at the segment head, a retransmit at base_seq+1 (the shape reachable from the packet path; pre-fix the copy reads too far into the stored data), and a packet overlapping the pruned head while ending before base_seq (pre-fix `range` wraps). Ticket: OISF#9463
suricata-review-bot
left a comment
There was a problem hiding this comment.
AI-generated review.
Verdict: approve
No high- or medium-severity findings.
Automated at commit c8807231462a using Claude Code with claude-opus-5-5/xhigh. Run: 21848d35d999f082.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #16744 +/- ##
==========================================
- Coverage 83.97% 83.95% -0.02%
==========================================
Files 1008 1008
Lines 286491 286542 +51
==========================================
Hits 240577 240577
- Misses 45914 45965 +51
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
|
Information: QA ran without warnings. Pipeline = 36135 |
victorjulien
marked this pull request as ready for review
November 26, 2026 14:37
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.
Ticket: https://redmine.openinfosecfoundation.org/issues/9463
StreamTcpInlineSegmentCompare/ReplacePacket derive the retransmit/
segment overlap from the segment's original seq. Once the stream head
has slid past that head, the stored data starts at base_seq and every
offset is shifted. In IPS mode a retransmit at or after base_seq that
overlaps such a segment is handled here (DoHandleDataOverlap): the
compare clamps internally and reports the data as different, but
ReplacePacket copies from
base_seq - seg->seqbytes too far into thestored data, so the forwarded payload differs from the inspected
stream. A packet that overlaps the pruned head but ends at or before
base_seq also wraps the range arithmetic; that pre-base shape is dropped
by the spurious-retransmission check before the overlap code
(src/stream-tcp.c:3398-3404), but the segment API should not depend on
that.
Clamp tseq/seg_seq to base_seq in both compare and replace before
deriving the overlap: in stored-data coordinates a non-overlap means no
shared data and the range cannot wrap. Fast path is kept only for
unpruned segments; replace guards empty segments; the stale BUG_ON is
dropped.
Unit tests (StreamTcpInlineTest09/10) slide the buffer, insert a
pruned-head segment and drive both paths directly: a retransmit at
base_seq+1 (the reachable shape; pre-fix this copies [6,8) instead of
[4,6)), a retransmit at the segment head, and a packet ending before
base_seq (pre-fix the range wraps). StreamTcpInlineTest09 fails on unfixed main.
SV_BRANCH=OISF/suricata-verify#3579