The patch titled
Subject: pidns: remove recursion from free_pid_ns()
has been removed from the -mm tree. Its filename was
pidns-remove-recursion-from-free_pid_ns-v3.patch
This patch was dropped because an updated version will be merged
------------------------------------------------------
From: Andrew Vagin <[email protected]>
Subject: pidns: remove recursion from free_pid_ns()
Here is a stack trace of recursion:
free_pid_ns(parent)
put_pid_ns(parent)
kref_put(&ns->kref, free_pid_ns);
free_pid_ns
This patch turns the recursion into loops.
pidns can be nested many times, so in case of recursion a simple userspace
program can provoke a kernel panic due to exceed of a kernel stack.
Acked-by: Cyrill Gorcunov <[email protected]>
Reviewed-by: Oleg Nesterov <[email protected]>
Cc: "Eric W. Biederman" <[email protected]>
Cc: Pavel Emelyanov <[email protected]>
Signed-off-by: Andrew Vagin <[email protected]>
Cc: Greg KH <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
---
include/linux/kref.h | 12 ++++++++++++
kernel/pid_namespace.c | 16 ++++++++++++----
2 files changed, 24 insertions(+), 4 deletions(-)
diff -puN include/linux/kref.h~pidns-remove-recursion-from-free_pid_ns-v3
include/linux/kref.h
--- a/include/linux/kref.h~pidns-remove-recursion-from-free_pid_ns-v3
+++ a/include/linux/kref.h
@@ -95,6 +95,18 @@ static inline int kref_put(struct kref *
return kref_sub(kref, 1, release);
}
+/**
+ * kref_put - decrement refcount for object.
+ * @kref: object.
+ *
+ * Decrement the refcount.
+ * Return 1 if refcount is zero.
+ */
+static inline int __kref_put(struct kref *kref)
+{
+ return atomic_dec_and_test(&kref->refcount);
+}
+
static inline int kref_put_mutex(struct kref *kref,
void (*release)(struct kref *kref),
struct mutex *lock)
diff -puN kernel/pid_namespace.c~pidns-remove-recursion-from-free_pid_ns-v3
kernel/pid_namespace.c
--- a/kernel/pid_namespace.c~pidns-remove-recursion-from-free_pid_ns-v3
+++ a/kernel/pid_namespace.c
@@ -139,11 +139,19 @@ void free_pid_ns(struct kref *kref)
ns = container_of(kref, struct pid_namespace, kref);
- parent = ns->parent;
- destroy_pid_namespace(ns);
+ while (1) {
+ parent = ns->parent;
+ destroy_pid_namespace(ns);
- if (parent != NULL)
- put_pid_ns(parent);
+ if (parent == &init_pid_ns)
+ break;
+
+ /* kref_put cannot be used for avoiding recursion */
+ if (__kref_put(&parent->kref) == 0)
+ break;
+
+ ns = parent;
+ }
}
EXPORT_SYMBOL_GPL(free_pid_ns);
_
Patches currently in -mm which might be from [email protected] are
origin.patch
pidns-remove-recursion-from-free_pid_ns-v5.patch
proc-dont-show-nonexistent-capabilities.patch
--
To unsubscribe from this list: send the line "unsubscribe stable" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html