diff options
author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2015-02-10 14:35:36 -0500 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2015-02-10 14:35:36 -0500 |
commit | 4ba24fef3eb3b142197135223b90ced2f319cd53 (patch) | |
tree | a20c125b27740ec7b4c761b11d801108e1b316b2 /kernel/pid_namespace.c | |
parent | 47c1ffb2b6b630894e9a16442611c056ab21c057 (diff) | |
parent | 98a4a59ee31a12105a2b84f5b8b515ac2cb208ef (diff) |
Merge branch 'next' into for-linus
Prepare first round of input updates for 3.20.
Diffstat (limited to 'kernel/pid_namespace.c')
-rw-r--r-- | kernel/pid_namespace.c | 57 |
1 files changed, 38 insertions, 19 deletions
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c index db95d8eb761b..a65ba137fd15 100644 --- a/kernel/pid_namespace.c +++ b/kernel/pid_namespace.c | |||
@@ -105,9 +105,10 @@ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns | |||
105 | if (ns->pid_cachep == NULL) | 105 | if (ns->pid_cachep == NULL) |
106 | goto out_free_map; | 106 | goto out_free_map; |
107 | 107 | ||
108 | err = proc_alloc_inum(&ns->proc_inum); | 108 | err = ns_alloc_inum(&ns->ns); |
109 | if (err) | 109 | if (err) |
110 | goto out_free_map; | 110 | goto out_free_map; |
111 | ns->ns.ops = &pidns_operations; | ||
111 | 112 | ||
112 | kref_init(&ns->kref); | 113 | kref_init(&ns->kref); |
113 | ns->level = level; | 114 | ns->level = level; |
@@ -142,7 +143,7 @@ static void destroy_pid_namespace(struct pid_namespace *ns) | |||
142 | { | 143 | { |
143 | int i; | 144 | int i; |
144 | 145 | ||
145 | proc_free_inum(ns->proc_inum); | 146 | ns_free_inum(&ns->ns); |
146 | for (i = 0; i < PIDMAP_ENTRIES; i++) | 147 | for (i = 0; i < PIDMAP_ENTRIES; i++) |
147 | kfree(ns->pidmap[i].page); | 148 | kfree(ns->pidmap[i].page); |
148 | put_user_ns(ns->user_ns); | 149 | put_user_ns(ns->user_ns); |
@@ -190,7 +191,11 @@ void zap_pid_ns_processes(struct pid_namespace *pid_ns) | |||
190 | /* Don't allow any more processes into the pid namespace */ | 191 | /* Don't allow any more processes into the pid namespace */ |
191 | disable_pid_allocation(pid_ns); | 192 | disable_pid_allocation(pid_ns); |
192 | 193 | ||
193 | /* Ignore SIGCHLD causing any terminated children to autoreap */ | 194 | /* |
195 | * Ignore SIGCHLD causing any terminated children to autoreap. | ||
196 | * This speeds up the namespace shutdown, plus see the comment | ||
197 | * below. | ||
198 | */ | ||
194 | spin_lock_irq(&me->sighand->siglock); | 199 | spin_lock_irq(&me->sighand->siglock); |
195 | me->sighand->action[SIGCHLD - 1].sa.sa_handler = SIG_IGN; | 200 | me->sighand->action[SIGCHLD - 1].sa.sa_handler = SIG_IGN; |
196 | spin_unlock_irq(&me->sighand->siglock); | 201 | spin_unlock_irq(&me->sighand->siglock); |
@@ -223,15 +228,31 @@ void zap_pid_ns_processes(struct pid_namespace *pid_ns) | |||
223 | } | 228 | } |
224 | read_unlock(&tasklist_lock); | 229 | read_unlock(&tasklist_lock); |
225 | 230 | ||
226 | /* Firstly reap the EXIT_ZOMBIE children we may have. */ | 231 | /* |
232 | * Reap the EXIT_ZOMBIE children we had before we ignored SIGCHLD. | ||
233 | * sys_wait4() will also block until our children traced from the | ||
234 | * parent namespace are detached and become EXIT_DEAD. | ||
235 | */ | ||
227 | do { | 236 | do { |
228 | clear_thread_flag(TIF_SIGPENDING); | 237 | clear_thread_flag(TIF_SIGPENDING); |
229 | rc = sys_wait4(-1, NULL, __WALL, NULL); | 238 | rc = sys_wait4(-1, NULL, __WALL, NULL); |
230 | } while (rc != -ECHILD); | 239 | } while (rc != -ECHILD); |
231 | 240 | ||
232 | /* | 241 | /* |
233 | * sys_wait4() above can't reap the TASK_DEAD children. | 242 | * sys_wait4() above can't reap the EXIT_DEAD children but we do not |
234 | * Make sure they all go away, see free_pid(). | 243 | * really care, we could reparent them to the global init. We could |
244 | * exit and reap ->child_reaper even if it is not the last thread in | ||
245 | * this pid_ns, free_pid(nr_hashed == 0) calls proc_cleanup_work(), | ||
246 | * pid_ns can not go away until proc_kill_sb() drops the reference. | ||
247 | * | ||
248 | * But this ns can also have other tasks injected by setns()+fork(). | ||
249 | * Again, ignoring the user visible semantics we do not really need | ||
250 | * to wait until they are all reaped, but they can be reparented to | ||
251 | * us and thus we need to ensure that pid->child_reaper stays valid | ||
252 | * until they all go away. See free_pid()->wake_up_process(). | ||
253 | * | ||
254 | * We rely on ignored SIGCHLD, an injected zombie must be autoreaped | ||
255 | * if reparented. | ||
235 | */ | 256 | */ |
236 | for (;;) { | 257 | for (;;) { |
237 | set_current_state(TASK_UNINTERRUPTIBLE); | 258 | set_current_state(TASK_UNINTERRUPTIBLE); |
@@ -313,7 +334,12 @@ int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd) | |||
313 | return 0; | 334 | return 0; |
314 | } | 335 | } |
315 | 336 | ||
316 | static void *pidns_get(struct task_struct *task) | 337 | static inline struct pid_namespace *to_pid_ns(struct ns_common *ns) |
338 | { | ||
339 | return container_of(ns, struct pid_namespace, ns); | ||
340 | } | ||
341 | |||
342 | static struct ns_common *pidns_get(struct task_struct *task) | ||
317 | { | 343 | { |
318 | struct pid_namespace *ns; | 344 | struct pid_namespace *ns; |
319 | 345 | ||
@@ -323,18 +349,18 @@ static void *pidns_get(struct task_struct *task) | |||
323 | get_pid_ns(ns); | 349 | get_pid_ns(ns); |
324 | rcu_read_unlock(); | 350 | rcu_read_unlock(); |
325 | 351 | ||
326 | return ns; | 352 | return ns ? &ns->ns : NULL; |
327 | } | 353 | } |
328 | 354 | ||
329 | static void pidns_put(void *ns) | 355 | static void pidns_put(struct ns_common *ns) |
330 | { | 356 | { |
331 | put_pid_ns(ns); | 357 | put_pid_ns(to_pid_ns(ns)); |
332 | } | 358 | } |
333 | 359 | ||
334 | static int pidns_install(struct nsproxy *nsproxy, void *ns) | 360 | static int pidns_install(struct nsproxy *nsproxy, struct ns_common *ns) |
335 | { | 361 | { |
336 | struct pid_namespace *active = task_active_pid_ns(current); | 362 | struct pid_namespace *active = task_active_pid_ns(current); |
337 | struct pid_namespace *ancestor, *new = ns; | 363 | struct pid_namespace *ancestor, *new = to_pid_ns(ns); |
338 | 364 | ||
339 | if (!ns_capable(new->user_ns, CAP_SYS_ADMIN) || | 365 | if (!ns_capable(new->user_ns, CAP_SYS_ADMIN) || |
340 | !ns_capable(current_user_ns(), CAP_SYS_ADMIN)) | 366 | !ns_capable(current_user_ns(), CAP_SYS_ADMIN)) |
@@ -362,19 +388,12 @@ static int pidns_install(struct nsproxy *nsproxy, void *ns) | |||
362 | return 0; | 388 | return 0; |
363 | } | 389 | } |
364 | 390 | ||
365 | static unsigned int pidns_inum(void *ns) | ||
366 | { | ||
367 | struct pid_namespace *pid_ns = ns; | ||
368 | return pid_ns->proc_inum; | ||
369 | } | ||
370 | |||
371 | const struct proc_ns_operations pidns_operations = { | 391 | const struct proc_ns_operations pidns_operations = { |
372 | .name = "pid", | 392 | .name = "pid", |
373 | .type = CLONE_NEWPID, | 393 | .type = CLONE_NEWPID, |
374 | .get = pidns_get, | 394 | .get = pidns_get, |
375 | .put = pidns_put, | 395 | .put = pidns_put, |
376 | .install = pidns_install, | 396 | .install = pidns_install, |
377 | .inum = pidns_inum, | ||
378 | }; | 397 | }; |
379 | 398 | ||
380 | static __init int pid_namespaces_init(void) | 399 | static __init int pid_namespaces_init(void) |