]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
workqueue: Fix race condition in wq->stats incrementation
authorJiayuan Chen <jiayuan.chen@linux.dev>
Wed, 23 Apr 2025 16:17:42 +0000 (00:17 +0800)
committerTejun Heo <tj@kernel.org>
Wed, 23 Apr 2025 16:58:57 +0000 (06:58 -1000)
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>
kernel/workqueue.c

index 2cb8276a27a99c951883d09ed2dbd5f488bda8e2..f9ef467020cffc72b607fddd70eb4875041b8848 100644 (file)
@@ -3241,7 +3241,7 @@ __acquires(&pool->lock)
         * point will only record its address.
         */
        trace_workqueue_execute_end(work, worker->current_func);
-       pwq->stats[PWQ_STAT_COMPLETED]++;
+
        lock_map_release(&lockdep_map);
        if (!bh_draining)
                lock_map_release(pwq->wq->lockdep_map);
@@ -3272,6 +3272,8 @@ __acquires(&pool->lock)
 
        raw_spin_lock_irq(&pool->lock);
 
+       pwq->stats[PWQ_STAT_COMPLETED]++;
+
        /*
         * In addition to %WQ_CPU_INTENSIVE, @worker may also have been marked
         * CPU intensive by wq_worker_tick() if @work hogged CPU longer than