Messages in this thread Patch in this message | | | From | Lai Jiangshan <> | Subject | [PATCH] workqueue: ensure @task is valid across kthread_stop() | Date | Sat, 15 Feb 2014 22:02:28 +0800 |
| |
When a worker is set WORKER_DIE, it may die very quickly, and kthread_stop() will access to a stale task stuct/stack. To avoid this, we use get_task_struct() to ensure @task is valid.
See more comments in kthread_create_on_node()&kthread_stop(). Note: comments in kthread_create_on_node() does not elaborate any use case like this patch, but it is a valid way to use kthread_stop().
CC: stable@vger.kernel.org Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com> --- kernel/workqueue.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 82ef9f3..783d5f2 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -1856,9 +1856,12 @@ static void destroy_worker(struct worker *worker) idr_remove(&pool->worker_idr, worker->id); + /* Enusre the @worker->task is valid across kthread_stop() */ + get_task_struct(worker->task); spin_unlock_irq(&pool->lock); kthread_stop(worker->task); + put_task_struct(worker->task); kfree(worker); spin_lock_irq(&pool->lock); -- 1.7.7.6
| |