Skip to contentSkip to conversation

sched: fix fork() error path to not crash.

PATCH In review Salman Qazi 2 participants 4 messages Jun 26, 2012 – Jul 6, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched: fix fork() error path to not crash.

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.

---
 kernel/fork.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
kernel/fork.c +8 -3
index ab5211b..f00e319 100644
@@ -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);
#1 lore raw
Quoted 7 lines · Salman Qazi

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.

Cute, however did you find that?

#2 lore raw
Quoted 10 lines · Peter Zijlstra
Quoted 7 lines · Salman Qazi

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.

Cute, however did you find that?

Our test infrastructure folks have developed a fault injection framework geared towards detecting bugs triggered by memory allocation failures in random places.

#3 lore raw

[tip:sched/core] sched: Fix fork() error path to not crash

In reply to Salman Qazi
Commit-ID:  164c33c6adee609b8b9062cce4c10f764d0dce13
Gitweb:     http://git.kernel.org/tip/164c33c6adee609b8b9062cce4c10f764d0dce13
Author:     Salman Qazi <[email protected]>
AuthorDate: Mon, 25 Jun 2012 18:18:15 -0700
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 5 Jul 2012 20:57:32 +0200

sched: Fix fork() error path to not crash

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.

---
 kernel/fork.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
kernel/fork.c +8 -3
index ab5211b..f00e319 100644
@@ -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);