Since commit b025461303d8 ("tcp: update window_clamp when SO_RCVBUF is set") SO_RCVBUF sets tp->window_clamp from the new buffer size in every socket state. For a socket without a connection this has a side effect. tcp_connect_init() and tcp_openreq_init_rwin() use the window metric of the route (RTAX_WINDOW, "ip route ... window N") only if window_clamp is zero. The clamp left behind by SO_RCVBUF makes the metric ineffective for that socket, or for the connections accepted on a listener. Example: two network namespaces connected by a veth pair, "window 4096" on the route to the peer on both sides, SO_RCVBUF set to 1 MiB before connect(): v7.3-rc6: SYN win 65535, wscale 5 TCP_WINDOW_CLAMP 1047128 with that commit reverted: SYN win 2920, no window scaling TCP_WINDOW_CLAMP 4096 With SO_RCVBUF set on the listener the SYN-ACK and the clamp of the accepted socket differ in the same way. The update is not needed in these states. When the connection is set up with SOCK_RCVBUF_LOCK set, both functions limit a zero or too large clamp to tcp_full_space(), which is the value tcp_set_rcvbuf() computes. Skip the update for sockets in TCP_CLOSE and TCP_LISTEN. Tested in qemu with the setup above. With the route metric, the SYN and SYN-ACK windows and TCP_WINDOW_CLAMP are the same as with the commit above reverted. Without the metric they are the same as before this change, with and without SO_RCVBUF on either side. Fixes: b025461303d8 ("tcp: update window_clamp when SO_RCVBUF is set") Assisted-by: LLM Signed-off-by: Shashank Mohan Jain --- Prepared with Claude Code (Anthropic), model Claude Opus 5.5 (claude-opus-5-5). net/ipv4/tcp.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 87ef6d5cbf..9b6f214411 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1856,6 +1856,14 @@ int tcp_set_rcvlowat(struct sock *sk, int val) void tcp_set_rcvbuf(struct sock *sk, int val) { + /* Without a connection there is no clamp to update: it is chosen + * from the route's window metric and the buffer size when the + * connection is set up, see tcp_connect_init() and + * tcp_openreq_init_rwin(). + */ + if ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) + return; + tcp_set_window_clamp(sk, tcp_win_from_space(sk, val)); } base-commit: a5ebb76233b79db01e82e061173cb73c6d2b5c6b -- 2.43.0