kernel: cleanup offload hooks on netdev unregister
[openwrt/openwrt.git] / target / linux / generic / hack-4.14 / 940-cleanup-offload-hooks-on-netdev-unregister.patch
1 From ae56e27e30122f82d244f9eb35fcab8fa60e0d31 Mon Sep 17 00:00:00 2001
2 From: Chen Minqiang <ptpt52@gmail.com>
3 Date: Sun, 29 Apr 2018 14:08:57 +0800
4 Subject: [PATCH] cleanup offload hooks on netdev unregister
5
6 This should fix crashdump on reboot when FLOWOFFLOAD enabled
7
8 kmsg:
9 [ 84.188081] Workqueue: events_power_efficient xt_flowoffload_hook_work [xt_FLOWOFFLOAD]
10 [ 84.209326] task: ffff88000ecd0c80 task.stack: ffffc90000068000
11 [ 84.224706] RIP: 0010:__nf_unregister_net_hook+0x1/0x90
12 [ 84.242911] RSP: 0018:ffffc9000006be30 EFLAGS: 00010202
13 [ 84.257405] RAX: 0000000000000000 RBX: ffff88000c5b3228 RCX: 0000000100170001
14 [ 84.292175] RDX: ffff88000ecd0c80 RSI: ffff88000c5b3228 RDI: 6b6b6b6b6b6b6b6b
15 [ 84.305095] RBP: ffffc9000006be58 R08: ffff88000c5b3578 R09: ffff88000c5b3538
16 [ 84.325980] R10: ffffc9000006be50 R11: ffff88000fc1f310 R12: ffffffff81e6c580
17 [ 84.396514] R13: ffff88000d1723d0 R14: ffff88000ec0fc00 R15: 0000000000000000
18 [ 84.459500] FS: 0000000000000000(0000) GS:ffff88000fc00000(0000) knlGS:0000000000000000
19 [ 84.525121] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
20 [ 84.565460] CR2: 0000000000a931d8 CR3: 0000000001e08006 CR4: 00000000000606f0
21 [ 84.638311] Call Trace:
22 [ 84.655229] ? nf_unregister_net_hook+0x88/0xd0
23 [ 84.706898] xt_flowoffload_hook_work+0x12a/0x17a [xt_FLOWOFFLOAD]
24 [ 84.765504] process_one_work+0x1c4/0x310
25 [ 84.799558] worker_thread+0x20b/0x3c0
26 [ 84.850119] kthread+0x112/0x120
27 [ 84.884839] ? process_one_work+0x310/0x310
28 [ 84.923571] ? kthread_create_on_node+0x40/0x40
29 [ 84.966100] ret_from_fork+0x35/0x40
30 [ 84.981738] Code: 41 5c 41 5d 41 5e 41 5f 5d c3 48 8b 05 c1 f1 99 00 55 48 89 e5 48 85 c0 75 02 0f 0b e8 b9 f6 30 00 5d c3 0f 1f 80 00 00 00 00 55 <0f> b7 0f 48 89 e5 48 89 c8 48 c1 e0 04 48 8d 54 07 08 31 c0 eb
31 [ 85.100453] RIP: __nf_unregister_net_hook+0x1/0x90 RSP: ffffc9000006be30
32 [ 85.111658] ---[ end trace 5c25a390045cac75 ]---
33 [ 85.124535] Kernel panic - not syncing: Fatal exception
34
35 Signed-off-by: Chen Minqiang <ptpt52@gmail.com>
36 ---
37 net/netfilter/xt_FLOWOFFLOAD.c | 32 ++++++++++++++++++++++++++++++++
38 1 file changed, 32 insertions(+)
39
40 diff --git a/net/netfilter/xt_FLOWOFFLOAD.c b/net/netfilter/xt_FLOWOFFLOAD.c
41 index ab6259e..3bea08e 100644
42 --- a/net/netfilter/xt_FLOWOFFLOAD.c
43 +++ b/net/netfilter/xt_FLOWOFFLOAD.c
44 @@ -337,10 +337,41 @@ static void xt_flowoffload_table_cleanup(struct nf_flowtable *table)
45 nf_flow_table_free(table);
46 }
47
48 +static int flow_offload_netdev_event(struct notifier_block *this,
49 + unsigned long event, void *ptr)
50 +{
51 + struct xt_flowoffload_hook *hook = NULL;
52 + struct net_device *dev = netdev_notifier_info_to_dev(ptr);
53 +
54 + if (event != NETDEV_UNREGISTER)
55 + return NOTIFY_DONE;
56 +
57 + spin_lock_bh(&hooks_lock);
58 + hook = flow_offload_lookup_hook(dev);
59 + if (hook) {
60 + hlist_del(&hook->list);
61 + }
62 + spin_unlock_bh(&hooks_lock);
63 + if (hook) {
64 + nf_unregister_net_hook(hook->net, &hook->ops);
65 + kfree(hook);
66 + }
67 +
68 + nf_flow_table_cleanup(dev_net(dev), dev);
69 +
70 + return NOTIFY_DONE;
71 +}
72 +
73 +static struct notifier_block flow_offload_netdev_notifier = {
74 + .notifier_call = flow_offload_netdev_event,
75 +};
76 +
77 static int __init xt_flowoffload_tg_init(void)
78 {
79 int ret;
80
81 + register_netdevice_notifier(&flow_offload_netdev_notifier);
82 +
83 INIT_DELAYED_WORK(&hook_work, xt_flowoffload_hook_work);
84
85 ret = xt_flowoffload_table_init(&nf_flowtable);
86 @@ -358,6 +389,7 @@ static void __exit xt_flowoffload_tg_exit(void)
87 {
88 xt_unregister_target(&offload_tg_reg);
89 xt_flowoffload_table_cleanup(&nf_flowtable);
90 + unregister_netdevice_notifier(&flow_offload_netdev_notifier);
91 }
92
93 MODULE_LICENSE("GPL");
94 --
95 2.17.0
96