git: 0aa6428f4636 - main - tcp: address PR295870

From: Richard Scheffenegger <rscheff_at_FreeBSD.org>
Date: Sun, 08 Nov 2026 17:04:56 UTC
The branch main has been updated by rscheff:

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

commit 0aa6428f463699c5f5e03715ea4ebe2309a23a2d
Author:     Richard Scheffenegger <rscheff@FreeBSD.org>
AuthorDate: 2026-11-08 15:36:13 +0000
Commit:     Richard Scheffenegger <rscheff@FreeBSD.org>
CommitDate: 2026-11-08 17:04:12 +0000

    tcp: address PR295870
    
    Fix accounting in the sequence space for a FIN bit potentially
    piggy bagged during SACK loss recovery triggered transmissions.
    
    Reviewed By: #transport, tuexen
    Sponsored by: NetApp, Inc.
    MFC after: 1 week
    Differential Revision: https://reviews.freebsd.org/D61312
---
 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 b5f36d83f5a2..2ed2a7319aba 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)) {
 			/*