Skip to contentSkip to conversation

tcp: re-enable acceptance of FIN packets when RWIN is 0

PATCH Applied Simon Baatz 4 participants 8 messages Feb 24 – Feb 26

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover tcp: re-enable acceptance of FIN packets when RWIN is 0

Hi,

this series restores the ability to accept in‑sequence FIN packets even when the advertised receive window is zero, and adds a packetdrill test to guard the behavior.

---
Changes in v2:
- Move the FIN handling out of the default execution path as suggested by Eric Dumazet
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Simon Baatz (2):
tcp: re-enable acceptance of FIN packets when RWIN is 0 selftests/net: packetdrill: Verify acceptance of FIN packets when RWIN is 0

 net/ipv4/tcp_input.c                               | 18 +++++++++++----
 .../net/packetdrill/tcp_rcv_zero_wnd_fin.pkt       | 27 ++++++++++++++++++++++
 2 files changed, 41 insertions(+), 4 deletions(-)

---
base-commit: d4f687fbbce45b5e88438e89b5e26c0c15847992
change-id: 20260221-fix_zero_wnd_fin-d1ba11cd3b07

Best regards,

Signature · 1 line
Simon Baatz <[email protected]>
#1 lore raw

PATCH v2 1/2 tcp: re-enable acceptance of FIN packets when RWIN is 0

Commit 2bd99aef1b19 ("tcp: accept bare FIN packets under memory pressure") allowed accepting FIN packets in tcp_data_queue() even when the receive window was closed, to prevent ACK/FIN loops with broken clients.

Such a FIN packet is in sequence, but because the FIN consumes a sequence number, it extends beyond the window. Before commit 9ca48d616ed7 ("tcp: do not accept packets beyond window"), tcp_sequence() only required the seq to be within the window. After that change, the entire packet (including the FIN) must fit within the window. As a result, such FIN packets are now dropped and the handling path is no longer reached.

Be more lenient by not counting the sequence number consumed by the FIN when calling tcp_sequence(), restoring the previous behavior for cases where only the FIN extends beyond the window.

Fixes 9ca48d616ed7 ("tcp: do not accept packets beyond window")
---
 net/ipv4/tcp_input.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
net/ipv4/tcp_input.c +14 -4
index e7b41abb82aad33d8cab4fcfa989cc4771149b41..1c6b8ca67918f0601b9b3e8ef884c5fef0a7ab65 100644
@@ -4858,15 +4858,24 @@ static enum skb_drop_reason tcp_disordered_ack_check(const struct sock *sk,
  */
 
 static enum skb_drop_reason tcp_sequence(const struct sock *sk,
-					 u32 seq, u32 end_seq)
+					 u32 seq, u32 end_seq,
+					 const struct tcphdr *th)
 {
 	const struct tcp_sock *tp = tcp_sk(sk);
+	u32 seq_limit;
 
 	if (before(end_seq, tp->rcv_wup))
 		return SKB_DROP_REASON_TCP_OLD_SEQUENCE;
 
-	if (after(end_seq, tp->rcv_nxt + tcp_receive_window(tp))) {
-		if (after(seq, tp->rcv_nxt + tcp_receive_window(tp)))
+	seq_limit = tp->rcv_nxt + tcp_receive_window(tp);
+	if (unlikely(after(end_seq, seq_limit))) {
+		/* Some stacks are known to handle FIN incorrectly; allow the
+		 * FIN to extend beyond the window and check it in detail later.
+		 */
+		if (!after(end_seq - th->fin, seq_limit))
+			return SKB_NOT_DROPPED_YET;
+
+		if (after(seq, seq_limit))
 			return SKB_DROP_REASON_TCP_INVALID_SEQUENCE;
 
 		/* Only accept this packet if receive queue is empty. */
@@ -6379,7 +6388,8 @@ static bool tcp_validate_incoming(struct sock *sk, struct sk_buff *skb,
 
 step1:
 	/* Step 1: check sequence number */
-	reason = tcp_sequence(sk, TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq);
+	reason = tcp_sequence(sk, TCP_SKB_CB(skb)->seq,
+			      TCP_SKB_CB(skb)->end_seq, th);
 	if (reason) {
 		/* RFC793, page 37: "In all states except SYN-SENT, all reset
 		 * (RST) segments are validated by checking their SEQ-fields."
Signature · 1 line
2.53.0
Reviewed-by on v2 1/2
#2 lore raw
Quoted 16 lines · On Tue, Feb 24, 2026 at 9:20 AM Simon Baatz via B4 Relay…

From: Simon Baatz <[email protected]>

Commit 2bd99aef1b19 ("tcp: accept bare FIN packets under memory pressure") allowed accepting FIN packets in tcp_data_queue() even when the receive window was closed, to prevent ACK/FIN loops with broken clients.

Such a FIN packet is in sequence, but because the FIN consumes a sequence number, it extends beyond the window. Before commit 9ca48d616ed7 ("tcp: do not accept packets beyond window"), tcp_sequence() only required the seq to be within the window. After that change, the entire packet (including the FIN) must fit within the window. As a result, such FIN packets are now dropped and the handling path is no longer reached.

Quoted 7 lines

Be more lenient by not counting the sequence number consumed by the FIN when calling tcp_sequence(), restoring the previous behavior for cases where only the FIN extends beyond the window.

Fixes 9ca48d616ed7 ("tcp: do not accept packets beyond window")

---

reviewer Reviewed-by on v2 1/2
#3 lore raw
In reply to Simon Baatz
Quoted 16 lines · On Tue, Feb 24, 2026 at 12:20 AM Simon Baatz via B4 Relay…

From: Simon Baatz <[email protected]>

Commit 2bd99aef1b19 ("tcp: accept bare FIN packets under memory pressure") allowed accepting FIN packets in tcp_data_queue() even when the receive window was closed, to prevent ACK/FIN loops with broken clients.

Such a FIN packet is in sequence, but because the FIN consumes a sequence number, it extends beyond the window. Before commit 9ca48d616ed7 ("tcp: do not accept packets beyond window"), tcp_sequence() only required the seq to be within the window. After that change, the entire packet (including the FIN) must fit within the window. As a result, such FIN packets are now dropped and the handling path is no longer reached.

Quoted 6 lines

Be more lenient by not counting the sequence number consumed by the FIN when calling tcp_sequence(), restoring the previous behavior for cases where only the FIN extends beyond the window.

Fixes 9ca48d616ed7 ("tcp: do not accept packets beyond window")
#4 lore raw

PATCH v2 2/2 selftests/net: packetdrill: Verify acceptance of FIN packets when RWIN is 0

In reply to Simon Baatz

Add a packetdrill test that verifies we accept bare FIN packets when the advertised receive window is zero.

---
 .../net/packetdrill/tcp_rcv_zero_wnd_fin.pkt       | 27 ++++++++++++++++++++++
 1 file changed, 27 insertions(+)
tools/testing/selftests/net/packetdrill/tcp_rcv_zero_wnd_fin.pkt new file +27 -0
new file mode 100644
index 0000000000000000000000000000000000000000..e245359a1a91d4b6d7ef64496681cea57792cb71
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0
+
+// Some TCP stacks send FINs even though the window is closed. We break
+// a possible FIN/ACK loop by accepting the FIN.
+
+--mss=1000
+
+`./defaults.sh`
+
+// Establish a connection.
+   +0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
+   +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+   +0 setsockopt(3, SOL_SOCKET, SO_RCVBUF, [20000], 4) = 0
+   +0 bind(3, ..., ...) = 0
+   +0 listen(3, 1) = 0
+
+   +0 < S 0:0(0) win 32792 <mss 1000,nop,wscale 7>
+   +0 > S. 0:0(0) ack 1 <mss 1460,nop,wscale 0>
+   +0 < . 1:1(0) ack 1 win 257
+
+   +0 accept(3, ..., ...) = 4
+
+   +0 < P. 1:60001(60000) ack 1 win 257
+    * > .  1:1(0) ack 60001 win 0
+
+   +0 < F. 60001:60001(0) ack 1 win 257
+   +0 > . 1:1(0) ack 60002 win 0
Signature · 1 line
2.53.0
reviewer Reviewed-by on v2 2/2
#6 lore raw

Re: [PATCH net v2 2/2] selftests/net: packetdrill: Verify acceptance of FIN packets when RWIN is 0

In reply to Simon Baatz
Quoted 7 lines · On Tue, Feb 24, 2026 at 12:20 AM Simon Baatz via B4 Relay…

From: Simon Baatz <[email protected]>

Add a packetdrill test that verifies we accept bare FIN packets when the advertised receive window is zero.

#7 lore raw
In reply to Simon Baatz
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Tue, 24 Feb 2026 09:20:11 +0100 you wrote:

Hi,

this series restores the ability to accept in‑sequence FIN packets even when the advertised receive window is zero, and adds a packetdrill test to guard the behavior.

[...]

Here is the summary with links:
- [net,v2,1/2] tcp: re-enable acceptance of FIN packets when RWIN is 0

    https://git.kernel.org/netdev/net/c/1e3bb184e941
  - [net,v2,2/2] selftests/net: packetdrill: Verify acceptance of FIN packets when RWIN is 0
    https://git.kernel.org/netdev/net/c/745113323098

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html