Skip to content

Commit f4a3313

Browse files
edumazetdavem330
authored andcommitted
tcp: avoid collapses in tcp_prune_queue() if possible
Right after a TCP flow is created, receiving tiny out of order packets allways hit the condition : if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) tcp_clamp_window(sk); tcp_clamp_window() increases sk_rcvbuf to match sk_rmem_alloc (guarded by tcp_rmem[2]) Calling tcp_collapse_ofo_queue() in this case is not useful, and offers a O(N^2) surface attack to malicious peers. Better not attempt anything before full queue capacity is reached, forcing attacker to spend lots of resource and allow us to more easily detect the abuse. Signed-off-by: Eric Dumazet <[email protected]> Acked-by: Soheil Hassas Yeganeh <[email protected]> Acked-by: Yuchung Cheng <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 72cd43b commit f4a3313

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

net/ipv4/tcp_input.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5004,6 +5004,9 @@ static int tcp_prune_queue(struct sock *sk)
50045004
else if (tcp_under_memory_pressure(sk))
50055005
tp->rcv_ssthresh = min(tp->rcv_ssthresh, 4U * tp->advmss);
50065006

5007+
if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf)
5008+
return 0;
5009+
50075010
tcp_collapse_ofo_queue(sk);
50085011
if (!skb_queue_empty(&sk->sk_receive_queue))
50095012
tcp_collapse(sk, &sk->sk_receive_queue, NULL,

0 commit comments

Comments
 (0)