linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix failure path in alloc_pid()
@ 2018-12-28 15:22 Matthew Wilcox
  2018-12-28 20:53 ` Linus Torvalds
  0 siblings, 1 reply; 2+ messages in thread
From: Matthew Wilcox @ 2018-12-28 15:22 UTC (permalink / raw)
  To: Andrew Morton, Linus Torvalds, linux-kernel; +Cc: Matthew Wilcox, stable

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: <stable@vger.kernel.org>
Signed-off-by: Matthew Wilcox <willy@infradead.org>
Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>
Reviewed-by: Oleg Nesterov <oleg@redhat.com>
---
 kernel/pid.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/pid.c b/kernel/pid.c
index b2f6c506035da..20881598bdfac 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -233,8 +233,10 @@ struct pid *alloc_pid(struct pid_namespace *ns)
 
 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)
-- 
2.19.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix failure path in alloc_pid()
  2018-12-28 15:22 [PATCH] Fix failure path in alloc_pid() Matthew Wilcox
@ 2018-12-28 20:53 ` Linus Torvalds
  0 siblings, 0 replies; 2+ messages in thread
From: Linus Torvalds @ 2018-12-28 20:53 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: Andrew Morton, Linux List Kernel Mailing, stable

On Fri, Dec 28, 2018 at 7:22 AM Matthew Wilcox <willy@infradead.org> wrote:
>
> 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.

Applied,

             Linus

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-12-28 20:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-28 15:22 [PATCH] Fix failure path in alloc_pid() Matthew Wilcox
2018-12-28 20:53 ` Linus Torvalds

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).