diff options
author | Peter Zijlstra <peterz@infradead.org> | 2015-05-15 11:43:34 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2015-08-12 06:06:09 -0400 |
commit | 25834c73f93af7f0712c98ca4593691592e6b360 (patch) | |
tree | 5da4f7c4da2a85ba6458a4de234da5e3d0a0c27a /kernel/workqueue.c | |
parent | 7855a35ac07a350e2cd26f09568a6d8e372be358 (diff) |
sched: Fix a race between __kthread_bind() and sched_setaffinity()
Because sched_setscheduler() checks p->flags & PF_NO_SETAFFINITY
without locks, a caller might observe an old value and race with the
set_cpus_allowed_ptr() call from __kthread_bind() and effectively undo
it:
__kthread_bind()
do_set_cpus_allowed()
<SYSCALL>
sched_setaffinity()
if (p->flags & PF_NO_SETAFFINITIY)
set_cpus_allowed_ptr()
p->flags |= PF_NO_SETAFFINITY
Fix the bug by putting everything under the regular scheduler locks.
This also closes a hole in the serialization of task_struct::{nr_,}cpus_allowed.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: dedekind1@gmail.com
Cc: juri.lelli@arm.com
Cc: mgorman@suse.de
Cc: riel@redhat.com
Cc: rostedt@goodmis.org
Link: http://lkml.kernel.org/r/20150515154833.545640346@infradead.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel/workqueue.c')
-rw-r--r-- | kernel/workqueue.c | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 4c4f06176f74..f5782d5fd196 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c | |||
@@ -1714,9 +1714,7 @@ static struct worker *create_worker(struct worker_pool *pool) | |||
1714 | goto fail; | 1714 | goto fail; |
1715 | 1715 | ||
1716 | set_user_nice(worker->task, pool->attrs->nice); | 1716 | set_user_nice(worker->task, pool->attrs->nice); |
1717 | 1717 | kthread_bind_mask(worker->task, pool->attrs->cpumask); | |
1718 | /* prevent userland from meddling with cpumask of workqueue workers */ | ||
1719 | worker->task->flags |= PF_NO_SETAFFINITY; | ||
1720 | 1718 | ||
1721 | /* successful, attach the worker to the pool */ | 1719 | /* successful, attach the worker to the pool */ |
1722 | worker_attach_to_pool(worker, pool); | 1720 | worker_attach_to_pool(worker, pool); |
@@ -3856,7 +3854,7 @@ struct workqueue_struct *__alloc_workqueue_key(const char *fmt, | |||
3856 | } | 3854 | } |
3857 | 3855 | ||
3858 | wq->rescuer = rescuer; | 3856 | wq->rescuer = rescuer; |
3859 | rescuer->task->flags |= PF_NO_SETAFFINITY; | 3857 | kthread_bind_mask(rescuer->task, cpu_possible_mask); |
3860 | wake_up_process(rescuer->task); | 3858 | wake_up_process(rescuer->task); |
3861 | } | 3859 | } |
3862 | 3860 | ||