Skip to content

Commit a854491

Browse files
Matthew Wilcoxgregkh
authored andcommitted
Fix failure path in alloc_pid()
commit 1a80dad upstream. 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: 95846ec ("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> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5781b53 commit a854491

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎kernel/pid.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,10 @@ struct pid *alloc_pid(struct pid_namespace *ns)
233233

234234
out_free:
235235
spin_lock_irq(&pidmap_lock);
236-
while (++i <= ns->level)
237-
idr_remove(&ns->idr, (pid->numbers + i)->nr);
236+
while (++i <= ns->level) {
237+
upid = pid->numbers + i;
238+
idr_remove(&upid->ns->idr, upid->nr);
239+
}
238240

239241
/* On failure to allocate the first pid, reset the state */
240242
if (ns->pid_allocated == PIDNS_ADDING)

0 commit comments

Comments
 (0)