Skip to content

Commit 70e1683

Browse files
mrprehtejun
authored andcommitted
workqueue: Fix race condition in wq->stats incrementation
Fixed a race condition in incrementing wq->stats[PWQ_STAT_COMPLETED] by moving the operation under pool->lock. Reported-by: syzbot+01affb1491750534256d@syzkaller.appspotmail.com Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 24cdab5 commit 70e1683

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

kernel/workqueue.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3241,7 +3241,7 @@ __acquires(&pool->lock)
32413241
* point will only record its address.
32423242
*/
32433243
trace_workqueue_execute_end(work, worker->current_func);
3244-
pwq->stats[PWQ_STAT_COMPLETED]++;
3244+
32453245
lock_map_release(&lockdep_map);
32463246
if (!bh_draining)
32473247
lock_map_release(pwq->wq->lockdep_map);
@@ -3272,6 +3272,8 @@ __acquires(&pool->lock)
32723272

32733273
raw_spin_lock_irq(&pool->lock);
32743274

3275+
pwq->stats[PWQ_STAT_COMPLETED]++;
3276+
32753277
/*
32763278
* In addition to %WQ_CPU_INTENSIVE, @worker may also have been marked
32773279
* CPU intensive by wq_worker_tick() if @work hogged CPU longer than

0 commit comments

Comments
 (0)