From: Matthew Wilcox Date: Fri, 28 Dec 2018 15:22:26 +0000 (-0800) Subject: Fix failure path in alloc_pid() X-Git-Tag: v5.15~7321 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1a80dade010c7a7f4885a4c4c2a7ac22cc7b34df;p=platform%2Fkernel%2Flinux-starfive.git Fix failure path in alloc_pid() The failure path removes the allocated PIDs from the wrong namespace. This could lead to us inadvertently reusing PIDs in the leaf namespace and leaking PIDs in parent namespaces. Fixes: 95846ecf9dac ("pid: replace pid bitmap implementation with IDR API") Cc: Signed-off-by: Matthew Wilcox Acked-by: "Eric W. Biederman" Reviewed-by: Oleg Nesterov Signed-off-by: Linus Torvalds --- diff --git a/kernel/pid.c b/kernel/pid.c index b2f6c50..2088159 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -233,8 +233,10 @@ out_unlock: out_free: spin_lock_irq(&pidmap_lock); - while (++i <= ns->level) - idr_remove(&ns->idr, (pid->numbers + i)->nr); + while (++i <= ns->level) { + upid = pid->numbers + i; + idr_remove(&upid->ns->idr, upid->nr); + } /* On failure to allocate the first pid, reset the state */ if (ns->pid_allocated == PIDNS_ADDING)