diff options
author | Cyrill Gorcunov <gorcunov@openvz.org> | 2012-10-19 16:56:53 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-10-19 17:07:47 -0400 |
commit | bbc2e3ef87851bc5430b2b4cf4ca3a2f29baeda6 (patch) | |
tree | d9cef396c8370184f23e99480725aa8fde4bea08 /kernel | |
parent | dc36d7e7cd422d69b15e7ec7cc1f021f581a6b6d (diff) |
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.
[akpm@linux-foundation.org: export put_pid_ns() to modules]
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Cc: Andrew Vagin <avagin@openvz.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Pavel Emelyanov <xemul@parallels.com>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/pid_namespace.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c index 478bad2745e3..eb00be205811 100644 --- a/kernel/pid_namespace.c +++ b/kernel/pid_namespace.c | |||
@@ -133,19 +133,26 @@ struct pid_namespace *copy_pid_ns(unsigned long flags, struct pid_namespace *old | |||
133 | return create_pid_namespace(old_ns); | 133 | return create_pid_namespace(old_ns); |
134 | } | 134 | } |
135 | 135 | ||
136 | void free_pid_ns(struct kref *kref) | 136 | static void free_pid_ns(struct kref *kref) |
137 | { | 137 | { |
138 | struct pid_namespace *ns, *parent; | 138 | struct pid_namespace *ns; |
139 | 139 | ||
140 | ns = container_of(kref, struct pid_namespace, kref); | 140 | ns = container_of(kref, struct pid_namespace, kref); |
141 | |||
142 | parent = ns->parent; | ||
143 | destroy_pid_namespace(ns); | 141 | destroy_pid_namespace(ns); |
142 | } | ||
144 | 143 | ||
145 | if (parent != NULL) | 144 | void put_pid_ns(struct pid_namespace *ns) |
146 | put_pid_ns(parent); | 145 | { |
146 | struct pid_namespace *parent; | ||
147 | |||
148 | while (ns != &init_pid_ns) { | ||
149 | parent = ns->parent; | ||
150 | if (!kref_put(&ns->kref, free_pid_ns)) | ||
151 | break; | ||
152 | ns = parent; | ||
153 | } | ||
147 | } | 154 | } |
148 | EXPORT_SYMBOL_GPL(free_pid_ns); | 155 | EXPORT_SYMBOL_GPL(put_pid_ns); |
149 | 156 | ||
150 | void zap_pid_ns_processes(struct pid_namespace *pid_ns) | 157 | void zap_pid_ns_processes(struct pid_namespace *pid_ns) |
151 | { | 158 | { |