Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3122755rwb; Mon, 15 Aug 2022 18:41:09 -0700 (PDT) X-Google-Smtp-Source: AA6agR7SW3LpD2JB269B49f5l3TCSQ1/uXYP1HRJ4EG6X4h1p7kzOFV8YIiIc6/fUDyv4cg5pEpx X-Received: by 2002:a05:6402:28cb:b0:43b:c6d7:ef92 with SMTP id ef11-20020a05640228cb00b0043bc6d7ef92mr17119529edb.333.1660614069443; Mon, 15 Aug 2022 18:41:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660614069; cv=none; d=google.com; s=arc-20160816; b=oEpP3WEHpyRbRzGjaiv4mQ99WEv+wMxsdiriuYPjYBw/OjaLNDZwclbMIysxXbNiud RYsNi+imv6AQ+gr+FIudp63hkdHVPeWvDiGWRJ+7IUFSWMgg5bI/xgav2xu4BczTSyiF 8eljUT1uP1qEdpW8IWrMqN59NTQ8Ll6vsMHTdUoIlzDqVdXOGH2dcBsBeXMsnJZ38OXj dJu21814vspKMuAvYB8Bfq4GMDeGu5KtfLacPR1tKoB0U0rwFHcZ3jNeUMFyiEwQjfeg OGcaytvymTAKwhb2x/UgaTM9G4WQshEfhWAji3IFqbK+2J0tWIEQA9Tc36+GVHobQ/lC W/rg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lmyYnF9JcXe2kCbFIc1PR2fGBFYpHcHbifd7UMdhY78=; b=kPAhmhD/6U5aqiatkOshcZc+vGQecR2lAJKD336zC19lj0iRtaZPYlPGaQtnn9TLFj i5PCa2OOWd1x0oQq7cO6NiLURuOaHYX2Ap6Beuw6xEBFisaMdC841Tycr0FB29yjZhh3 QloqU7U/rTPStLIX83zsrATUvenWMumFjwvkiYkZSdp5Njm/jTDUNlDxhIfRoA1dNpqU Q3+LQIXtgCQFFnjkAaw1m9NMSFLMeEbtvp5qxQdKoafhoQX9Dn3m4PLyDipaDpJASPv/ nd/8VnV8fERtnknVM6XP+5xFUeQdjklCUpxp+1nQOeucao33iOozeTY8SfRfGex61rGP ro2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LFHV0suo; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z26-20020aa7cf9a000000b0043cdb04b9f1si7228869edx.411.2022.08.15.18.40.44; Mon, 15 Aug 2022 18:41:09 -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=@linuxfoundation.org header.s=korg header.b=LFHV0suo; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234020AbiHOX4t (ORCPT + 99 others); Mon, 15 Aug 2022 19:56:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355090AbiHOXv1 (ORCPT ); Mon, 15 Aug 2022 19:51:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99D9184EF5; Mon, 15 Aug 2022 13:16:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E2F4A60F17; Mon, 15 Aug 2022 20:16:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8FCBC433C1; Mon, 15 Aug 2022 20:16:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660594578; bh=ajPxIQ9KfrZmhP73PqXnCWiAJ9Ydva+t3i73ZM8kKfE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LFHV0suoC1AhDcl7OR4o4TvFN1dLgogPfg41HXQXSYZ6Sd/WNBJKBaRr5Vro8eBVK htU4Ht+IU1szQuQdRNiuhRhz+9SZkZj/ECEgo8UiusNxFntvTBd/2C6BWIqN7PWkTI J2fAXlx7FPq6k269XAVU6ZmpB58eqi4JKuquGWu8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yonglong Li , Eric Dumazet , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.19 0493/1157] tcp: make retransmitted SKB fit into the send window Date: Mon, 15 Aug 2022 19:57:29 +0200 Message-Id: <20220815180459.368689561@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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: Yonglong Li [ Upstream commit 536a6c8e05f95e3d1118c40ae8b3022ee2d05d52 ] current code of __tcp_retransmit_skb only check TCP_SKB_CB(skb)->seq in send window, and TCP_SKB_CB(skb)->seq_end maybe out of send window. If receiver has shrunk his window, and skb is out of new window, it should retransmit a smaller portion of the payload. test packetdrill script: 0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3 +0 fcntl(3, F_GETFL) = 0x2 (flags O_RDWR) +0 fcntl(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0 +0 connect(3, ..., ...) = -1 EINPROGRESS (Operation now in progress) +0 > S 0:0(0) win 65535 +.05 < S. 0:0(0) ack 1 win 6000 +0 > . 1:1(0) ack 1 +0 write(3, ..., 10000) = 10000 +0 > . 1:2001(2000) ack 1 win 65535 +0 > . 2001:4001(2000) ack 1 win 65535 +0 > . 4001:6001(2000) ack 1 win 65535 +.05 < . 1:1(0) ack 4001 win 1001 and tcpdump show: 192.168.226.67.55 > 192.0.2.1.8080: Flags [.], seq 1:2001, ack 1, win 65535, length 2000 192.168.226.67.55 > 192.0.2.1.8080: Flags [.], seq 2001:4001, ack 1, win 65535, length 2000 192.168.226.67.55 > 192.0.2.1.8080: Flags [P.], seq 4001:5001, ack 1, win 65535, length 1000 192.168.226.67.55 > 192.0.2.1.8080: Flags [.], seq 5001:6001, ack 1, win 65535, length 1000 192.0.2.1.8080 > 192.168.226.67.55: Flags [.], ack 4001, win 1001, length 0 192.168.226.67.55 > 192.0.2.1.8080: Flags [.], seq 5001:6001, ack 1, win 65535, length 1000 192.168.226.67.55 > 192.0.2.1.8080: Flags [P.], seq 4001:5001, ack 1, win 65535, length 1000 when cient retract window to 1001, send window is [4001,5002], but TLP send 5001-6001 packet which is out of send window. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Yonglong Li Signed-off-by: Eric Dumazet Link: https://lore.kernel.org/r/1657532838-20200-1-git-send-email-liyonglong@chinatelecom.cn Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/ipv4/tcp_output.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 4c376b6d8764..ec9a4f621703 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -3142,7 +3142,7 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs) struct tcp_sock *tp = tcp_sk(sk); unsigned int cur_mss; int diff, len, err; - + int avail_wnd; /* Inconclusive MTU probe */ if (icsk->icsk_mtup.probe_size) @@ -3164,17 +3164,25 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs) return -EHOSTUNREACH; /* Routing failure or similar. */ cur_mss = tcp_current_mss(sk); + avail_wnd = tcp_wnd_end(tp) - TCP_SKB_CB(skb)->seq; /* If receiver has shrunk his window, and skb is out of * new window, do not retransmit it. The exception is the * case, when window is shrunk to zero. In this case - * our retransmit serves as a zero window probe. + * our retransmit of one segment serves as a zero window probe. */ - if (!before(TCP_SKB_CB(skb)->seq, tcp_wnd_end(tp)) && - TCP_SKB_CB(skb)->seq != tp->snd_una) - return -EAGAIN; + if (avail_wnd <= 0) { + if (TCP_SKB_CB(skb)->seq != tp->snd_una) + return -EAGAIN; + avail_wnd = cur_mss; + } len = cur_mss * segs; + if (len > avail_wnd) { + len = rounddown(avail_wnd, cur_mss); + if (!len) + len = avail_wnd; + } if (skb->len > len) { if (tcp_fragment(sk, TCP_FRAG_IN_RTX_QUEUE, skb, len, cur_mss, GFP_ATOMIC)) @@ -3188,8 +3196,9 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs) diff -= tcp_skb_pcount(skb); if (diff) tcp_adjust_pcount(sk, skb, diff); - if (skb->len < cur_mss) - tcp_retrans_try_collapse(sk, skb, cur_mss); + avail_wnd = min_t(int, avail_wnd, cur_mss); + if (skb->len < avail_wnd) + tcp_retrans_try_collapse(sk, skb, avail_wnd); } /* RFC3168, section 6.1.1.1. ECN fallback */ -- 2.35.1