Re: [RFC][PATCH 1/4] sched: Fix a race between __kthread_bind() and sched_setaffinity()

From: Tejun Heo
Date: Fri May 15 2015 - 11:57:04 EST


On Fri, May 15, 2015 at 05:43:34PM +0200, Peter Zijlstra wrote:
> 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 issue by putting everything under the regular scheduler locks.
>
> This also closes a hole in the serialization of
> task_struct::{nr_,}cpus_allowed.
>
> Cc: Tejun Heo <tj@xxxxxxxxxx>
> Cc: Oleg Nesterov <oleg@xxxxxxxxxx>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>

For workqueue part,

Acked-by: Tejun Heo <tj@xxxxxxxxxx>

Please route anyway you see fit.

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/