workqueue: sanity check pool->cpu in wq_worker_sleeping()
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.
Signed-off-by Lai Jiangshan <[email protected]>
--- kernel/workqueue.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
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))return NULL ;/*
Signature · 1 line
1.7.4.4
Quoted 15 lines · Lai Jiangshan
In theory,
pool->cpuis equals to @cpu inwq_worker_sleeping()afterworker->flagsis checked.And "
pool->cpu!= cpu" sanity check will help us if something wrong.Signed-off-by Lai Jiangshan <[email protected]>--- kernel/workqueue.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)kernel/workqueue.c +0
-0
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