]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - queue-4.14/tipc-fix-modprobe-tipc-failed-after-switch-order-of-device-registration.patch
fixes for 4.19
[thirdparty/kernel/stable-queue.git] / queue-4.14 / tipc-fix-modprobe-tipc-failed-after-switch-order-of-device-registration.patch
CommitLineData
94749fd6
GKH
1From 526f5b851a96566803ee4bee60d0a34df56c77f8 Mon Sep 17 00:00:00 2001
2From: Junwei Hu <hujunwei4@huawei.com>
3Date: Mon, 20 May 2019 14:43:59 +0800
4Subject: tipc: fix modprobe tipc failed after switch order of device registration
5
6From: Junwei Hu <hujunwei4@huawei.com>
7
8commit 526f5b851a96566803ee4bee60d0a34df56c77f8 upstream.
9
10Error message printed:
11modprobe: ERROR: could not insert 'tipc': Address family not
12supported by protocol.
13when modprobe tipc after the following patch: switch order of
14device registration, commit 7e27e8d6130c
15("tipc: switch order of device registration to fix a crash")
16
17Because sock_create_kern(net, AF_TIPC, ...) called by
18tipc_topsrv_create_listener() in the initialization process
19of tipc_init_net(), so tipc_socket_init() must be execute before that.
20Meanwhile, tipc_net_id need to be initialized when sock_create()
21called, and tipc_socket_init() is no need to be called for each namespace.
22
23I add a variable tipc_topsrv_net_ops, and split the
24register_pernet_subsys() of tipc into two parts, and split
25tipc_socket_init() with initialization of pernet params.
26
27By the way, I fixed resources rollback error when tipc_bcast_init()
28failed in tipc_init_net().
29
30Fixes: 7e27e8d6130c ("tipc: switch order of device registration to fix a crash")
31Signed-off-by: Junwei Hu <hujunwei4@huawei.com>
32Reported-by: Wang Wang <wangwang2@huawei.com>
33Reported-by: syzbot+1e8114b61079bfe9cbc5@syzkaller.appspotmail.com
34Reviewed-by: Kang Zhou <zhoukang7@huawei.com>
35Reviewed-by: Suanming Mou <mousuanming@huawei.com>
36Signed-off-by: David S. Miller <davem@davemloft.net>
37Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
38
39---
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(-)
44
45--- a/net/tipc/core.c
46+++ b/net/tipc/core.c
47@@ -71,9 +71,6 @@ static int __net_init tipc_init_net(stru
48 goto out_nametbl;
49
50 INIT_LIST_HEAD(&tn->dist_queue);
51- err = tipc_topsrv_start(net);
52- if (err)
53- goto out_subscr;
54
55 err = tipc_bcast_init(net);
56 if (err)
57@@ -82,8 +79,6 @@ static int __net_init tipc_init_net(stru
58 return 0;
59
60 out_bclink:
61- tipc_bcast_stop(net);
62-out_subscr:
63 tipc_nametbl_stop(net);
64 out_nametbl:
65 tipc_sk_rht_destroy(net);
66@@ -93,7 +88,6 @@ out_sk_rht:
67
68 static void __net_exit tipc_exit_net(struct net *net)
69 {
70- tipc_topsrv_stop(net);
71 tipc_net_stop(net);
72 tipc_bcast_stop(net);
73 tipc_nametbl_stop(net);
74@@ -107,6 +101,11 @@ static struct pernet_operations tipc_net
75 .size = sizeof(struct tipc_net),
76 };
77
78+static struct pernet_operations tipc_topsrv_net_ops = {
79+ .init = tipc_topsrv_init_net,
80+ .exit = tipc_topsrv_exit_net,
81+};
82+
83 static int __init tipc_init(void)
84 {
85 int err;
86@@ -137,6 +136,10 @@ static int __init tipc_init(void)
87 if (err)
88 goto out_socket;
89
90+ err = register_pernet_subsys(&tipc_topsrv_net_ops);
91+ if (err)
92+ goto out_pernet_topsrv;
93+
94 err = tipc_bearer_setup();
95 if (err)
96 goto out_bearer;
97@@ -144,6 +147,8 @@ static int __init tipc_init(void)
98 pr_info("Started in single node mode\n");
99 return 0;
100 out_bearer:
101+ unregister_pernet_subsys(&tipc_topsrv_net_ops);
102+out_pernet_topsrv:
103 tipc_socket_stop();
104 out_socket:
105 unregister_pernet_subsys(&tipc_net_ops);
106@@ -161,6 +166,7 @@ out_netlink:
107 static void __exit tipc_exit(void)
108 {
109 tipc_bearer_cleanup();
110+ unregister_pernet_subsys(&tipc_topsrv_net_ops);
111 tipc_socket_stop();
112 unregister_pernet_subsys(&tipc_net_ops);
113 tipc_netlink_stop();
114--- a/net/tipc/subscr.c
115+++ b/net/tipc/subscr.c
116@@ -344,7 +344,7 @@ static void *tipc_subscrb_connect_cb(int
117 return (void *)tipc_subscrb_create(conid);
118 }
119
120-int tipc_topsrv_start(struct net *net)
121+static int tipc_topsrv_start(struct net *net)
122 {
123 struct tipc_net *tn = net_generic(net, tipc_net_id);
124 const char name[] = "topology_server";
125@@ -382,7 +382,7 @@ int tipc_topsrv_start(struct net *net)
126 return tipc_server_start(topsrv);
127 }
128
129-void tipc_topsrv_stop(struct net *net)
130+static void tipc_topsrv_stop(struct net *net)
131 {
132 struct tipc_net *tn = net_generic(net, tipc_net_id);
133 struct tipc_server *topsrv = tn->topsrv;
134@@ -391,3 +391,13 @@ void tipc_topsrv_stop(struct net *net)
135 kfree(topsrv->saddr);
136 kfree(topsrv);
137 }
138+
139+int __net_init tipc_topsrv_init_net(struct net *net)
140+{
141+ return tipc_topsrv_start(net);
142+}
143+
144+void __net_exit tipc_topsrv_exit_net(struct net *net)
145+{
146+ tipc_topsrv_stop(net);
147+}
148--- a/net/tipc/subscr.h
149+++ b/net/tipc/subscr.h
150@@ -75,8 +75,9 @@ void tipc_subscrp_report_overlap(struct
151 void tipc_subscrp_convert_seq(struct tipc_name_seq *in, int swap,
152 struct tipc_name_seq *out);
153 u32 tipc_subscrp_convert_seq_type(u32 type, int swap);
154-int tipc_topsrv_start(struct net *net);
155-void tipc_topsrv_stop(struct net *net);
156+
157+int __net_init tipc_topsrv_init_net(struct net *net);
158+void __net_exit tipc_topsrv_exit_net(struct net *net);
159
160 void tipc_subscrp_put(struct tipc_subscription *subscription);
161 void tipc_subscrp_get(struct tipc_subscription *subscription);