summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Wellving <andreas.wellving@enea.com>2018-10-26 13:53:07 +0200
committerAndreas Wellving <andreas.wellving@enea.com>2018-10-26 13:53:07 +0200
commitc9c86492f9d5d36b35caffe638763cb0f84c7e63 (patch)
treef005728f5c9e40e036315baeaff2cc9dc04efedc
parent681b6e77b7ae8b95b8bcc70d29f9808e859be769 (diff)
downloadenea-kernel-cache-c9c86492f9d5d36b35caffe638763cb0f84c7e63.tar.gz
tcp: CVE-2018-5390
tcp: free batches of packets in tcp_prune_ofo_queue() Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=linux-4.9.y&id=2d08921c8da26bdce3d8848ef6f32068f594d7d4 Change-Id: Ia21ffaae335dd6fbea4f41ba64411974bc52bf3a Signed-off-by: Andreas Wellving <andreas.wellving@enea.com>
-rw-r--r--patches/cve/4.9.x.scc3
-rw-r--r--patches/cve/CVE-2018-5390-tcp-free-batches-of-packets-in-tcp_prune_ofo_queue.patch97
2 files changed, 100 insertions, 0 deletions
diff --git a/patches/cve/4.9.x.scc b/patches/cve/4.9.x.scc
index f521594..10999ce 100644
--- a/patches/cve/4.9.x.scc
+++ b/patches/cve/4.9.x.scc
@@ -24,3 +24,6 @@ SRC_URI += "file://CVE-2018-13405-Fix-up-non-directory-creation-in-SGID-director
24 24
25#CVEs fixed in 4.9.115: 25#CVEs fixed in 4.9.115:
26SRC_URI += "file://CVE-2018-10902-ALSA-rawmidi-Change-resized-buffers-atomically.patch" 26SRC_URI += "file://CVE-2018-10902-ALSA-rawmidi-Change-resized-buffers-atomically.patch"
27
28#CVEs fixed in 4.9.116:
29SRC_URI += "file://CVE-2018-5390-tcp-free-batches-of-packets-in-tcp_prune_ofo_queue.patch"
diff --git a/patches/cve/CVE-2018-5390-tcp-free-batches-of-packets-in-tcp_prune_ofo_queue.patch b/patches/cve/CVE-2018-5390-tcp-free-batches-of-packets-in-tcp_prune_ofo_queue.patch
new file mode 100644
index 0000000..67a8d27
--- /dev/null
+++ b/patches/cve/CVE-2018-5390-tcp-free-batches-of-packets-in-tcp_prune_ofo_queue.patch
@@ -0,0 +1,97 @@
1From 2d08921c8da26bdce3d8848ef6f32068f594d7d4 Mon Sep 17 00:00:00 2001
2From: Eric Dumazet <edumazet@google.com>
3Date: Mon, 23 Jul 2018 09:28:17 -0700
4Subject: [PATCH] tcp: free batches of packets in tcp_prune_ofo_queue()
5
6[ Upstream commit 72cd43ba64fc172a443410ce01645895850844c8 ]
7
8Juha-Matti Tilli reported that malicious peers could inject tiny
9packets in out_of_order_queue, forcing very expensive calls
10to tcp_collapse_ofo_queue() and tcp_prune_ofo_queue() for
11every incoming packet. out_of_order_queue rb-tree can contain
12thousands of nodes, iterating over all of them is not nice.
13
14Before linux-4.9, we would have pruned all packets in ofo_queue
15in one go, every XXXX packets. XXXX depends on sk_rcvbuf and skbs
16truesize, but is about 7000 packets with tcp_rmem[2] default of 6 MB.
17
18Since we plan to increase tcp_rmem[2] in the future to cope with
19modern BDP, can not revert to the old behavior, without great pain.
20
21Strategy taken in this patch is to purge ~12.5 % of the queue capacity.
22
23Fixes: 36a6503fedda ("tcp: refine tcp_prune_ofo_queue() to not drop all packets")
24
25CVE: CVE-2018-5390
26Upstream-Status: Backport [https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=linux-4.9.y&id=2d08921c8da26bdce3d8848ef6f32068f594d7d4]
27
28Signed-off-by: Eric Dumazet <edumazet@google.com>
29Reported-by: Juha-Matti Tilli <juha-matti.tilli@iki.fi>
30Acked-by: Yuchung Cheng <ycheng@google.com>
31Acked-by: Soheil Hassas Yeganeh <soheil@google.com>
32Signed-off-by: David S. Miller <davem@davemloft.net>
33Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
34Signed-off-by: Andreas Wellving <andreas.wellving@enea.com>
35---
36 include/linux/skbuff.h | 2 ++
37 net/ipv4/tcp_input.c | 15 +++++++++++----
38 2 files changed, 13 insertions(+), 4 deletions(-)
39
40diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
41index b048d3d3b327..1f207dd22757 100644
42--- a/include/linux/skbuff.h
43+++ b/include/linux/skbuff.h
44@@ -2982,6 +2982,8 @@ static inline int __skb_grow_rcsum(struct sk_buff *skb, unsigned int len)
45 return __skb_grow(skb, len);
46 }
47
48+#define rb_to_skb(rb) rb_entry_safe(rb, struct sk_buff, rbnode)
49+
50 #define skb_queue_walk(queue, skb) \
51 for (skb = (queue)->next; \
52 skb != (struct sk_buff *)(queue); \
53diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
54index 71f2b0958c4f..2eabf219b71d 100644
55--- a/net/ipv4/tcp_input.c
56+++ b/net/ipv4/tcp_input.c
57@@ -4965,6 +4965,7 @@ static void tcp_collapse_ofo_queue(struct sock *sk)
58 * 2) not add too big latencies if thousands of packets sit there.
59 * (But if application shrinks SO_RCVBUF, we could still end up
60 * freeing whole queue here)
61+ * 3) Drop at least 12.5 % of sk_rcvbuf to avoid malicious attacks.
62 *
63 * Return true if queue has shrunk.
64 */
65@@ -4972,20 +4973,26 @@ static bool tcp_prune_ofo_queue(struct sock *sk)
66 {
67 struct tcp_sock *tp = tcp_sk(sk);
68 struct rb_node *node, *prev;
69+ int goal;
70
71 if (RB_EMPTY_ROOT(&tp->out_of_order_queue))
72 return false;
73
74 NET_INC_STATS(sock_net(sk), LINUX_MIB_OFOPRUNED);
75+ goal = sk->sk_rcvbuf >> 3;
76 node = &tp->ooo_last_skb->rbnode;
77 do {
78 prev = rb_prev(node);
79 rb_erase(node, &tp->out_of_order_queue);
80+ goal -= rb_to_skb(node)->truesize;
81 tcp_drop(sk, rb_entry(node, struct sk_buff, rbnode));
82- sk_mem_reclaim(sk);
83- if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf &&
84- !tcp_under_memory_pressure(sk))
85- break;
86+ if (!prev || goal <= 0) {
87+ sk_mem_reclaim(sk);
88+ if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf &&
89+ !tcp_under_memory_pressure(sk))
90+ break;
91+ goal = sk->sk_rcvbuf >> 3;
92+ }
93 node = prev;
94 } while (node);
95 tp->ooo_last_skb = rb_entry(prev, struct sk_buff, rbnode);
96
97