__tcp_space_from_win() computes a receive-memory requirement in u64 but returns int. A result above INT_MAX can therefore become negative or wrap to a smaller positive value before the caller compares or limits it. TCP and MPTCP SO_RCVLOWAT handling compare this result with sk_rcvbuf. They can accept a large low watermark without increasing the receive budget because the truncated requirement appears smaller than the existing buffer. Receive autotuning uses the same conversion helper. Saturate the u64 result at INT_MAX before returning it. This matches the int type of sk_rcvbuf and preserves the value and rounding of every representable result. TCP and MPTCP loopback tests with tcp_rmem[2]=INT_MAX and SO_RCVLOWAT=INT_MAX/2 reproduce the missed update after learning a scaling ratio below 128. With this change, both budgets reach INT_MAX. Fixes: dfa2f0483360 ("tcp: get rid of sysctl_tcp_adv_win_scale") Signed-off-by: lllei --- include/net/tcp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 5c9203aae..09827f1ae 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -1799,7 +1799,7 @@ static inline int __tcp_space_from_win(u8 scaling_ratio, int win) u64 val = (u64)win << TCP_RMEM_TO_WIN_SCALE; do_div(val, scaling_ratio); - return val; + return min_t(u64, val, INT_MAX); } static inline int tcp_space_from_win(const struct sock *sk, int win) -- 2.43.0