]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.14.93/netfilter-nat-can-t-use-dst_hold-on-noref-dst.patch
Linux 4.19.15
[thirdparty/kernel/stable-queue.git] / releases / 4.14.93 / netfilter-nat-can-t-use-dst_hold-on-noref-dst.patch
1 From fe31e7b578e65d8e55c55aeb66be6c34c10513fd Mon Sep 17 00:00:00 2001
2 From: Florian Westphal <fw@strlen.de>
3 Date: Tue, 11 Dec 2018 07:45:29 +0100
4 Subject: netfilter: nat: can't use dst_hold on noref dst
5
6 [ Upstream commit 542fbda0f08f1cbbc250f9e59f7537649651d0c8 ]
7
8 The dst entry might already have a zero refcount, waiting on rcu list
9 to be free'd. Using dst_hold() transitions its reference count to 1, and
10 next dst release will try to free it again -- resulting in a double free:
11
12 WARNING: CPU: 1 PID: 0 at include/net/dst.h:239 nf_xfrm_me_harder+0xe7/0x130 [nf_nat]
13 RIP: 0010:nf_xfrm_me_harder+0xe7/0x130 [nf_nat]
14 Code: 48 8b 5c 24 60 65 48 33 1c 25 28 00 00 00 75 53 48 83 c4 68 5b 5d 41 5c c3 85 c0 74 0d 8d 48 01 f0 0f b1 0a 74 86 85 c0 75 f3 <0f> 0b e9 7b ff ff ff 29 c6 31 d2 b9 20 00 48 00 4c 89 e7 e8 31 27
15 Call Trace:
16 nf_nat_ipv4_out+0x78/0x90 [nf_nat_ipv4]
17 nf_hook_slow+0x36/0xd0
18 ip_output+0x9f/0xd0
19 ip_forward+0x328/0x440
20 ip_rcv+0x8a/0xb0
21
22 Use dst_hold_safe instead and bail out if we cannot take a reference.
23
24 Fixes: a4c2fd7f7891 ("net: remove DST_NOCACHE flag")
25 Reported-by: Martin Zaharinov <micron10@gmail.com>
26 Signed-off-by: Florian Westphal <fw@strlen.de>
27 Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
28 Signed-off-by: Sasha Levin <sashal@kernel.org>
29 ---
30 net/netfilter/nf_nat_core.c | 3 ++-
31 1 file changed, 2 insertions(+), 1 deletion(-)
32
33 diff --git a/net/netfilter/nf_nat_core.c b/net/netfilter/nf_nat_core.c
34 index af8345fc4fbd..ed0ea64b8d04 100644
35 --- a/net/netfilter/nf_nat_core.c
36 +++ b/net/netfilter/nf_nat_core.c
37 @@ -97,7 +97,8 @@ int nf_xfrm_me_harder(struct net *net, struct sk_buff *skb, unsigned int family)
38 dst = skb_dst(skb);
39 if (dst->xfrm)
40 dst = ((struct xfrm_dst *)dst)->route;
41 - dst_hold(dst);
42 + if (!dst_hold_safe(dst))
43 + return -EHOSTUNREACH;
44
45 dst = xfrm_lookup(net, dst, &fl, skb->sk, 0);
46 if (IS_ERR(dst))
47 --
48 2.19.1
49