1 From 526f5b851a96566803ee4bee60d0a34df56c77f8 Mon Sep 17 00:00:00 2001
2 From: Junwei Hu <hujunwei4@huawei.com>
3 Date: Mon, 20 May 2019 14:43:59 +0800
4 Subject: tipc: fix modprobe tipc failed after switch order of device registration -v2
6 From: Junwei Hu <hujunwei4@huawei.com>
8 commit 526f5b851a96566803ee4bee60d0a34df56c77f8 upstream.
10 Error message printed:
11 modprobe: ERROR: could not insert 'tipc': Address family not
12 supported by protocol.
13 when modprobe tipc after the following patch: switch order of
14 device registration, commit 7e27e8d6130c
15 ("tipc: switch order of device registration to fix a crash")
17 Because sock_create_kern(net, AF_TIPC, ...) called by
18 tipc_topsrv_create_listener() in the initialization process
19 of tipc_init_net(), so tipc_socket_init() must be execute before that.
20 Meanwhile, tipc_net_id need to be initialized when sock_create()
21 called, and tipc_socket_init() is no need to be called for each namespace.
23 I add a variable tipc_topsrv_net_ops, and split the
24 register_pernet_subsys() of tipc into two parts, and split
25 tipc_socket_init() with initialization of pernet params.
27 By the way, I fixed resources rollback error when tipc_bcast_init()
28 failed in tipc_init_net().
30 Fixes: 7e27e8d6130c ("tipc: switch order of device registration to fix a crash")
31 Signed-off-by: Junwei Hu <hujunwei4@huawei.com>
32 Reported-by: Wang Wang <wangwang2@huawei.com>
33 Reported-by: syzbot+1e8114b61079bfe9cbc5@syzkaller.appspotmail.com
34 Reviewed-by: Kang Zhou <zhoukang7@huawei.com>
35 Reviewed-by: Suanming Mou <mousuanming@huawei.com>
36 Signed-off-by: David S. Miller <davem@davemloft.net>
37 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
40 net/tipc/core.c | 18 ++++++++++++------
41 net/tipc/subscr.c | 14 ++++++++++++--
42 net/tipc/subscr.h | 5 +++--
43 3 files changed, 27 insertions(+), 10 deletions(-)
47 @@ -70,9 +70,6 @@ static int __net_init tipc_init_net(stru
50 INIT_LIST_HEAD(&tn->dist_queue);
51 - err = tipc_topsrv_start(net);
55 err = tipc_bcast_init(net);
57 @@ -81,8 +78,6 @@ static int __net_init tipc_init_net(stru
61 - tipc_bcast_stop(net);
63 tipc_nametbl_stop(net);
65 tipc_sk_rht_destroy(net);
66 @@ -92,7 +87,6 @@ out_sk_rht:
68 static void __net_exit tipc_exit_net(struct net *net)
70 - tipc_topsrv_stop(net);
73 tipc_nametbl_stop(net);
74 @@ -106,6 +100,11 @@ static struct pernet_operations tipc_net
75 .size = sizeof(struct tipc_net),
78 +static struct pernet_operations tipc_topsrv_net_ops = {
79 + .init = tipc_topsrv_init_net,
80 + .exit = tipc_topsrv_exit_net,
83 static int __init tipc_init(void)
86 @@ -138,6 +137,10 @@ static int __init tipc_init(void)
90 + err = register_pernet_subsys(&tipc_topsrv_net_ops);
92 + goto out_pernet_topsrv;
94 err = tipc_bearer_setup();
97 @@ -145,6 +148,8 @@ static int __init tipc_init(void)
98 pr_info("Started in single node mode\n");
101 + unregister_pernet_subsys(&tipc_topsrv_net_ops);
105 unregister_pernet_subsys(&tipc_net_ops);
106 @@ -162,6 +167,7 @@ out_netlink:
107 static void __exit tipc_exit(void)
109 tipc_bearer_cleanup();
110 + unregister_pernet_subsys(&tipc_topsrv_net_ops);
112 unregister_pernet_subsys(&tipc_net_ops);
114 --- a/net/tipc/subscr.c
115 +++ b/net/tipc/subscr.c
116 @@ -306,7 +306,7 @@ static void *tipc_subscrb_connect_cb(int
117 return (void *)tipc_subscrb_create(conid);
120 -int tipc_topsrv_start(struct net *net)
121 +static int tipc_topsrv_start(struct net *net)
123 struct tipc_net *tn = net_generic(net, tipc_net_id);
124 const char name[] = "topology_server";
125 @@ -344,7 +344,7 @@ int tipc_topsrv_start(struct net *net)
126 return tipc_server_start(topsrv);
129 -void tipc_topsrv_stop(struct net *net)
130 +static void tipc_topsrv_stop(struct net *net)
132 struct tipc_net *tn = net_generic(net, tipc_net_id);
133 struct tipc_server *topsrv = tn->topsrv;
134 @@ -353,3 +353,13 @@ void tipc_topsrv_stop(struct net *net)
135 kfree(topsrv->saddr);
139 +int __net_init tipc_topsrv_init_net(struct net *net)
141 + return tipc_topsrv_start(net);
144 +void __net_exit tipc_topsrv_exit_net(struct net *net)
146 + tipc_topsrv_stop(net);
148 --- a/net/tipc/subscr.h
149 +++ b/net/tipc/subscr.h
150 @@ -77,7 +77,8 @@ int tipc_subscrp_check_overlap(struct ti
151 void tipc_subscrp_report_overlap(struct tipc_subscription *sub,
152 u32 found_lower, u32 found_upper, u32 event,
153 u32 port_ref, u32 node, int must);
154 -int tipc_topsrv_start(struct net *net);
155 -void tipc_topsrv_stop(struct net *net);
157 +int __net_init tipc_topsrv_init_net(struct net *net);
158 +void __net_exit tipc_topsrv_exit_net(struct net *net);