Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2874213rwb; Mon, 15 Aug 2022 13:04:53 -0700 (PDT) X-Google-Smtp-Source: AA6agR4MgYGTrz5Lfox2saazs0iNdV8WKseUOq9C6SHZRgcrQ2323ZTFgaei0EVaRaRPWybUwn4c X-Received: by 2002:a17:907:75e7:b0:730:9711:ad80 with SMTP id jz7-20020a17090775e700b007309711ad80mr11139731ejc.35.1660593893772; Mon, 15 Aug 2022 13:04:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660593893; cv=none; d=google.com; s=arc-20160816; b=Rm8aJIduPNItJhuEewif0dtEGssYcJkNXvYK3egsvxbb/mA908nqPbQ7ERVYyeFybL iMzA3csHJ2WCJYLQKE580125/y4fJjw5sGEHGeT7tJsquxkaUDB/FkEMz7S2G/Qv2G6z b3y1WbeEChkA3fz4NK9NU2w7GAJEUVjkIMdSqoOD05OreiQX8FDmDsq9BHdcBsZ4X7hr w/p6eL2F74FbBLIUzKdzctKqIb6YWh9VCugCOjAxG+8fZrKl9I0VlRaZ8RS03GkFhVw6 EDLtn/iFnappXwVT0PgnaCl02ET16nNLVTKmbZ6KBeg/p0VXN3XNnwd008k0U39tPvnX wyhQ== 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=F3H0v7t382zf5Nz8oaOWj/PVJrH3wyaJUvRh5lejaxY=; b=q9lgQJGYd/6aU95d2v2SG7NmoQz1EOMb6QLPPT0HwQG37bWStyh8VWg1wafvtJ4RCM Clay8J++s123EEvRgZKUHK5IsEIME9LXzDRiwg/dRlkmQEe77aXGbYBZEWKno3dJBvzc qqmrh0GWs9+LpxLWQW1eIFWavJUa2NC5q6Oj0IosTw0ymKzllu/vUKMWQvZ2XTgCIOpJ j2rZLj5Gu77KDsEf+BjizBRZZWAS8EnUcDuE97G820f3XSDN94dcPRXRXVMQgF/PjsFZ S/4kPQhgZ0uCbD3yJtduhz+rfOTygJTgxHO0cSgIaOcuVZhVljodfvnsgmTzwqv47z2A G8CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XGQbqhaU; 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 dd15-20020a1709069b8f00b007306645a7absi7636526ejc.849.2022.08.15.13.04.27; Mon, 15 Aug 2022 13:04:53 -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=XGQbqhaU; 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 S244739AbiHOS6k (ORCPT + 99 others); Mon, 15 Aug 2022 14:58:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244827AbiHOSz4 (ORCPT ); Mon, 15 Aug 2022 14:55:56 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B4136433; Mon, 15 Aug 2022 11:30:28 -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 ams.source.kernel.org (Postfix) with ESMTPS id B5E80B81084; Mon, 15 Aug 2022 18:30:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0499EC433B5; Mon, 15 Aug 2022 18:30:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660588225; bh=fLuLv2yh8AGC1FfcjmtGnEvVzIHF2InizORL1tbTmdo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XGQbqhaUACn34iY65BvZJKteGJeUIcKIdBNVyl/1iRVhO0VTVNtYTpz9VGHrIuBwh D5XZElQJppBXoFz1ltsJSpHGEZzPp/J7pfnE63BZoox2QfwKcWUivZaSo0UliRyivp Lu61pVPnTEJyEbbjYjyRHDP00rQxiuSoTKE6o4A4= 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.15 335/779] tcp: make retransmitted SKB fit into the send window Date: Mon, 15 Aug 2022 19:59:39 +0200 Message-Id: <20220815180351.597849976@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@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 9c9a0f7a3dee..24cadcdb9890 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -3145,7 +3145,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) @@ -3167,17 +3167,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)) @@ -3191,8 +3199,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