git: cd2a0f873c13 - releng/15.2 - tcp: address PR295870

From: Colin Percival <cperciva_at_FreeBSD.org>
Date: Tue, 17 Nov 2026 19:52:00 UTC
The branch releng/15.2 has been updated by cperciva:

URL: https://cgit.FreeBSD.org/src/commit/?id=cd2a0f873c132ed734a36875aad190d447a59bc5

commit cd2a0f873c132ed734a36875aad190d447a59bc5
Author:     Richard Scheffenegger <rscheff@FreeBSD.org>
AuthorDate: 2026-11-08 15:36:13 +0000
Commit:     Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2026-11-17 19:51:39 +0000

    tcp: address PR295870
    
    Fix accounting in the sequence space for a FIN bit potentially
    piggy bagged during SACK loss recovery triggered transmissions.
    
    Approved by:    re (cperciva)
    Reviewed By: #transport, tuexen
    Sponsored by: NetApp, Inc.
    MFC after: 1 week
    Differential Revision: https://reviews.freebsd.org/D61312
    
    (cherry picked from commit 0aa6428f463699c5f5e03715ea4ebe2309a23a2d)
    (cherry picked from commit f5797fcb0d8d8b2a63a49c3fe27eb9d7c7c417a8)
---
 sys/netinet/tcp_output.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/sys/netinet/tcp_output.c b/sys/netinet/tcp_output.c
index 208f72c4661c..55a8090cf7e2 100644
--- a/sys/netinet/tcp_output.c
+++ b/sys/netinet/tcp_output.c
@@ -1192,6 +1192,7 @@ send:
 	if (flags & TH_FIN && tp->t_flags & TF_SENTFIN &&
 	    tp->snd_nxt == tp->snd_max)
 		tp->snd_nxt--;
+	KASSERT(SEQ_LEQ(tp->snd_nxt, tp->snd_max), ("SEG_GT(snd_nxt, snd_max)"));
 	/*
 	 * If we are starting a connection, send ECN setup
 	 * SYN packet. If we are on a retransmit, we may
@@ -1543,8 +1544,16 @@ out:
 				tp->t_flags |= TF_SENTFIN;
 			}
 		}
-		if (sack_rxmit)
+		if (sack_rxmit) {
+			/*
+			 * Retransmitted bytes are already in snd_max.
+			 * A FIN on this segment is not. snd_nxt was
+			 * advanced for it above.
+			 */
+			if (SEQ_GT(tp->snd_nxt, tp->snd_max))
+				tp->snd_max = tp->snd_nxt;
 			goto timer;
+		}
 		tp->snd_nxt += len;
 		if (SEQ_GT(tp->snd_nxt, tp->snd_max)) {
 			/*