diff --git a/kernel/fork.c b/kernel/fork.c index bd09773a3c82..a4b0ac52210d 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1516,11 +1516,13 @@ static struct task_struct *copy_process(unsigned long clone_flags, */ recalc_sigpending(); if (signal_pending(current)) { - spin_unlock(¤t->sighand->siglock); - write_unlock_irq(&tasklist_lock); retval = -ERESTARTNOINTR; goto bad_fork_free_pid; } + if (unlikely(!(ns_of_pid(pid)->nr_hashed & PIDNS_HASH_ADDING))) { + retval = -ENOMEM; + goto bad_fork_free_pid; + } if (likely(p->pid)) { ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace); @@ -1567,6 +1569,8 @@ static struct task_struct *copy_process(unsigned long clone_flags, return p; bad_fork_free_pid: + spin_unlock(¤t->sighand->siglock); + write_unlock_irq(&tasklist_lock); if (pid != &init_struct_pid) free_pid(pid); bad_fork_cleanup_io: