Re: [PATCH] pidns: Guarantee that the pidns init will be the lastpidns process reaped. v2

From: Oleg Nesterov
Date: Tue May 22 2012 - 12:55:31 EST


On 05/21, Eric W. Biederman wrote:
>
> Andrew can you replace your earlier version of this patch in your tree
> with this one,

Yes, please, the old one is

pidns-guarantee-that-the-pidns-init-will-be-the-last-pidns-process-reaped.patch

> after Oleg takes a look at it. I think this is about
> as simple and maintainable and obvious as we can make this bug fix.

I believe the patch is fine.

Thanks Eric.

> --- a/kernel/exit.c
> +++ b/kernel/exit.c
> @@ -64,15 +64,26 @@ static void exit_mm(struct task_struct * tsk);
> static void __unhash_process(struct task_struct *p, bool group_dead)
> {
> nr_threads--;
> - detach_pid(p, PIDTYPE_PID);
> if (group_dead) {
> + struct task_struct *parent;
> +
> detach_pid(p, PIDTYPE_PGID);
> detach_pid(p, PIDTYPE_SID);
>
> list_del_rcu(&p->tasks);
> list_del_init(&p->sibling);
> __this_cpu_dec(process_counts);
> +
> + /* If we are the last child process in a pid namespace
> + * to be reaped notify the child_reaper.
> + */
> + parent = p->real_parent;
> + if ((task_active_pid_ns(p)->child_reaper == parent) &&
> + list_empty(&parent->children) &&
> + (parent->flags & PF_EXITING))
> + wake_up_process(parent);
> }
> + detach_pid(p, PIDTYPE_PID);
> list_del_rcu(&p->thread_group);
> }
>
> diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
> index b98b0ed..ba1cbb8 100644
> --- a/kernel/pid_namespace.c
> +++ b/kernel/pid_namespace.c
> @@ -189,6 +189,17 @@ void zap_pid_ns_processes(struct pid_namespace *pid_ns)
> rc = sys_wait4(-1, NULL, __WALL, NULL);
> } while (rc != -ECHILD);
>
> + read_lock(&tasklist_lock);
> + for (;;) {
> + __set_current_state(TASK_UNINTERRUPTIBLE);
> + if (list_empty(&current->children))
> + break;
> + read_unlock(&tasklist_lock);
> + schedule();
> + read_lock(&tasklist_lock);
> + }
> + read_unlock(&tasklist_lock);
> +
> if (pid_ns->reboot)
> current->signal->group_exit_code = pid_ns->reboot;
>
> --
> 1.7.5.4
>

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/