Skip to content

Commit 1a3b0b5

Browse files
lxinaahmed71
authored andcommitted
tipc: wait and exit until all work queues are done
On some host, a crash could be triggered simply by repeating these commands several times: # modprobe tipc # tipc bearer enable media udp name UDP1 localip 127.0.0.1 # rmmod tipc [] BUG: unable to handle kernel paging request at ffffffffc096bb00 [] Workqueue: events 0xffffffffc096bb00 [] Call Trace: [] ? process_one_work+0x1a7/0x360 [] ? worker_thread+0x30/0x390 [] ? create_worker+0x1a0/0x1a0 [] ? kthread+0x116/0x130 [] ? kthread_flush_work_fn+0x10/0x10 [] ? ret_from_fork+0x35/0x40 When removing the TIPC module, the UDP tunnel sock will be delayed to release in a work queue as sock_release() can't be done in rtnl_lock(). If the work queue is schedule to run after the TIPC module is removed, kernel will crash as the work queue function cleanup_beareri() code no longer exists when trying to invoke it. To fix it, this patch introduce a member wq_count in tipc_net to track the numbers of work queues in schedule, and wait and exit until all work queues are done in tipc_exit_net(). Fixes: d0f9193 ("tipc: add ip/udp media type") Reported-by: Shuang Li <[email protected]> Signed-off-by: Xin Long <[email protected]> Acked-by: Jon Maloy <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Bjoern Doebel <[email protected]> [[email protected]: Backport to kernel 4.14 by adjusting to context.]
1 parent 36aabeb commit 1a3b0b5

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

net/tipc/core.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ static int __net_init tipc_init_net(struct net *net)
8888

8989
static void __net_exit tipc_exit_net(struct net *net)
9090
{
91+
struct tipc_net *tn = tipc_net(net);
9192
tipc_net_stop(net);
9293

9394
/* Make sure the tipc_net_finalize_work stopped
@@ -97,6 +98,8 @@ static void __net_exit tipc_exit_net(struct net *net)
9798
tipc_bcast_stop(net);
9899
tipc_nametbl_stop(net);
99100
tipc_sk_rht_destroy(net);
101+
while (atomic_read(&tn->wq_count))
102+
cond_resched();
100103
}
101104

102105
static struct pernet_operations tipc_net_ops = {

net/tipc/core.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ struct tipc_net {
115115
/* Topology subscription server */
116116
struct tipc_server *topsrv;
117117
atomic_t subscription_count;
118+
119+
/* The number of work queues in schedule */
120+
atomic_t wq_count;
118121
};
119122

120123
static inline struct tipc_net *tipc_net(struct net *net)

net/tipc/udp_media.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ static void cleanup_bearer(struct work_struct *work)
761761
kfree_rcu(rcast, rcu);
762762
}
763763

764+
atomic_dec(&tipc_net(sock_net(ub->ubsock->sk))->wq_count);
764765
if (ub->ubsock)
765766
udp_tunnel_sock_release(ub->ubsock);
766767
synchronize_net();
@@ -782,6 +783,7 @@ static void tipc_udp_disable(struct tipc_bearer *b)
782783
RCU_INIT_POINTER(ub->bearer, NULL);
783784

784785
/* sock_release need to be done outside of rtnl lock */
786+
atomic_inc(&tipc_net(sock_net(ub->ubsock->sk))->wq_count);
785787
INIT_WORK(&ub->work, cleanup_bearer);
786788
schedule_work(&ub->work);
787789
}

0 commit comments

Comments
 (0)