Article View: linux.kernel.netdev
Article #26784Re: [PATCH v1 net] tcp: Correct wscale mismatch in tcp_acceptable_seq().
From: Jiayuan Chen
Date: Fri, 04 Dec 2026 06:45
Date: Fri, 04 Dec 2026 06:45
73 lines
10882 bytes
10882 bytes
On 12/3/26 11:11 AM, Kuniyuki Iwashima wrote:
> tcp_acceptable_seq() returns SEQ for ACK or RST.
>
> Before the cited commit, when tcp_wnd_end() is smaller than
> tp->snd_nxt, it thinks the window size is shrunk and returned
> tcp_wnd_end() instead of tp->snd_nxt.
>
> However, with Window Scaling, the peer's buffer size could look
> smaller than actual, e.g. with wscale=7, 1000 bytes is advertised
> as 896 bytes ((1000 >> 7) << 7).
>
> So, the cited commit started to return tp->snd_nxt when
> tp->snd_nxt - tcp_wnd_end(tp) is smaller than 1 scaled value.
>
> But it used tp->rx_opt.rcv_wscale, which is the host's wscale
> instead of the peer's wscale, tp->rx_opt.snd_wscale.
>
> This results in ACK/RST with left-shifted SEQ if the peer's
> wscale is larger, or out-of-bound SEQ if the peer's wscale
> is smaller, triggering challenge ACK.
>
> Let's use the peer's wscale.
>
> This can be reproduced with the following script.
>
> --strict_segments
> 0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
> +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
> +0 setsockopt(3, SOL_TCP, 10, [65535], 4) = 0 // TCP_WINDOW_CLAMP
> +0 bind(3, ..., ...) = 0
> +0 listen(3, 1) = 0
> +.1 < S 0:0(0) win 32768 <mss 1000,nop,wscale 7>
> +0 > S. 0:0(0) ack 1 <mss 1440,nop,wscale 0>
> +0 < . 1:1(0) ack 1 win 100
> +.1 accept(3, ..., ...) = 4
> +.1 write(4, ..., 1000) = 1000
> +0 > P. 1:1001(1000) ack 1
> +.1 write(4, ..., 1000) = 1000
> +0 > P. 1001:2001(1000) ack 1
> +.1 < P. 1:2(1) ack 1001 win 7
> +0 > . 1897:1897(0) ack 2
>
> Without the patch, the last ACK is sent with SEQ being 1897,
> which should be 2001.
>
> Fixes: a4ecb15a2432 ("tcp: accommodate sequence number to a peer's shrunk receive window caused by precision loss in window scaling")
> Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Jiayuan Chen <jiayuan.chen@linux.dev>
> ---
> Found by LLM w/ packetdrill
> ---
> net/ipv4/tcp_output.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
> index cf3ddc055d48..80d6369fd682 100644
> --- a/net/ipv4/tcp_output.c
> +++ b/net/ipv4/tcp_output.c
> @@ -116,7 +116,7 @@ static inline __u32 tcp_acceptable_seq(const struct sock *sk)
>
> if (!before(tcp_wnd_end(tp), tp->snd_nxt) ||
> (tp->rx_opt.wscale_ok &&
> - ((tp->snd_nxt - tcp_wnd_end(tp)) < (1 << tp->rx_opt.rcv_wscale))))
> + ((tp->snd_nxt - tcp_wnd_end(tp)) < (1 << tp->rx_opt.snd_wscale))))
> return tp->snd_nxt;
> else
> return tcp_wnd_end(tp);
Technical Details
Message-ID:
<878ced3d-0068-4e3a-9527-5f6fb9dcfee5@linux.dev>Path:
mbox-mo1.pugleaf.net!news-fra.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ro.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377123-linux-kernel-netdev=dewy.ruReferences:
<20261203031139.1898493-1-kuniyu@google.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-fra.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ro.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377123-linux-kernel-netdev=dewy.ru From: jiayuan.chen@linux.dev (Jiayuan Chen) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH v1 net] tcp: Correct wscale mismatch in tcp_acceptable_seq(). Date: Fri, 4 Dec 2026 14:45:58 +0800 Organization: Usenet Network Message-ID: <878ced3d-0068-4e3a-9527-5f6fb9dcfee5@linux.dev> References: <20261203031139.1898493-1-kuniyu@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="2695535"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:8wj4BEIYFAuWFu8U/SjuZIiC5E8= sha256:rABA5HUH6wDV+e/flUjimoUhGFw5CtU6C8KWKSNzTSg= sha1:yIxUVkGFRyYCWSHl8zUJI4hpYYc= sha256:mYhiK6OPBBiAk6i5C+4OvB9gcFqmsTZEt2ZgD3Uxy9Q= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id C3318117B35; Fri, 4 Dec 2026 09:46:37 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -2.399 X-Spam-Status: No, score=-2.399 tagged_above=-9999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.001, HK_RANDOM_FROM=0.999, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key) header.d=linux.dev X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id O4I_L4hGGVB0; Fri, 4 Dec 2026 09:46:34 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-377123-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id D74B4117B2B; Fri, 4 Dec 2026 09:46:25 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 8B6FA27390; Fri, 4 Dec 2026 06:46:21 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796366767; b=Zkwa38oxXmNkIGzzyIkGV4YB01KgDKep19RZNlAjikyWBmAXDJHhrI1pZqElUVnoT+dS eT12YD1XN02aHPNeFa5Gsx0Ahj/w7waoHW1awmHCSrtco/BuOCSZz6JH+yh6kpASurMuK +IBor8IhWDP33nuT+3WmI8Ht2nDfcLqJfAcTq4p5LZrVAjVEERTe+5Fj26pGRkfLpgRAK g7EYl8bqFhsltofteYadsSSWmF/T7AQMup7dyUtGKRQTUHlnKWGtAcSh+CTwjRSAetdC5 zYSX+MuEemWv9bWAQl8NAE071yCis9tSeh5QKQJvOMNeaT7KrKilqiTajH6QaV2UaZQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796366767; h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature: X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:User-Agent: Subject:To:Cc:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=hocDdNrqnfTSLj9SGjAauayVXHJBZL6pcq6kz+hDXGY=; b=5ghBjI2jfIkL8yM0LWBYA68/T/lwxqws7W7x9JECAWdGkGSidUxw6OTi4qUueiHZmIgk I93XrUH5x+YlE8Ck8W5lShOky+BibaO5J6b6idgKnQ+sSB6BmTI68ENoxxV73cMql4LQp p7CAzwihfp6BIyrOePZw8NVAOhjVquX9nJ4pS1+Q1nkVunHjW+4WnCPdkaYxmus0IRB9u i0CS0i0txnT3BaspkbN0XQtSxyoItsR/6pGsCGZGFVneLxlSd5lTGH8qiC+mVRTtHWxem WmYWuMz1Jz8l7DtwZGnligKmY/BvHjWS6bSOE6is6ipvszeVfeXrWKEnOvx7476fNTQ== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=at6KvcTP; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 61A8B60A261D; Fri, 4 Dec 2026 06:46:07 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=at6KvcTP X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.95 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796366766; b=DBPGDRqgg92iZAf+xZwQS6OEM7Zm8Gq2ZydwA97ndlNwfPv6oXnmAMmiInptM5chZZLm AOd2QONujjtSA1wcVg26PCcfnCQk1ZshFdPrYj8ixmHXTmj98/xftCS1HgtlQrEnqYIvz z/a38rJw17aD99DfYan/RBkDdYdmFDCQ2Lbg1iWGxPyOKHMZrSaBmIpsEexRzEpgR8PLU A1sikFkN4EgUhCgEvOUBXJ01r3X+zubv/vr9+NZ88muxOZPi4KD+slEaCtldpf5p4j/tW W3lVXcSJ6aVuPPHJAO0KrCkhKorchRADBWWFlOMSlAf7A+3Rf8Qc+ES0RA7EFx2Kr7Q== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796366766; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=hocDdNrqnfTSLj9SGjAauayVXHJBZL6pcq6kz+hDXGY=; b=gOJ67DVS9p5GgpzjoC5SHrShY2sBLMfKny3/U/VG4FgnP6iFyOnJQkIQtTH7nWWuuxOJ dvFTYBwWiX3X7m+7SFzCIFGruUA5Ijdj6ArNlh89HkSn9flwbYhFKhDVjAqtro6pbVdgj drti0NxoWEBuWk6Kj7XLyI9e1/VfSJsWUUEVHLv/+MjT9F+RbsXWma88RBRszti01/gdo 8V5hb4G1D7RGalt0Biukc12NeFCUIbzR0yczydjgE8dkP/0p4Jjs7rhbKYQ6mB5dxG6eM 6PcWkm2gYV08Nxlure2kvLKMotFn697Si2QM7sDR3o4vNyNNxwogkXg0jABl8f/URHA== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=at6KvcTP; arc=none smtp.remote-ip=91.218.175.95 X-Received: from mta0.migadu.com (out-95.mta0.migadu.com [91.218.175.95]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D242660A2613 for <netdev@vger.kernel.org>; Fri, 4 Dec 2026 06:46:05 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D242660A2613 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: netdev@vger.kernel.org X-DKIM-Signature: a=rsa-sha256; bh=AC4EoWGWUoF3/zHb0ihvLyG+n1hlcrW3NUZvirMayC4=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796366763; v=1; x=1796971563; b=at6KvcTPb82Ng5yaeAsUiWtUfLj62SbW8uo/zJ6bHRf+AE+tcFyzgWsBEIDbtGbx/1fuSQ0O TKWdWQ1mXlqp4+I21UgeT4w70NupqBQa+SipMTmPfcpBUmx30abROPjjDXebLudZyukTou/4Cq1 RGkMndfcVeGpttpKIYB62Ac4= X-Envelope-To: netdev@vger.kernel.org X-Received: by smtp.migadu.com with ESMTPS id 87bece627aa10dca; Fri, 04 Dec 2026 06:46:03 +0000 X-Mizu-Trace-ID: 87bece627aa10dca X-Migadu-Flow: FLOW_OUT X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-User-Agent: Mozilla Thunderbird X-Cc: Simon Horman <horms@kernel.org>, "Cui, Cheng" <Cheng.Cui@netapp.com>, Kuniyuki Iwashima <kuni1840@gmail.com>, netdev@vger.kernel.org X-In-Reply-To: <20261203031139.1898493-1-kuniyu@google.com>