pidns: remove recursion from free_pid_ns()
authorCyrill Gorcunov <[email protected]>
Fri, 19 Oct 2012 20:56:53 +0000 (13:56 -0700)
committerLinus Torvalds <[email protected]>
Fri, 19 Oct 2012 21:07:47 +0000 (14:07 -0700)
commitbbc2e3ef87851bc5430b2b4cf4ca3a2f29baeda6
treed9cef396c8370184f23e99480725aa8fde4bea08
parentdc36d7e7cd422d69b15e7ec7cc1f021f581a6b6d
pidns: remove recursion from free_pid_ns()

free_pid_ns() operates in a recursive fashion:

free_pid_ns(parent)
  put_pid_ns(parent)
    kref_put(&ns->kref, free_pid_ns);
      free_pid_ns

thus if there was a huge nesting of namespaces the userspace may trigger
avalanche calling of free_pid_ns leading to kernel stack exhausting and a
panic eventually.

This patch turns the recursion into an iterative loop.

Based on a patch by Andrew Vagin.

[[email protected]: export put_pid_ns() to modules]
Signed-off-by: Cyrill Gorcunov <[email protected]>
Cc: Andrew Vagin <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: "Eric W. Biederman" <[email protected]>
Cc: Pavel Emelyanov <[email protected]>
Cc: Greg KH <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
include/linux/pid_namespace.h
kernel/pid_namespace.c