diff options
author | Paul Jackson <pj@sgi.com> | 2006-01-08 04:01:53 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-01-08 23:13:43 -0500 |
commit | b4b2641843db124637fa3d2cb2101982035dcc82 (patch) | |
tree | fe8ed223f2e1828a6d14090711bad1c864aded09 /kernel/cpuset.c | |
parent | 59dac16fb95f09253b8086134443abeb439703cd (diff) |
[PATCH] cpuset: fork hook fix
Fix obscure, never seen in real life, cpuset fork race. The cpuset_fork()
call in fork.c was setting up the correct task->cpuset pointer after the
tasklist_lock was dropped, which briefly exposed the newly forked process with
an unsafe (copied from parent without locks or usage counter increment) cpuset
pointer.
In theory, that exposed cpuset pointer could have been pointing at a cpuset
that was already freed and removed, and in theory another task that had been
sitting on the tasklist_lock waiting to scan the task list could have raced
down the entire tasklist, found our new child at the far end, and dereferenced
that bogus cpuset pointer.
To fix, setup up the correct cpuset pointer in the new child by calling
cpuset_fork() before the new task is linked into the tasklist, and with that,
add a fork failure case, to dereference that cpuset, if the fork fails along
the way, after cpuset_fork() was called.
Had to remove a BUG_ON() from cpuset_exit(), because it was no longer valid -
the call to cpuset_exit() from a failed fork would not have PF_EXITING set.
Signed-off-by: Paul Jackson <pj@sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'kernel/cpuset.c')
-rw-r--r-- | kernel/cpuset.c | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/kernel/cpuset.c b/kernel/cpuset.c index 3ea63da11d71..d9349cc48b95 100644 --- a/kernel/cpuset.c +++ b/kernel/cpuset.c | |||
@@ -1821,15 +1821,13 @@ void cpuset_fork(struct task_struct *child) | |||
1821 | * | 1821 | * |
1822 | * We don't need to task_lock() this reference to tsk->cpuset, | 1822 | * We don't need to task_lock() this reference to tsk->cpuset, |
1823 | * because tsk is already marked PF_EXITING, so attach_task() won't | 1823 | * because tsk is already marked PF_EXITING, so attach_task() won't |
1824 | * mess with it. | 1824 | * mess with it, or task is a failed fork, never visible to attach_task. |
1825 | **/ | 1825 | **/ |
1826 | 1826 | ||
1827 | void cpuset_exit(struct task_struct *tsk) | 1827 | void cpuset_exit(struct task_struct *tsk) |
1828 | { | 1828 | { |
1829 | struct cpuset *cs; | 1829 | struct cpuset *cs; |
1830 | 1830 | ||
1831 | BUG_ON(!(tsk->flags & PF_EXITING)); | ||
1832 | |||
1833 | cs = tsk->cpuset; | 1831 | cs = tsk->cpuset; |
1834 | tsk->cpuset = NULL; | 1832 | tsk->cpuset = NULL; |
1835 | 1833 | ||