Netdev List
 help / color / mirror / Atom feed
From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: Kuniyuki Iwashima <kuniyu@google.com>,
	Eric Dumazet <edumazet@kernel.org>,
	Neal Cardwell <ncardwell@google.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Willem de Bruijn <willemb@google.com>
Cc: Simon Horman <horms@kernel.org>,
	"Cui, Cheng" <Cheng.Cui@netapp.com>,
	Kuniyuki Iwashima <kuni1840@gmail.com>,
	netdev@vger.kernel.org
Subject: Re: [PATCH v1 net] tcp: Correct wscale mismatch in tcp_acceptable_seq().
Date: Fri, 4 Dec 2026 14:45:58 +0800	[thread overview]
Message-ID: <878ced3d-0068-4e3a-9527-5f6fb9dcfee5@linux.dev> (raw)
In-Reply-To: <20261203031139.1898493-1-kuniyu@google.com>



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);


      reply	other threads:[~2026-12-04  6:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  3:11 [PATCH v1 net] tcp: Correct wscale mismatch in tcp_acceptable_seq() Kuniyuki Iwashima
2026-12-04  6:45 ` Jiayuan Chen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878ced3d-0068-4e3a-9527-5f6fb9dcfee5@linux.dev \
    --to=jiayuan.chen@linux.dev \
    --cc=Cheng.Cui@netapp.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuni1840@gmail.com \
    --cc=kuniyu@google.com \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox