1 From foo@baz Wed 22 May 2019 06:53:31 PM CEST
2 From: Junwei Hu <hujunwei4@huawei.com>
3 Date: Thu, 16 May 2019 10:51:15 +0800
4 Subject: tipc: switch order of device registration to fix a crash
6 From: Junwei Hu <hujunwei4@huawei.com>
8 [ Upstream commit 7e27e8d6130c5e88fac9ddec4249f7f2337fe7f8 ]
10 When tipc is loaded while many processes try to create a TIPC socket,
12 PANIC: Unable to handle kernel paging request at virtual
13 address "dfff20000000021d"
14 pc : tipc_sk_create+0x374/0x1180 [tipc]
15 lr : tipc_sk_create+0x374/0x1180 [tipc]
16 Exception class = DABT (current EL), IL = 32 bits
18 tipc_sk_create+0x374/0x1180 [tipc]
19 __sock_create+0x1cc/0x408
20 __sys_socket+0xec/0x1f0
21 __arm64_sys_socket+0x74/0xa8
24 This is due to race between sock_create and unfinished
25 register_pernet_device. tipc_sk_insert tries to do
26 "net_generic(net, tipc_net_id)".
27 but tipc_net_id is not initialized yet.
29 So switch the order of the two to close the race.
31 This can be reproduced with multiple processes doing socket(AF_TIPC, ...)
32 and one process doing module removal.
34 Fixes: a62fbccecd62 ("tipc: make subscriber server support net namespace")
35 Signed-off-by: Junwei Hu <hujunwei4@huawei.com>
36 Reported-by: Wang Wang <wangwang2@huawei.com>
37 Reviewed-by: Xiaogang Wang <wangxiaogang3@huawei.com>
38 Signed-off-by: David S. Miller <davem@davemloft.net>
39 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
41 net/tipc/core.c | 14 +++++++-------
42 1 file changed, 7 insertions(+), 7 deletions(-)
46 @@ -125,10 +125,6 @@ static int __init tipc_init(void)
48 goto out_netlink_compat;
50 - err = tipc_socket_init();
54 err = tipc_register_sysctl();
57 @@ -137,6 +133,10 @@ static int __init tipc_init(void)
61 + err = tipc_socket_init();
65 err = tipc_bearer_setup();
68 @@ -144,12 +144,12 @@ static int __init tipc_init(void)
69 pr_info("Started in single node mode\n");
74 unregister_pernet_subsys(&tipc_net_ops);
76 tipc_unregister_sysctl();
80 tipc_netlink_compat_stop();
83 @@ -161,10 +161,10 @@ out_netlink:
84 static void __exit tipc_exit(void)
86 tipc_bearer_cleanup();
88 unregister_pernet_subsys(&tipc_net_ops);
90 tipc_netlink_compat_stop();
92 tipc_unregister_sysctl();
94 pr_info("Deactivated\n");