]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.4.177/ip6mr-do-not-call-__ip6_inc_stats-from-preemptible-context.patch
Linux 4.4.177
[thirdparty/kernel/stable-queue.git] / releases / 4.4.177 / ip6mr-do-not-call-__ip6_inc_stats-from-preemptible-context.patch
1 From foo@baz Fri Mar 8 10:00:48 CET 2019
2 From: Ido Schimmel <idosch@mellanox.com>
3 Date: Sun, 3 Mar 2019 07:34:57 +0000
4 Subject: ip6mr: Do not call __IP6_INC_STATS() from preemptible context
5
6 From: Ido Schimmel <idosch@mellanox.com>
7
8 [ Upstream commit 87c11f1ddbbad38ad8bad47af133a8208985fbdf ]
9
10 Similar to commit 44f49dd8b5a6 ("ipmr: fix possible race resulting from
11 improper usage of IP_INC_STATS_BH() in preemptible context."), we cannot
12 assume preemption is disabled when incrementing the counter and
13 accessing a per-CPU variable.
14
15 Preemption can be enabled when we add a route in process context that
16 corresponds to packets stored in the unresolved queue, which are then
17 forwarded using this route [1].
18
19 Fix this by using IP6_INC_STATS() which takes care of disabling
20 preemption on architectures where it is needed.
21
22 [1]
23 [ 157.451447] BUG: using __this_cpu_add() in preemptible [00000000] code: smcrouted/2314
24 [ 157.460409] caller is ip6mr_forward2+0x73e/0x10e0
25 [ 157.460434] CPU: 3 PID: 2314 Comm: smcrouted Not tainted 5.0.0-rc7-custom-03635-g22f2712113f1 #1336
26 [ 157.460449] Hardware name: Mellanox Technologies Ltd. MSN2100-CB2FO/SA001017, BIOS 5.6.5 06/07/2016
27 [ 157.460461] Call Trace:
28 [ 157.460486] dump_stack+0xf9/0x1be
29 [ 157.460553] check_preemption_disabled+0x1d6/0x200
30 [ 157.460576] ip6mr_forward2+0x73e/0x10e0
31 [ 157.460705] ip6_mr_forward+0x9a0/0x1510
32 [ 157.460771] ip6mr_mfc_add+0x16b3/0x1e00
33 [ 157.461155] ip6_mroute_setsockopt+0x3cb/0x13c0
34 [ 157.461384] do_ipv6_setsockopt.isra.8+0x348/0x4060
35 [ 157.462013] ipv6_setsockopt+0x90/0x110
36 [ 157.462036] rawv6_setsockopt+0x4a/0x120
37 [ 157.462058] __sys_setsockopt+0x16b/0x340
38 [ 157.462198] __x64_sys_setsockopt+0xbf/0x160
39 [ 157.462220] do_syscall_64+0x14d/0x610
40 [ 157.462349] entry_SYSCALL_64_after_hwframe+0x49/0xbe
41
42 Fixes: 0912ea38de61 ("[IPV6] MROUTE: Add stats in multicast routing module method ip6_mr_forward().")
43 Signed-off-by: Ido Schimmel <idosch@mellanox.com>
44 Reported-by: Amit Cohen <amitc@mellanox.com>
45 Signed-off-by: David S. Miller <davem@davemloft.net>
46 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
47 ---
48 net/ipv6/ip6mr.c | 8 ++++----
49 1 file changed, 4 insertions(+), 4 deletions(-)
50
51 --- a/net/ipv6/ip6mr.c
52 +++ b/net/ipv6/ip6mr.c
53 @@ -1990,10 +1990,10 @@ int ip6mr_compat_ioctl(struct sock *sk,
54
55 static inline int ip6mr_forward2_finish(struct net *net, struct sock *sk, struct sk_buff *skb)
56 {
57 - IP6_INC_STATS_BH(net, ip6_dst_idev(skb_dst(skb)),
58 - IPSTATS_MIB_OUTFORWDATAGRAMS);
59 - IP6_ADD_STATS_BH(net, ip6_dst_idev(skb_dst(skb)),
60 - IPSTATS_MIB_OUTOCTETS, skb->len);
61 + IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)),
62 + IPSTATS_MIB_OUTFORWDATAGRAMS);
63 + IP6_ADD_STATS(net, ip6_dst_idev(skb_dst(skb)),
64 + IPSTATS_MIB_OUTOCTETS, skb->len);
65 return dst_output(net, sk, skb);
66 }
67