Skip to content

Commit

Permalink
sched: Fix fork() error path to not crash
Browse files Browse the repository at this point in the history
In dup_task_struct(), if arch_dup_task_struct() fails, the clean up
code fails to clean up correctly.  That's because the clean up
code depends on unininitalized ti->task pointer.  We fix this
by making sure that the task and thread_info know about each other
before we attempt to take the error path.

Signed-off-by: Salman Qazi <[email protected]>
Signed-off-by: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
sqazi authored and Ingo Molnar committed Jul 5, 2012
1 parent 9e85a6f commit 164c33c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,17 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
}

err = arch_dup_task_struct(tsk, orig);
if (err)
goto out;

/*
* We defer looking at err, because we will need this setup
* for the clean up path to work correctly.
*/
tsk->stack = ti;

setup_thread_stack(tsk, orig);

if (err)
goto out;

clear_user_return_notifier(tsk);
clear_tsk_need_resched(tsk);
stackend = end_of_stack(tsk);
Expand Down

0 comments on commit 164c33c

Please sign in to comment.