linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] fork: fix oops after fork failure
@ 2012-08-23 15:36 Glauber Costa
  2012-08-23 16:04 ` Frederic Weisbecker
  2012-08-24 22:08 ` Andrew Morton
  0 siblings, 2 replies; 4+ messages in thread
From: Glauber Costa @ 2012-08-23 15:36 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, torvalds, Peter Zijlstra, Frederic Weisbecker,
	Glauber Costa, Thomas Gleixner, Tony Luck, Fenghua Yu

When we want to duplicate a new process, dup_task_struct() will undergo
a series of allocations. If alloc_thread_info_node() fails, we call
free_task_struct() and return.

This seems right, but it is not. free_task_struct() will not only free
the task struct from the kmem_cache, but will also call
arch_release_task_struct(). The problem is that this function is
supposed to undo whatever arch-specific work done by
arch_dup_task_struct(), that is not yet called at this point.  The
particular problem I ran accross was that in x86, we will arrive at
fpu_free() without having ever allocated it.

Signed-off-by: Glauber Costa <glommer@parallels.com>
Reported-by: Frederic Weisbecker <fweisbec@redhat.com>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Tony Luck <tony.luck@intel.com>
CC: Fenghua Yu <fenghua.yu@intel.com>
---
 arch/ia64/include/asm/thread_info.h | 2 +-
 kernel/fork.c                       | 9 +++++++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/ia64/include/asm/thread_info.h b/arch/ia64/include/asm/thread_info.h
index f7ee853..62452bd 100644
--- a/arch/ia64/include/asm/thread_info.h
+++ b/arch/ia64/include/asm/thread_info.h
@@ -90,7 +90,7 @@ struct thread_info {
 										\
 	ret;									\
 })
-#define free_task_struct(tsk)	free_pages((unsigned long) (tsk), KERNEL_STACK_SIZE_ORDER)
+#define __free_task_struct(tsk)	free_pages((unsigned long) (tsk), KERNEL_STACK_SIZE_ORDER)
 
 #endif /* !__ASSEMBLY */
 
diff --git a/kernel/fork.c b/kernel/fork.c
index 152d023..76acb1a 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -124,10 +124,15 @@ static inline struct task_struct *alloc_task_struct_node(int node)
 
 void __weak arch_release_task_struct(struct task_struct *tsk) { }
 
+static inline void __free_task_struct(struct task_struct *tsk)
+{
+	kmem_cache_free(task_struct_cachep, tsk);
+}
+
 static inline void free_task_struct(struct task_struct *tsk)
 {
 	arch_release_task_struct(tsk);
-	kmem_cache_free(task_struct_cachep, tsk);
+	__free_task_struct(tsk);
 }
 #endif
 
@@ -299,7 +304,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
 
 	ti = alloc_thread_info_node(tsk, node);
 	if (!ti) {
-		free_task_struct(tsk);
+		__free_task_struct(tsk);
 		return NULL;
 	}
 
-- 
1.7.11.4


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

* Re: [PATCH v2] fork: fix oops after fork failure
  2012-08-23 15:36 [PATCH v2] fork: fix oops after fork failure Glauber Costa
@ 2012-08-23 16:04 ` Frederic Weisbecker
  2012-08-24 22:08 ` Andrew Morton
  1 sibling, 0 replies; 4+ messages in thread
From: Frederic Weisbecker @ 2012-08-23 16:04 UTC (permalink / raw)
  To: Glauber Costa
  Cc: linux-kernel, Andrew Morton, torvalds, Peter Zijlstra,
	Thomas Gleixner, Tony Luck, Fenghua Yu

On Thu, Aug 23, 2012 at 07:36:08PM +0400, Glauber Costa wrote:
> When we want to duplicate a new process, dup_task_struct() will undergo
> a series of allocations. If alloc_thread_info_node() fails, we call
> free_task_struct() and return.
> 
> This seems right, but it is not. free_task_struct() will not only free
> the task struct from the kmem_cache, but will also call
> arch_release_task_struct(). The problem is that this function is
> supposed to undo whatever arch-specific work done by
> arch_dup_task_struct(), that is not yet called at this point.  The
> particular problem I ran accross was that in x86, we will arrive at
> fpu_free() without having ever allocated it.
> 
> Signed-off-by: Glauber Costa <glommer@parallels.com>
> Reported-by: Frederic Weisbecker <fweisbec@redhat.com>

Tested-by: Frederic Weisbecker <fweisbec@redhat.com>

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

* Re: [PATCH v2] fork: fix oops after fork failure
  2012-08-23 15:36 [PATCH v2] fork: fix oops after fork failure Glauber Costa
  2012-08-23 16:04 ` Frederic Weisbecker
@ 2012-08-24 22:08 ` Andrew Morton
  2012-08-26  2:06   ` Glauber Costa
  1 sibling, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2012-08-24 22:08 UTC (permalink / raw)
  To: Glauber Costa
  Cc: linux-kernel, torvalds, Peter Zijlstra, Frederic Weisbecker,
	Thomas Gleixner, Tony Luck, Fenghua Yu

On Thu, 23 Aug 2012 19:36:08 +0400
Glauber Costa <glommer@parallels.com> wrote:

> When we want to duplicate a new process, dup_task_struct() will undergo
> a series of allocations. If alloc_thread_info_node() fails, we call
> free_task_struct() and return.
> 
> This seems right, but it is not. free_task_struct() will not only free
> the task struct from the kmem_cache, but will also call
> arch_release_task_struct(). The problem is that this function is
> supposed to undo whatever arch-specific work done by
> arch_dup_task_struct(), that is not yet called at this point.  The
> particular problem I ran accross was that in x86, we will arrive at
> fpu_free() without having ever allocated it.

I think ths was already fixed by f19b9f74b7ea3b ("fork: fix error
handling in dup_task()").  As you would have noticed if you were
preparing patches against up-to-date kernel versions!


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

* Re: [PATCH v2] fork: fix oops after fork failure
  2012-08-24 22:08 ` Andrew Morton
@ 2012-08-26  2:06   ` Glauber Costa
  0 siblings, 0 replies; 4+ messages in thread
From: Glauber Costa @ 2012-08-26  2:06 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, torvalds, Peter Zijlstra, Frederic Weisbecker,
	Thomas Gleixner, Tony Luck, Fenghua Yu

On 08/24/2012 06:08 PM, Andrew Morton wrote:
> On Thu, 23 Aug 2012 19:36:08 +0400
> Glauber Costa <glommer@parallels.com> wrote:
> 
>> When we want to duplicate a new process, dup_task_struct() will undergo
>> a series of allocations. If alloc_thread_info_node() fails, we call
>> free_task_struct() and return.
>>
>> This seems right, but it is not. free_task_struct() will not only free
>> the task struct from the kmem_cache, but will also call
>> arch_release_task_struct(). The problem is that this function is
>> supposed to undo whatever arch-specific work done by
>> arch_dup_task_struct(), that is not yet called at this point.  The
>> particular problem I ran accross was that in x86, we will arrive at
>> fpu_free() without having ever allocated it.
> 
> I think ths was already fixed by f19b9f74b7ea3b ("fork: fix error
> handling in dup_task()").  As you would have noticed if you were
> preparing patches against up-to-date kernel versions!
> 
I am basing all my patches against mmotm (actually, Michal's git copy of
it...)
I might have missed one spin, though. It happens

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

end of thread, other threads:[~2012-08-26  2:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-23 15:36 [PATCH v2] fork: fix oops after fork failure Glauber Costa
2012-08-23 16:04 ` Frederic Weisbecker
2012-08-24 22:08 ` Andrew Morton
2012-08-26  2:06   ` Glauber Costa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).