From: Simon Baatz via B4 Relay <devnull+gmbnomis.gmail.com@kernel.org>
To: Eric Dumazet <edumazet@google.com>,
Neal Cardwell <ncardwell@google.com>,
Kuniyuki Iwashima <kuniyu@google.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Simon Baatz <gmbnomis@gmail.com>
Subject: [PATCH net-next] tcp: tighten the FIN exception in tcp_sequence()
Date: Wed, 10 Jun 2026 00:09:24 +0200 [thread overview]
Message-ID: <20260610-tcp_fin_more_restrictive-v1-1-eefc30d7ddd8@gmail.com> (raw)
From: Simon Baatz <gmbnomis@gmail.com>
Commit 1e3bb184e941 ("tcp: re-enable acceptance of FIN packets when
RWIN is 0") added a special case in tcp_sequence() to mirror the FIN
exception in tcp_data_queue(), which accepts bare in-order FINs even
when the advertised window is zero. That behavior is not
RFC-compliant, but was introduced in commit 2bd99aef1b19 ("tcp: accept
bare FIN packets under memory pressure") to break tight FIN/ACK loops
caused by broken clients.
However, the condition added by commit 1e3bb184e941 ("tcp: re-enable
acceptance of FIN packets when RWIN is 0") is broader than required
and allows other non-compliant packets as well.
Tighten the tcp_sequence() FIN exception to only allow packets where
the packet is a bare in-order FIN and only the FIN flag extends beyond
tcp_max_receive_window(). In particular, this exception is only
reachable if tcp_max_receive_window() is zero. Otherwise the packet is
already accepted by the normal sequence check.
The existing packetdrill test tcp_rcv_zero_wnd_fin.pkt exercises this
behavior already and does not need to be changed.
Signed-off-by: Simon Baatz <gmbnomis@gmail.com>
---
net/ipv4/tcp_input.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index ab7a4e5435a8..1eddae246963 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -4812,18 +4812,21 @@ static enum skb_drop_reason tcp_sequence(const struct sock *sk,
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 (unlikely(after(end_seq, tp->rcv_nxt + tcp_max_receive_window(tp)))) {
- /* Some stacks are known to handle FIN incorrectly; allow the
- * FIN to extend beyond the window and check it in detail later.
+ seq_limit = tp->rcv_nxt + tcp_max_receive_window(tp);
+ if (unlikely(after(end_seq, seq_limit))) {
+ /* Some stacks are known to send bare FIN packets
+ * in a loop even if we send RWIN 0 in our ACK. Allow
+ * them here, they are handled later in tcp_data_queue().
*/
- if (!after(end_seq - th->fin, tp->rcv_nxt + tcp_receive_window(tp)))
+ if (seq == tp->rcv_nxt && end_seq - th->fin == tp->rcv_nxt)
return SKB_NOT_DROPPED_YET;
- if (after(seq, tp->rcv_nxt + tcp_max_receive_window(tp)))
+ if (after(seq, seq_limit))
return SKB_DROP_REASON_TCP_INVALID_SEQUENCE;
/* Only accept this packet if receive queue is empty. */
---
base-commit: 3abbe30231441f1fbb3305e9854c56a34650af53
change-id: 20260609-tcp_fin_more_restrictive-5bc808e87c6a
Best regards,
--
Simon Baatz <gmbnomis@gmail.com>
next reply other threads:[~2026-06-09 22:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-09 22:09 Simon Baatz via B4 Relay [this message]
2026-06-12 22:43 ` [PATCH net-next] tcp: tighten the FIN exception in tcp_sequence() Jakub Kicinski
2026-06-12 23:40 ` Simon Baatz
2026-06-13 3:47 ` Eric Dumazet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260610-tcp_fin_more_restrictive-v1-1-eefc30d7ddd8@gmail.com \
--to=devnull+gmbnomis.gmail.com@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gmbnomis@gmail.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox