From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.95 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== 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== 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 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 ; Fri, 4 Dec 2026 06:46:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D242660A2613 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev 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-Envelope-To: netdev@vger.kernel.org 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 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 Message-ID: <878ced3d-0068-4e3a-9527-5f6fb9dcfee5@linux.dev> Date: Fri, 4 Dec 2026 14:45:58 +0800 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 net] tcp: Correct wscale mismatch in tcp_acceptable_seq(). To: Kuniyuki Iwashima , Eric Dumazet , Neal Cardwell , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Willem de Bruijn Cc: Simon Horman , "Cui, Cheng" , Kuniyuki Iwashima , netdev@vger.kernel.org References: <20261203031139.1898493-1-kuniyu@google.com> From: Jiayuan Chen In-Reply-To: <20261203031139.1898493-1-kuniyu@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 > +0 > S. 0:0(0) ack 1 > +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 Reviewed-by: Jiayuan Chen > --- > 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);