From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.198 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796267503; b=2keVZuIxP7THbstkxu7ds8pJidkouWtfo7EgvRS90GzVvhGTgmb8yM2Ovt5SG8TKevJk 2A2n+Fqj9bTL2CnljuEyrXzHbiybvDgCd0VdhfqBq+ryGinblYYRyKCFkOsXuF5ZdtiVD HBgknaWCxnq+aLCQyuJOZDShTRubIg21tHAQM17rMjXM81LLc0FRMUInALUMeSdMRk2Tf MwgU9etaAjctEWmy420OOCu9PO6QcpFsOjmc6p+XtBPTgRzalhm+MhwD2HmZQ24d/YsMV G4kMkMbMH6wJ7aLDBFdiID27Z1fc77r2pcqPpx9Fdvb+zvOo0ZZ9oRgrLh3LAaKXk+g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796267503; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:Mime-Version: X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=tDUHc0ahwcM/muhHc9+FV61XmGgk3kdwI2T3eK+ULVo=; b=eTeE/WK7FBIf8bWK3HZ08eFG33S9Ck8RDZwAUI+obZA4wf1oH/nuHO/26AFPU6Dyvxgv bKwO2KOcLnSydb2LV0hW5+nwQumj+jP0XWQSfBHF0LcQmOJk+WjXWCnFYVBMh41DduWt3 AAhaxY4jDLP70eEMzDphiZHpDxXs4sF6jiXbTPbVwkFpr2DXgiXZxijh+bqy6+FLq6MV/ ZckzVmZwP4HWqVmwIQugWPAJzX5Lgx0i9BNDTcdCFrR/5DXoFzGZ0rt+hwDcl1xJdWP5T HE+sbgCSbvPYaF8Tgp0w/IWvnS7dYERnjIdhkMxpChS4QOfoOlzMCFHj/47bYKmePGA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--kuniyu.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=jQ2CfFku; arc=none smtp.remote-ip=209.85.215.198 Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) (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 74DC2606A322 for ; Thu, 3 Dec 2026 03:11:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 74DC2606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kuniyu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=jQ2CfFku Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-cddf142187aso7657874a12.2 for ; Wed, 02 Dec 2026 19:11:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796267502; x=1796872302; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=tDUHc0ahwcM/muhHc9+FV61XmGgk3kdwI2T3eK+ULVo=; b=jQ2CfFkuP0ku20MzJnHvIqZGQKFx0j/mKJ1SUFOTHfK/BRKckZG3l+L3lIoFnOkBxP zwV1tAG8KTiDjJ6G7eRG8EmZVlx7Z0j6qArCns9lnnVo89A0yOdIQXVB4YIcfR9ipsxC CFchHs79038xv6MQpT/0cvTMPQ5G1qs+cRBtPwU7icukeGO7cCvsMqoYY45/DMfe9/we nL58fREOOrCW40SXtufnTKaEVXBSKAiU6YWTnslQEUKx7FQAmOEBqTZgVHdW05Z0RfcL T4WgZvEaMKbcLj4yVzRarWwqrT6WqSKY7KU7NDKb02gRFaPE0f/FHjpd7ekdPYPuo+b0 7iSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796267502; x=1796872302; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=tDUHc0ahwcM/muhHc9+FV61XmGgk3kdwI2T3eK+ULVo=; b=oLqIGWcBZGiLhkr7Yb2LpD7RJzLb4IDe62uE53IpMcl/kpLclSwoCItSbIYAR6T3W1 GHwKwR/549v0ZEp7aIYwn8Rb5ne2P5wR23g03BMbptP1fWjJ3iY5eg4/22NHstV62xWv Wm3eSAhL+OJIH93uvRpRnRP7g5UWXyjLvAHI8HuqFrb1gKL2pvC3kbQQdfxoXaKbsfCr Iq47vwNCBz8fbsDHKFy4kinwb57ZzFPoObrAHk3fHgMDgrf+JK9Myw3L785qfBWuqJ0d +SdBSP0fqfvSxbkMWXSc8nIIzN1RpyrJpeSyO1f4z2p3TTvYeuaLjnQ8G5xSXxJ2Wx/E c7BQ== X-Forwarded-Encrypted: i=1; AL+hErECgiMZE1MMFuHxXPFLbVyzFLPdLb8L1du0SoYjVZEKsmx9s4hjJMiOi09TEOBSOjgpISqkwu8=@vger.kernel.org X-Gm-Message-State: APuU4Z/AZ+PfN7FyrAd+0IQ+sym91Qw3gdajLE6HiUGCSsvtSgqO5IrR AZLWrZCwCS7hBV3jbE/XpFvXKaFDnEpRhnh6A5HWmJB2so5AETGimY87QWgdIrQ85dPXjJ0Nyl8 xw3t7hQ== X-Received: from plbla13.prod.google.com ([2002:a17:902:fa0d:b0:2f0:cf6f:8311]) (user=kuniyu job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:178e:b0:2f1:9311:2da0 with SMTP id d9443c01a7336-2f193112e1fmr10446285ad.65.1796267502356; Wed, 02 Dec 2026 19:11:42 -0800 (PST) Date: Thu, 3 Dec 2026 12:11:15 +0900 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 X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog Message-ID: <20261203031139.1898493-1-kuniyu@google.com> Subject: [PATCH v1 net] tcp: Correct wscale mismatch in tcp_acceptable_seq(). From: Kuniyuki Iwashima To: Eric Dumazet , Neal Cardwell , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Willem de Bruijn Cc: Simon Horman , "Cui, Cheng" , Kuniyuki Iwashima , Kuniyuki Iwashima , netdev@vger.kernel.org Content-Type: text/plain; charset="UTF-8" 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 --- 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); -- 2.56.1.911.g883d8bcb20-goog