]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.4/tipc-fix-modprobe-tipc-failed-after-switch-order-of-device-registration-v2.patch
Linux 4.9.181
[thirdparty/kernel/stable-queue.git] / queue-4.4 / tipc-fix-modprobe-tipc-failed-after-switch-order-of-device-registration-v2.patch
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
5
6 From: Junwei Hu <hujunwei4@huawei.com>
7
8 commit 526f5b851a96566803ee4bee60d0a34df56c77f8 upstream.
9
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")
16
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.
22
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.
26
27 By the way, I fixed resources rollback error when tipc_bcast_init()
28 failed in tipc_init_net().
29
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>
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 @@ -70,9 +70,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 @@ -81,8 +78,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 @@ -92,7 +87,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 @@ -106,6 +100,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 @@ -138,6 +137,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 @@ -145,6 +148,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 @@ -162,6 +167,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 @@ -306,7 +306,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 @@ -344,7 +344,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 @@ -353,3 +353,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 @@ -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);
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 #endif