workqueue: Fix NULL current_pwq deref in current_is_workqueue_mem_reclaim()
Subsystems (2)
PATCH 1/1 workqueue: Fix NULL current_pwq deref in current_is_workqueue_mem_reclaim()
current_wq_worker() indicates that %current is a kworker thread, but it does not guarantee that the worker is currently executing a work item, as worker->current_pwq is populated only while process_one_work() is actively running the work function. Outside of that window (e.g. during worker idle, initialization, or auxiliary execution paths), worker->current_pwq is NULL.
In current_is_workqueue_mem_reclaim(), worker->current_pwq->wq is dereferenced without checking worker->current_pwq:
return worker && ((worker->current_pwq->wq->flags & (WQ_MEM_RECLAIM | __WQ_LEGACY)) == WQ_MEM_RECLAIM);
If current_is_workqueue_mem_reclaim() is called when worker->current_pwq is NULL, the kernel triggers a NULL pointer dereference.
This mirrors the issue recently fixed in is_chained_work() by commit 980db94e3eee ("workqueue: Fix NULL current_pwq deref in chained work check").
Guard the check with worker->current_pwq before dereferencing ->wq.
--- kernel/workqueue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/workqueue.c +1 -1
@@ -6320,7 +6320,7 @@ bool current_is_workqueue_mem_reclaim(void) {struct worker *worker =current_wq_worker (); -return worker && +return worker && worker->current_pwq && ((worker->current_pwq->wq->flags & (WQ_MEM_RECLAIM | __WQ_LEGACY)) ==WQ_MEM_RECLAIM ); }
Signature · 1 line
2.43.0
Tejun Heo
maintainerHello, Dung.
The same fix was posted earlier by Pavankumar Kondeti and is now applied to wq/for-7.3-fixes:
https://lore.kernel.org/all/[email protected]/
Thanks.
--
tejun