Skip to content

Commit 1e3bb18

Browse files
gmbnomiskuba-moo
authored andcommitted
tcp: re-enable acceptance of FIN packets when RWIN is 0
Commit 2bd99ae ("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 9ca48d6 ("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: 9ca48d6 ("tcp: do not accept packets beyond window") Signed-off-by: Simon Baatz <gmbnomis@gmail.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com> Link: https://patch.msgid.link/20260224-fix_zero_wnd_fin-v2-1-a16677ea7cea@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 5cc6195 commit 1e3bb18

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

net/ipv4/tcp_input.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4858,15 +4858,24 @@ static enum skb_drop_reason tcp_disordered_ack_check(const struct sock *sk,
48584858
*/
48594859

48604860
static enum skb_drop_reason tcp_sequence(const struct sock *sk,
4861-
u32 seq, u32 end_seq)
4861+
u32 seq, u32 end_seq,
4862+
const struct tcphdr *th)
48624863
{
48634864
const struct tcp_sock *tp = tcp_sk(sk);
4865+
u32 seq_limit;
48644866

48654867
if (before(end_seq, tp->rcv_wup))
48664868
return SKB_DROP_REASON_TCP_OLD_SEQUENCE;
48674869

4868-
if (after(end_seq, tp->rcv_nxt + tcp_receive_window(tp))) {
4869-
if (after(seq, tp->rcv_nxt + tcp_receive_window(tp)))
4870+
seq_limit = tp->rcv_nxt + tcp_receive_window(tp);
4871+
if (unlikely(after(end_seq, seq_limit))) {
4872+
/* Some stacks are known to handle FIN incorrectly; allow the
4873+
* FIN to extend beyond the window and check it in detail later.
4874+
*/
4875+
if (!after(end_seq - th->fin, seq_limit))
4876+
return SKB_NOT_DROPPED_YET;
4877+
4878+
if (after(seq, seq_limit))
48704879
return SKB_DROP_REASON_TCP_INVALID_SEQUENCE;
48714880

48724881
/* 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,
63796388

63806389
step1:
63816390
/* Step 1: check sequence number */
6382-
reason = tcp_sequence(sk, TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq);
6391+
reason = tcp_sequence(sk, TCP_SKB_CB(skb)->seq,
6392+
TCP_SKB_CB(skb)->end_seq, th);
63836393
if (reason) {
63846394
/* RFC793, page 37: "In all states except SYN-SENT, all reset
63856395
* (RST) segments are validated by checking their SEQ-fields."

0 commit comments

Comments
 (0)