Skip to content

Commit 00ede97

Browse files
ying-xuedavem330
authored andcommitted
tipc: protect handler_enabled variable with qitem_lock spin lock
'handler_enabled' is a global flag indicating whether the TIPC signal handling service is enabled or not. The lack of lock protection for this flag incurs a risk for contention, so that a tipc_k_signal() call might queue a signal handler to a destroyed signal queue, with unpredictable results. To correct this, we let the already existing 'qitem_lock' protect the flag, as it already does with the queue itself. This way, we ensure that the flag always is consistent across all cores. Signed-off-by: Ying Xue <ying.xue@windriver.com> Reviewed-by: Paul Gortmaker <paul.gortmaker@windriver.com> Signed-off-by: Jon Maloy <jon.maloy@ericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 993b858 commit 00ede97

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

net/tipc/handler.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@ unsigned int tipc_k_signal(Handler routine, unsigned long argument)
5656
{
5757
struct queue_item *item;
5858

59+
spin_lock_bh(&qitem_lock);
5960
if (!handler_enabled) {
6061
pr_err("Signal request ignored by handler\n");
62+
spin_unlock_bh(&qitem_lock);
6163
return -ENOPROTOOPT;
6264
}
6365

64-
spin_lock_bh(&qitem_lock);
6566
item = kmem_cache_alloc(tipc_queue_item_cache, GFP_ATOMIC);
6667
if (!item) {
6768
pr_err("Signal queue out of memory\n");
@@ -112,10 +113,14 @@ void tipc_handler_stop(void)
112113
struct list_head *l, *n;
113114
struct queue_item *item;
114115

115-
if (!handler_enabled)
116+
spin_lock_bh(&qitem_lock);
117+
if (!handler_enabled) {
118+
spin_unlock_bh(&qitem_lock);
116119
return;
117-
120+
}
118121
handler_enabled = 0;
122+
spin_unlock_bh(&qitem_lock);
123+
119124
tasklet_kill(&tipc_tasklet);
120125

121126
spin_lock_bh(&qitem_lock);

0 commit comments

Comments
 (0)