aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/tcp_input.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/ipv4/tcp_input.c')
-rw-r--r--net/ipv4/tcp_input.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 6bade06aaf72..64e45b279431 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -4942,6 +4942,7 @@ new_range:
4942 * 2) not add too big latencies if thousands of packets sit there. 4942 * 2) not add too big latencies if thousands of packets sit there.
4943 * (But if application shrinks SO_RCVBUF, we could still end up 4943 * (But if application shrinks SO_RCVBUF, we could still end up
4944 * freeing whole queue here) 4944 * freeing whole queue here)
4945 * 3) Drop at least 12.5 % of sk_rcvbuf to avoid malicious attacks.
4945 * 4946 *
4946 * Return true if queue has shrunk. 4947 * Return true if queue has shrunk.
4947 */ 4948 */
@@ -4949,20 +4950,26 @@ static bool tcp_prune_ofo_queue(struct sock *sk)
4949{ 4950{
4950 struct tcp_sock *tp = tcp_sk(sk); 4951 struct tcp_sock *tp = tcp_sk(sk);
4951 struct rb_node *node, *prev; 4952 struct rb_node *node, *prev;
4953 int goal;
4952 4954
4953 if (RB_EMPTY_ROOT(&tp->out_of_order_queue)) 4955 if (RB_EMPTY_ROOT(&tp->out_of_order_queue))
4954 return false; 4956 return false;
4955 4957
4956 NET_INC_STATS(sock_net(sk), LINUX_MIB_OFOPRUNED); 4958 NET_INC_STATS(sock_net(sk), LINUX_MIB_OFOPRUNED);
4959 goal = sk->sk_rcvbuf >> 3;
4957 node = &tp->ooo_last_skb->rbnode; 4960 node = &tp->ooo_last_skb->rbnode;
4958 do { 4961 do {
4959 prev = rb_prev(node); 4962 prev = rb_prev(node);
4960 rb_erase(node, &tp->out_of_order_queue); 4963 rb_erase(node, &tp->out_of_order_queue);
4964 goal -= rb_to_skb(node)->truesize;
4961 tcp_drop(sk, rb_to_skb(node)); 4965 tcp_drop(sk, rb_to_skb(node));
4962 sk_mem_reclaim(sk); 4966 if (!prev || goal <= 0) {
4963 if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf && 4967 sk_mem_reclaim(sk);
4964 !tcp_under_memory_pressure(sk)) 4968 if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf &&
4965 break; 4969 !tcp_under_memory_pressure(sk))
4970 break;
4971 goal = sk->sk_rcvbuf >> 3;
4972 }
4966 node = prev; 4973 node = prev;
4967 } while (node); 4974 } while (node);
4968 tp->ooo_last_skb = rb_to_skb(prev); 4975 tp->ooo_last_skb = rb_to_skb(prev);