public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched: fix fork() error path to not crash.
@ 2012-06-26  1:18 Salman Qazi
  2012-06-26  8:40 ` Peter Zijlstra
  2012-07-06  6:18 ` [tip:sched/core] sched: Fix " tip-bot for Salman Qazi
  0 siblings, 2 replies; 4+ messages in thread
From: Salman Qazi @ 2012-06-26  1:18 UTC (permalink / raw)
  To: a.p.zijlstra, linux-kernel

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 <sqazi@google.com>
---
 kernel/fork.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/kernel/fork.c b/kernel/fork.c
index ab5211b..f00e319 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -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);


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] sched: fix fork() error path to not crash.
  2012-06-26  1:18 [PATCH] sched: fix fork() error path to not crash Salman Qazi
@ 2012-06-26  8:40 ` Peter Zijlstra
  2012-06-26 16:58   ` Salman Qazi
  2012-07-06  6:18 ` [tip:sched/core] sched: Fix " tip-bot for Salman Qazi
  1 sibling, 1 reply; 4+ messages in thread
From: Peter Zijlstra @ 2012-06-26  8:40 UTC (permalink / raw)
  To: Salman Qazi; +Cc: linux-kernel

On Mon, 2012-06-25 at 18:18 -0700, Salman Qazi wrote:
> 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 <sqazi@google.com>

Cute, however did you find that?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] sched: fix fork() error path to not crash.
  2012-06-26  8:40 ` Peter Zijlstra
@ 2012-06-26 16:58   ` Salman Qazi
  0 siblings, 0 replies; 4+ messages in thread
From: Salman Qazi @ 2012-06-26 16:58 UTC (permalink / raw)
  To: Peter Zijlstra; +Cc: linux-kernel

On Tue, Jun 26, 2012 at 1:40 AM, Peter Zijlstra <a.p.zijlstra@chello.nl> wrote:
> On Mon, 2012-06-25 at 18:18 -0700, Salman Qazi wrote:
>> 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 <sqazi@google.com>
>
> 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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [tip:sched/core] sched: Fix fork() error path to not crash
  2012-06-26  1:18 [PATCH] sched: fix fork() error path to not crash Salman Qazi
  2012-06-26  8:40 ` Peter Zijlstra
@ 2012-07-06  6:18 ` tip-bot for Salman Qazi
  1 sibling, 0 replies; 4+ messages in thread
From: tip-bot for Salman Qazi @ 2012-07-06  6:18 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, a.p.zijlstra, sqazi, tglx

Commit-ID:  164c33c6adee609b8b9062cce4c10f764d0dce13
Gitweb:     http://git.kernel.org/tip/164c33c6adee609b8b9062cce4c10f764d0dce13
Author:     Salman Qazi <sqazi@google.com>
AuthorDate: Mon, 25 Jun 2012 18:18:15 -0700
Committer:  Ingo Molnar <mingo@kernel.org>
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.

Signed-off-by: Salman Qazi <sqazi@google.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/20120626011815.11323.5533.stgit@dungbeetle.mtv.corp.google.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/fork.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/kernel/fork.c b/kernel/fork.c
index ab5211b..f00e319 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -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);

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-07-06  6:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-26  1:18 [PATCH] sched: fix fork() error path to not crash Salman Qazi
2012-06-26  8:40 ` Peter Zijlstra
2012-06-26 16:58   ` Salman Qazi
2012-07-06  6:18 ` [tip:sched/core] sched: Fix " tip-bot for Salman Qazi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox