Re: [PATCH] workqueue: sanity check pool->cpu in wq_worker_sleeping()

From: Tejun Heo
Date: Thu Jun 19 2014 - 12:32:22 EST


On Tue, Jun 03, 2014 at 03:33:08PM +0800, Lai Jiangshan wrote:
> 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 <laijs@xxxxxxxxxxxxxx>
> ---
> kernel/workqueue.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/kernel/workqueue.c b/kernel/workqueue.c
> index 9f53abd..61381a2 100644
> --- a/kernel/workqueue.c
> +++ b/kernel/workqueue.c
> @@ -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.

--
tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/