Commit dd9037a2 authored by Srivatsa Vaddagiri's avatar Srivatsa Vaddagiri Committed by Linus Torvalds

Fix race between attach_task and cpuset_exit

Currently cpuset_exit() changes the exiting task's ->cpuset pointer w/o
taking task_lock().  This can lead to ugly races between attach_task and
cpuset_exit.  Details of the races are described at
http://lkml.org/lkml/2007/3/24/132.

Patch below closes those races.
Signed-off-by: default avatarSrivatsa Vaddagiri <vatsa@in.ibm.com>
Cc: Paul Jackson <pj@sgi.com>
Cc: Balbir Singh <balbir@in.ibm.com>
Cc: Paul Menage <menage@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent e5f00f42
...@@ -2200,10 +2200,6 @@ void cpuset_fork(struct task_struct *child) ...@@ -2200,10 +2200,6 @@ void cpuset_fork(struct task_struct *child)
* it is holding that mutex while calling check_for_release(), * it is holding that mutex while calling check_for_release(),
* which calls kmalloc(), so can't be called holding callback_mutex(). * which calls kmalloc(), so can't be called holding callback_mutex().
* *
* We don't need to task_lock() this reference to tsk->cpuset,
* because tsk is already marked PF_EXITING, so attach_task() won't
* mess with it, or task is a failed fork, never visible to attach_task.
*
* the_top_cpuset_hack: * the_top_cpuset_hack:
* *
* Set the exiting tasks cpuset to the root cpuset (top_cpuset). * Set the exiting tasks cpuset to the root cpuset (top_cpuset).
...@@ -2242,8 +2238,10 @@ void cpuset_exit(struct task_struct *tsk) ...@@ -2242,8 +2238,10 @@ void cpuset_exit(struct task_struct *tsk)
{ {
struct cpuset *cs; struct cpuset *cs;
task_lock(current);
cs = tsk->cpuset; cs = tsk->cpuset;
tsk->cpuset = &top_cpuset; /* the_top_cpuset_hack - see above */ tsk->cpuset = &top_cpuset; /* the_top_cpuset_hack - see above */
task_unlock(current);
if (notify_on_release(cs)) { if (notify_on_release(cs)) {
char *pathbuf = NULL; char *pathbuf = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment