* [PATCH v1 net] tcp: Correct wscale mismatch in tcp_acceptable_seq().
@ 2026-12-03 3:11 Kuniyuki Iwashima
2026-12-04 6:45 ` Jiayuan Chen
0 siblings, 1 reply; 2+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-03 3:11 UTC (permalink / raw)
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
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>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v1 net] tcp: Correct wscale mismatch in tcp_acceptable_seq().
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
0 siblings, 0 replies; 2+ messages in thread
From: Jiayuan Chen @ 2026-12-04 6:45 UTC (permalink / raw)
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
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);
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-04 6:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox