tcp_rcvbuf_grow() and mptcp_rcvbuf_grow() compute growth terms in u64 but accumulate the predicted receive window in u32. The prediction can wrap before conversion to a memory budget and application of tcp_rmem[2]. For example, oldval=16 KiB and newval=4104 KiB produce a slow-start window prediction of 4 GiB + 8 MiB. Storing it in u32 leaves only 8 MiB, so the memory limit is applied to an already truncated prediction. Keep rcvwin in u64 and promote newval before the initial shift. Clamp the completed prediction at INT_MAX before passing it to the existing int-input window-to-memory helpers. Since scaling_ratio is a nonzero u8, the required memory is at least as large as the window. Predictions above INT_MAX therefore already require a saturated receive budget. The helpers' return saturation and the existing tcp_rmem[2] limit then provide the appropriate memory bound. TCP and MPTCP loopback tests using small warm-up reads followed by a queued burst of about 4 MiB previously left the budget below the configured 64 MiB limit. With this change, both reach that limit. Fixes: aa251c84636c ("tcp: fix too slow tcp_rcvbuf_grow() action") Signed-off-by: lllei --- net/ipv4/tcp_input.c | 11 ++++++----- net/mptcp/protocol.c | 9 +++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index a2074a1af..6d5950dbe 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -940,9 +940,9 @@ void tcp_rcvbuf_grow(struct sock *sk, u32 newval) { const struct net *net = sock_net(sk); struct tcp_sock *tp = tcp_sk(sk); - u32 rcvwin, rcvbuf, cap, oldval; + u32 rcvbuf, cap, oldval; u32 rtt_threshold, rtt_us; - u64 grow; + u64 rcvwin, grow; oldval = tp->rcvq_space.space; tp->rcvq_space.space = newval; @@ -952,7 +952,7 @@ void tcp_rcvbuf_grow(struct sock *sk, u32 newval) return; /* DRS is always one RTT late. */ - rcvwin = newval << 1; + rcvwin = (u64)newval << 1; rtt_us = tp->rcv_rtt_est.rtt_us >> 3; rtt_threshold = READ_ONCE(net->ipv4.sysctl_tcp_rcvbuf_low_rtt); @@ -961,10 +961,10 @@ void tcp_rcvbuf_grow(struct sock *sk, u32 newval) * It might take few additional ms to reach 'line rate', * but will avoid sk_rcvbuf inflation and poor cache use. */ - grow = div_u64((u64)rcvwin * rtt_us, rtt_threshold); + grow = div_u64(rcvwin * rtt_us, rtt_threshold); } else { /* slow start: allow the sender to double its rate. */ - grow = div_u64(((u64)rcvwin << 1) * (newval - oldval), oldval); + grow = div_u64((rcvwin << 1) * (newval - oldval), oldval); } rcvwin += grow; @@ -973,6 +973,7 @@ void tcp_rcvbuf_grow(struct sock *sk, u32 newval) cap = READ_ONCE(net->ipv4.sysctl_tcp_rmem[2]); + rcvwin = min_t(u64, rcvwin, INT_MAX); rcvbuf = min_t(u32, tcp_space_from_win(sk, rcvwin), cap); if (rcvbuf > sk->sk_rcvbuf) { WRITE_ONCE(sk->sk_rcvbuf, rcvbuf); diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 8968db580..b3b979403 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -216,8 +216,8 @@ static bool mptcp_rcvbuf_grow(struct sock *sk, u32 newval) { struct mptcp_sock *msk = mptcp_sk(sk); const struct net *net = sock_net(sk); - u32 rcvwin, rcvbuf, cap, oldval; - u64 grow; + u32 rcvbuf, cap, oldval; + u64 rcvwin, grow; oldval = msk->rcvq_space.space; msk->rcvq_space.space = newval; @@ -226,15 +226,16 @@ static bool mptcp_rcvbuf_grow(struct sock *sk, u32 newval) return false; /* DRS is always one RTT late. */ - rcvwin = newval << 1; + rcvwin = (u64)newval << 1; /* slow start: allow the sender to double its rate. */ - grow = (u64)rcvwin * (newval - oldval); + grow = rcvwin * (newval - oldval); do_div(grow, oldval); rcvwin += grow << 1; cap = READ_ONCE(net->ipv4.sysctl_tcp_rmem[2]); + rcvwin = min_t(u64, rcvwin, INT_MAX); rcvbuf = min_t(u32, mptcp_space_from_win(sk, rcvwin), cap); if (rcvbuf > sk->sk_rcvbuf) { WRITE_ONCE(sk->sk_rcvbuf, rcvbuf); -- 2.43.0