]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/5.0.6/ipv6-make-ip6_create_rt_rcu-return-ip6_null_entry-instead-of-null.patch
Linux 4.19.33
[thirdparty/kernel/stable-queue.git] / releases / 5.0.6 / ipv6-make-ip6_create_rt_rcu-return-ip6_null_entry-instead-of-null.patch
1 From foo@baz Thu Mar 28 21:53:58 CET 2019
2 From: Xin Long <lucien.xin@gmail.com>
3 Date: Wed, 20 Mar 2019 14:45:48 +0800
4 Subject: ipv6: make ip6_create_rt_rcu return ip6_null_entry instead of NULL
5
6 From: Xin Long <lucien.xin@gmail.com>
7
8 [ Upstream commit 1c87e79a002f6a159396138cd3f3ab554a2a8887 ]
9
10 Jianlin reported a crash:
11
12 [ 381.484332] BUG: unable to handle kernel NULL pointer dereference at 0000000000000068
13 [ 381.619802] RIP: 0010:fib6_rule_lookup+0xa3/0x160
14 [ 382.009615] Call Trace:
15 [ 382.020762] <IRQ>
16 [ 382.030174] ip6_route_redirect.isra.52+0xc9/0xf0
17 [ 382.050984] ip6_redirect+0xb6/0xf0
18 [ 382.066731] icmpv6_notify+0xca/0x190
19 [ 382.083185] ndisc_redirect_rcv+0x10f/0x160
20 [ 382.102569] ndisc_rcv+0xfb/0x100
21 [ 382.117725] icmpv6_rcv+0x3f2/0x520
22 [ 382.133637] ip6_input_finish+0xbf/0x460
23 [ 382.151634] ip6_input+0x3b/0xb0
24 [ 382.166097] ipv6_rcv+0x378/0x4e0
25
26 It was caused by the lookup function __ip6_route_redirect() returns NULL in
27 fib6_rule_lookup() when ip6_create_rt_rcu() returns NULL.
28
29 So we fix it by simply making ip6_create_rt_rcu() return ip6_null_entry
30 instead of NULL.
31
32 v1->v2:
33 - move down 'fallback:' to make it more readable.
34
35 Fixes: e873e4b9cc7e ("ipv6: use fib6_info_hold_safe() when necessary")
36 Reported-by: Jianlin Shi <jishi@redhat.com>
37 Suggested-by: Paolo Abeni <pabeni@redhat.com>
38 Signed-off-by: Xin Long <lucien.xin@gmail.com>
39 Reviewed-by: David Ahern <dsahern@gmail.com>
40 Acked-by: Wei Wang <weiwan@google.com>
41 Signed-off-by: David S. Miller <davem@davemloft.net>
42 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
43 ---
44 net/ipv6/route.c | 18 ++++++++++--------
45 1 file changed, 10 insertions(+), 8 deletions(-)
46
47 --- a/net/ipv6/route.c
48 +++ b/net/ipv6/route.c
49 @@ -1040,14 +1040,20 @@ static struct rt6_info *ip6_create_rt_rc
50 struct rt6_info *nrt;
51
52 if (!fib6_info_hold_safe(rt))
53 - return NULL;
54 + goto fallback;
55
56 nrt = ip6_dst_alloc(dev_net(dev), dev, flags);
57 - if (nrt)
58 - ip6_rt_copy_init(nrt, rt);
59 - else
60 + if (!nrt) {
61 fib6_info_release(rt);
62 + goto fallback;
63 + }
64 +
65 + ip6_rt_copy_init(nrt, rt);
66 + return nrt;
67
68 +fallback:
69 + nrt = dev_net(dev)->ipv6.ip6_null_entry;
70 + dst_hold(&nrt->dst);
71 return nrt;
72 }
73
74 @@ -1096,10 +1102,6 @@ restart:
75 dst_hold(&rt->dst);
76 } else {
77 rt = ip6_create_rt_rcu(f6i);
78 - if (!rt) {
79 - rt = net->ipv6.ip6_null_entry;
80 - dst_hold(&rt->dst);
81 - }
82 }
83
84 rcu_read_unlock();