Skip to content

Commit 6d67543

Browse files
edumazetgregkh
authored andcommitted
tcp: take care of zero tp->window_clamp in tcp_set_rcvlowat()
[ Upstream commit 21b29e7 ] Some applications (like selftests/net/tcp_mmap.c) call SO_RCVLOWAT on their listener, before accept(). This has an unfortunate effect on wscale selection in tcp_select_initial_window() during 3WHS. For instance, tcp_mmap was negotiating wscale 4, regardless of tcp_rmem[2] and sysctl_rmem_max. Do not change tp->window_clamp if it is zero or bigger than our computed value. Zero value is special, it allows tcp_select_initial_window() to enable autotuning. Note that SO_RCVLOWAT use on listener is probably not wise, because tp->scaling_ratio has a default value, possibly wrong. Fixes: d136184 ("tcp: fix SO_RCVLOWAT and RCVBUF autotuning") Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com> Reviewed-by: Neal Cardwell <ncardwell@google.com> Link: https://patch.msgid.link/20251003184119.2526655-1-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent cdab92a commit 6d67543

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

net/ipv4/tcp.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1735,6 +1735,7 @@ EXPORT_SYMBOL(tcp_peek_len);
17351735
/* Make sure sk_rcvbuf is big enough to satisfy SO_RCVLOWAT hint */
17361736
int tcp_set_rcvlowat(struct sock *sk, int val)
17371737
{
1738+
struct tcp_sock *tp = tcp_sk(sk);
17381739
int space, cap;
17391740

17401741
if (sk->sk_userlocks & SOCK_RCVBUF_LOCK)
@@ -1753,7 +1754,9 @@ int tcp_set_rcvlowat(struct sock *sk, int val)
17531754
space = tcp_space_from_win(sk, val);
17541755
if (space > sk->sk_rcvbuf) {
17551756
WRITE_ONCE(sk->sk_rcvbuf, space);
1756-
WRITE_ONCE(tcp_sk(sk)->window_clamp, val);
1757+
1758+
if (tp->window_clamp && tp->window_clamp < val)
1759+
WRITE_ONCE(tp->window_clamp, val);
17571760
}
17581761
return 0;
17591762
}

0 commit comments

Comments
 (0)