Skip to contentSkip to conversation

workqueue: sanity check pool->cpu in wq_worker_sleeping()

PATCH Applied Lai Jiangshan 2 participants 2 messages Jun 3, 2014 – Jun 19, 2014 Workqueue

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 workqueue: sanity check pool->cpu in wq_worker_sleeping()

In theory, pool->cpu is equals to @cpu in wq_worker_sleeping() after worker->flags is checked.

And "pool->cpu != cpu" sanity check will help us if something wrong.

---
 kernel/workqueue.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/workqueue.c +1 -1
index 9f53abd..61381a2 100644
@@ -843,7 +843,7 @@ struct task_struct *wq_worker_sleeping(struct task_struct *task, int cpu)
 	pool = worker->pool;
 
 	/* this can only happen on the local cpu */
-	if (WARN_ON_ONCE(cpu != raw_smp_processor_id()))
+	if (WARN_ON_ONCE(cpu != raw_smp_processor_id() || pool->cpu != cpu))
 		return NULL;
 
 	/*
Signature · 1 line
1.7.4.4
maintainer Applied
#1 lore raw
Quoted 15 lines · Lai Jiangshan

In theory, pool->cpu is equals to @cpu in wq_worker_sleeping() after worker->flags is checked.

And "pool->cpu != cpu" sanity check will help us if something wrong.

---
 kernel/workqueue.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/workqueue.c +0 -0
index 9f53abd..61381a2 100644

kernel/workqueue.c struct task_struct *wq_worker_sleeping(struct task_struct *task, int cpu) · line 846

Quoted 5 lines
kernel/workqueue.c +1 -1
@@ -843,7 +843,7 @@ struct task_struct *wq_worker_sleeping(struct task_struct *task, int cpu)
 	pool = worker->pool;
 
 	/* this can only happen on the local cpu */
-	if (WARN_ON_ONCE(cpu != raw_smp_processor_id()))
+	if (WARN_ON_ONCE(cpu != raw_smp_processor_id() || pool->cpu != cpu))

Hmmm... yeah, this can catch work functions hijacking and binding per-cpu worker to another cpu.

Applied to wq/for-3.17.

Thanks.

Signature · 1 line
tejun