Skip to content

Validate SACK block ranges - #1396

Draft
yitingb wants to merge 1 commit into
FreeRTOS:mainfrom
yitingb:sack-range-check
Draft

yitingb wants to merge 1 commit into
FreeRTOS:mainfrom
yitingb:sack-range-check

Conversation

@yitingb

@yitingb yitingb commented Dec 3, 2026

Copy link
Copy Markdown

Description

This change adds SACK block validation to ulTCPWindowTxSack(), to match the ACK range check added in #1367.

A SACK block starting at SND.UNA made prvTCPWindowTxCheckAck() free the segments it covered and advance SND.UNA. RFC 2018 section 8 says "the sender MUST NOT discard data before it is acknowledged by the Acknowledgment Number field in the TCP header". A block is now used only when SND.UNA < left edge < right edge <= SND.NXT, with the same SND.NXT and FIN handling as ulTCPWindowTxAck(). A SACK can still mark segments as acknowledged, but only the cumulative ACK frees them. Ignored blocks no longer count towards fast retransmit either.

Two notes for review:

  • The separate ulFirst < SND.NXT comparison is needed because sequence numbers wrap. Without it, a block that starts after SND.NXT can pass the other three comparisons.
  • ulTCPWindowTxSack() now returns 0 for every block. Its caller, prvReadSackOption(), is left unchanged to keep the diff small.

We thank Systina12 (https://github.com/Systina12) for their help identifying this issue.

Test Steps

  • Adds 7 unit tests for ulTCPWindowTxSack(): one for each comparison, plus a block covering a sent FIN, a window that wraps past 2^32, and the state after a FIN is sent. 6 of them fail without the source change.
  • The 7 existing SACK tests now zero-initialize the window and set tx.ulHighestSequenceNumber, because the new check reads it. Their expected results are unchanged.
  • All unit tests pass in the CI's ASan/UBSan and coverage builds, and FreeRTOS_TCP_WIN.c keeps 100% line and branch coverage. Formatting and spell check pass.

Checklist:

  • I have tested my changes. No regression in existing tests.
  • I have modified and/or added unit-tests to cover the code changes in this Pull Request.

Related Issue

None.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

ulTCPWindowTxSack() passed every received SACK block to
prvTCPWindowTxCheckAck() unchecked, so a block starting at SND.UNA
freed the covered segments and advanced SND.UNA. RFC 2018 section 8
leaves releasing data to the cumulative ACK.

Use a block only when SND.UNA < left edge < right edge <= SND.NXT,
with the same SND.NXT and FIN handling as ulTCPWindowTxAck(). A SACK
can now only mark segments as acknowledged, and ignored blocks no
longer count towards fast retransmit.

Add a unit test for each rejected case, plus FIN and sequence-wrap
cases, and set SND.NXT in the existing SACK tests.

We thank Systina12 (https://github.com/Systina12) for their help
identifying this issue.
@htibosch

htibosch commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Hello @yitingb , thanks for reporting for preparing a PR!

The pipe-line of PRs is a bit crowded at the moment. I'm waiting for a new PR related to the FIN flags, and after that we can try to merge your #1396. Please hold on a moment.

Thanks

@htibosch

htibosch commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Good news @yitingb, we tested it and the change looks good!
I don't see any overlap with the new upcoming PR, so we can try to get it merged.

Here is a copy of the testing script:

Validate_SACK_block_ranges.zip

I tested before and after applying the patch. This is after:

==================================================================================
 SACK RANGE CONFORMANCE TEST SUMMARY
==================================================================================
TEST CASE                    | RESULT |   TIME | DETAILS
----------------------------------------------------------------------------------
1) SACK AT SND.UNA           | PASS   |  4.15s | Ignored invalid SACK; RTO retransmitted seq=1738203262 at +0.984s
2) SACK BEHIND SND.UNA       | PASS   |  3.94s | Ignored invalid SACK; RTO retransmitted seq=1358944843 at +0.984s
3) SACK PAST SND.NXT         | PASS   |  4.03s | Ignored invalid SACK; RTO retransmitted seq=3416946973 at +0.984s
4) SACK WRAP PAST 2^32       | PASS   |  3.95s | Ignored invalid SACK; RTO retransmitted seq=3998446005 at +0.984s
5) VALID OOO SACK FAST RETX  | PASS   |  2.17s | Fast-retransmitted seg1 at +0.000s after SACK; seg2 not resent
==================================================================================
 TOTAL: 5/5 passed (out of 5 planned)
==================================================================================

This branch has not been deployed

No deployments
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.

2 participants