[PATCH] fork: fix oops after fork failure

From: Glauber Costa
Date: Thu Aug 23 2012 - 09:12:02 EST


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.

This code is very ancient, and according to git, it is there since the
pre-git era. But forks don't fail that often, so that made it well
hidden.

Signed-off-by: Glauber Costa <glommer@xxxxxxxxxxxxx>
Reported-by: Frederic Weisbecker <fweisbec@xxxxxxxxxx>
---
kernel/fork.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/fork.c b/kernel/fork.c
index 152d023..b397435 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -299,7 +299,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);
+ kmem_cache_free(task_struct_cachep, tsk);
return NULL;
}

--
1.7.11.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/