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 <kuni…@google.com>
Reviewed-by: Jiayuan Chen <jiay…@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);