Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1996164pxp; Mon, 21 Mar 2022 09:09:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyblSnb6hJBL6sjBkXWtWQPSpvw/3ejTB1iDxOel0HHXj+/zF9gO/y8jc6ksZlb8dlXqE49 X-Received: by 2002:a54:4899:0:b0:2ef:3f6a:5a1e with SMTP id r25-20020a544899000000b002ef3f6a5a1emr6690865oic.296.1647878954246; Mon, 21 Mar 2022 09:09:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647878954; cv=none; d=google.com; s=arc-20160816; b=V+ZOlg6J5YF9xtN2/rbqNbrB2lhioETTZoIExjExCG2YXdMICtWbbGjpwb8Ul/E2cw +Ze/fzQX2nxQU4I5JBNNH7OIiksA/XIgqws6A1AYobe3sT1VyAtw1z/gTw4khvJ1tGTJ 16f0aMnrSmWSiUVmuOKs7+HgSPuAVxkZccYkDKMStvRYsbNfFHmlUzOk+LbZRlxeK4vZ HMw/2xYZgsH2V5JFBZI9H0pu7R/G0M9famrswK/9kul1D59rnfjfD1E4EqfB1EBx3R5J UoHvecTS0Ud0Wh6JYDEeNVS9BGpeVEMu1ctEYU/yD9YXK5dx8zsyUd3ZN1dZWT3pTOj9 j5/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Ziw5CJhDRZqUL3LNhkYQbYf/R/d1yl0g1A3sF/TdmjA=; b=iqw/ao5iOPsAIbnGGXOcjUNpmFq15i3sQKZB7fABAsjmXuWyBpIlMSWO/pNJ9VIF9R FpZUlP21F8ujP4AUkcrqovh6zYw4xDOiKALv6Xho7VkBTA6x0JGy0FweaqbO84bxmQlt taxUc641n/p4kAFzxovG9F1Po+ofKT90jEL0kI6TYN8yFdqVecSN+gT8/p3Jz4q2DpbZ 0l9JtwrHZYr8n8LicluM6Ab6rBW+jW2pVWX7nsn3QjfewyISD7YK6vmtBsTodq6ZrRKv po2hT0r6oA/4siT/p2xrMyHERnopyZFdUEdzZKptbIRB0G9soHZsbRra12bXDF3PA9IQ J3qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=WChYIdMi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v29-20020a4a245d000000b0032489f16abesi2690709oov.80.2022.03.21.09.09.01; Mon, 21 Mar 2022 09:09:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=WChYIdMi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242728AbiCSLGA (ORCPT + 99 others); Sat, 19 Mar 2022 07:06:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233854AbiCSLF5 (ORCPT ); Sat, 19 Mar 2022 07:05:57 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F07BA1A5; Sat, 19 Mar 2022 04:04:36 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id q1-20020a17090a4f8100b001c6575ae105so7143255pjh.0; Sat, 19 Mar 2022 04:04:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ziw5CJhDRZqUL3LNhkYQbYf/R/d1yl0g1A3sF/TdmjA=; b=WChYIdMiyOy6xX0u63bVHRUfpVCzFAXwqS+9h5yuM/drwScx59WS/SncuRNaeRQISK yvvdqpqxlGV0ptyKRugJNkIHjzXMZKRI/aR9ihLh7YQcHpgb9wJvsozf+klSItc+98ct JS5eFTqvi6VSrF1tgaCM9uoapsvulF8TtOem4mt4YCDNmHh1upoTtREiinCN4aC4px8P d1parz2XdFrr4iwDtyB0FN0bCLMNSK1IDJ74GLMBawKYUzpLeNxr08Jf/g9HWo0SlZol KRYq3yIb7Gp/daLisuXM80r7vQPa0/m3fgdjyZ6jSQq5mvD+mUxQU6wQvP4ZFmKgvjBR z+/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ziw5CJhDRZqUL3LNhkYQbYf/R/d1yl0g1A3sF/TdmjA=; b=fBa0cBbGpY53vOHbThsqlwNU+VXeYr6Nd8G2TeG1wMd72revvlE4ZeO0jpZEePj9Tb 8izd+I93keHpzmil60lN5A4KNmmcu/Our8igrG5ga6CrgW9qMdeuayR8mEyIyjpdYLxM GLyZBMzeuc+k9qEXJteFC87iRqUcUhQXnXvVFtplzwZ7M+jWSn5mKHuXvO2LwA+FJ9aq UTq2xkVmtZXvYnF7IeiYhvW4ao5OkZJ1w7Tlv72jRLjYzAT+2QPzb5/CJj4J5VW9lu4Y cb+o4QQMfAC5STzipizQ69PNJ8Cb+cbBDt0BCb+MjYBxrdAuN6cC1lnM5yxAIC8r1Kih +seA== X-Gm-Message-State: AOAM53357NdQUsOOg86xbMSz4hRzeRoWfpMBzZK6jZKOA5dEeMy4Njmw SSgWT0Wul3ytG0uuyP8jgDs= X-Received: by 2002:a17:902:ec87:b0:151:c3f3:ddd5 with SMTP id x7-20020a170902ec8700b00151c3f3ddd5mr3730347plg.154.1647687875848; Sat, 19 Mar 2022 04:04:35 -0700 (PDT) Received: from localhost.localdomain ([85.203.23.81]) by smtp.gmail.com with ESMTPSA id 2-20020a17090a034200b001bfc572d018sm10432001pjf.48.2022.03.19.04.04.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Mar 2022 04:04:35 -0700 (PDT) From: zhouzhouyi@gmail.com To: fw@strlen.de, edumazet@google.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Zhouyi Zhou , Wei Xu Subject: [PATCH v2] net:ipv4: send an ack when seg.ack > snd.nxt Date: Sat, 19 Mar 2022 19:04:22 +0800 Message-Id: <20220319110422.8261-1-zhouzhouyi@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhouyi Zhou In RFC 793, page 72: "If the ACK acks something not yet sent (SEG.ACK > SND.NXT) then send an ACK, drop the segment, and return." Fix Linux's behavior according to RFC 793. Reported-by: Wei Xu Signed-off-by: Wei Xu Signed-off-by: Zhouyi Zhou --- Thank Florian Westphal for pointing out the potential duplicated ack bug in patch version 1. -- net/ipv4/tcp_input.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index bfe4112e000c..4bbf85d7ea8c 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -3771,11 +3771,13 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag) goto old_ack; } - /* If the ack includes data we haven't sent yet, discard - * this segment (RFC793 Section 3.9). + /* If the ack includes data we haven't sent yet, then send + * an ack, drop this segment, and return (RFC793 Section 3.9 page 72). */ - if (after(ack, tp->snd_nxt)) - return -1; + if (after(ack, tp->snd_nxt)) { + tcp_send_ack(sk); + return -2; + } if (after(ack, prior_snd_una)) { flag |= FLAG_SND_UNA_ADVANCED; @@ -6385,6 +6387,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) struct request_sock *req; int queued = 0; bool acceptable; + int ret; switch (sk->sk_state) { case TCP_CLOSE: @@ -6451,14 +6454,16 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) return 0; /* step 5: check the ACK field */ - acceptable = tcp_ack(sk, skb, FLAG_SLOWPATH | - FLAG_UPDATE_TS_RECENT | - FLAG_NO_CHALLENGE_ACK) > 0; + ret = tcp_ack(sk, skb, FLAG_SLOWPATH | + FLAG_UPDATE_TS_RECENT | + FLAG_NO_CHALLENGE_ACK); + acceptable = ret > 0; if (!acceptable) { if (sk->sk_state == TCP_SYN_RECV) return 1; /* send one RST */ - tcp_send_challenge_ack(sk); + if (ret > -2) + tcp_send_challenge_ack(sk); goto discard; } switch (sk->sk_state) { -- 2.25.1