aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/pid_namespace.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/pid_namespace.c')
-rw-r--r--kernel/pid_namespace.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
index 478bad2745e3..7b07cc0dfb75 100644
--- a/kernel/pid_namespace.c
+++ b/kernel/pid_namespace.c
@@ -71,12 +71,22 @@ err_alloc:
71 return NULL; 71 return NULL;
72} 72}
73 73
74/* MAX_PID_NS_LEVEL is needed for limiting size of 'struct pid' */
75#define MAX_PID_NS_LEVEL 32
76
74static struct pid_namespace *create_pid_namespace(struct pid_namespace *parent_pid_ns) 77static struct pid_namespace *create_pid_namespace(struct pid_namespace *parent_pid_ns)
75{ 78{
76 struct pid_namespace *ns; 79 struct pid_namespace *ns;
77 unsigned int level = parent_pid_ns->level + 1; 80 unsigned int level = parent_pid_ns->level + 1;
78 int i, err = -ENOMEM; 81 int i;
82 int err;
83
84 if (level > MAX_PID_NS_LEVEL) {
85 err = -EINVAL;
86 goto out;
87 }
79 88
89 err = -ENOMEM;
80 ns = kmem_cache_zalloc(pid_ns_cachep, GFP_KERNEL); 90 ns = kmem_cache_zalloc(pid_ns_cachep, GFP_KERNEL);
81 if (ns == NULL) 91 if (ns == NULL)
82 goto out; 92 goto out;
@@ -133,19 +143,26 @@ struct pid_namespace *copy_pid_ns(unsigned long flags, struct pid_namespace *old
133 return create_pid_namespace(old_ns); 143 return create_pid_namespace(old_ns);
134} 144}
135 145
136void free_pid_ns(struct kref *kref) 146static void free_pid_ns(struct kref *kref)
137{ 147{
138 struct pid_namespace *ns, *parent; 148 struct pid_namespace *ns;
139 149
140 ns = container_of(kref, struct pid_namespace, kref); 150 ns = container_of(kref, struct pid_namespace, kref);
141
142 parent = ns->parent;
143 destroy_pid_namespace(ns); 151 destroy_pid_namespace(ns);
152}
153
154void put_pid_ns(struct pid_namespace *ns)
155{
156 struct pid_namespace *parent;
144 157
145 if (parent != NULL) 158 while (ns != &init_pid_ns) {
146 put_pid_ns(parent); 159 parent = ns->parent;
160 if (!kref_put(&ns->kref, free_pid_ns))
161 break;
162 ns = parent;
163 }
147} 164}
148EXPORT_SYMBOL_GPL(free_pid_ns); 165EXPORT_SYMBOL_GPL(put_pid_ns);
149 166
150void zap_pid_ns_processes(struct pid_namespace *pid_ns) 167void zap_pid_ns_processes(struct pid_namespace *pid_ns)
151{ 168{