fork.c: fix NULL pointer dereference when nr_threads == threads-max
authorLi Zefan <lizf@cn.fujitsu.com>
Fri, 6 Feb 2009 08:17:19 +0000 (08:17 +0000)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 6 Feb 2009 16:43:11 +0000 (08:43 -0800)
I happened to forked lots of processes, and hit NULL pointer dereference.
It is because in copy_process() after checking max_threads, 0 is returned
but not -EAGAIN.

The bug is introduced by "CRED: Detach the credentials from task_struct"
(commit f1752eec6145c97163dbce62d17cf5d928e28a27).

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
kernel/fork.c

index 242a706e77218073f74b9b8aa44ca589aaa1cbf4..6d5dbb7a13e253132f9281fcfaf9a112f576ff38 100644 (file)
@@ -1005,6 +1005,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
         * triggers too late. This doesn't hurt, the check is only there
         * to stop root fork bombs.
         */
+       retval = -EAGAIN;
        if (nr_threads >= max_threads)
                goto bad_fork_cleanup_count;