Commit 3299a0ee authored by KJ Tsanaktsidis's avatar KJ Tsanaktsidis Committed by Greg Kroah-Hartman
Browse files

fork: report pid exhaustion correctly

commit f83606f5 upstream.

Make the clone and fork syscalls return EAGAIN when the limit on the
number of pids /proc/sys/kernel/pid_max is exceeded.

Currently, when the pid_max limit is exceeded, the kernel will return
ENOSPC from the fork and clone syscalls.  This is contrary to the
documented behaviour, which explicitly calls out the pid_max case as one
where EAGAIN should be returned.  It also leads to really confusing error
messages in userspace programs which will complain about a lack of disk
space when they fail to create processes/threads for this reason.

This error is being returned because alloc_pid() uses the idr api to find
a new pid; when there are none available, idr_alloc_cyclic() returns
-ENOSPC, and this is being propagated back to userspace.

This behaviour has been broken before, and was explicitly fixed in
commit 35f71bc0 ("fork: report pid reservation failure properly"),
so I think -EAGAIN is definitely the right thing to return in this case.
The current behaviour change dates from commit 95846ecf ("pid:
replace pid bitmap implementation with IDR AIP") and was I believe

This patch has no impact on the case where allocating a pid fails because
the child reaper for the namespace is dead; that case will still return

Fixes: 95846ecf

 ("pid: replace pid bitmap implementation with IDR AIP")
Signed-off-by: default avatarKJ Tsanaktsidis <>
Reviewed-by: default avatarAndrew Morton <>
Acked-by: default avatarMichal Hocko <>
Cc: Gargi Sharma <>
Cc: Rik van Riel <>
Cc: Oleg Nesterov <>
Cc: <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarGreg Kroah-Hartman <>
parent 30938d20
......@@ -195,7 +195,7 @@ struct pid *alloc_pid(struct pid_namespace *ns)
if (nr < 0) {
retval = nr;
retval = (nr == -ENOSPC) ? -EAGAIN : nr;
goto out_free;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment