From: akpm@linux-foundation.org Subject: [merged] exit-fix-the-setns-pr_set_child_subreaper-interaction.patch removed from -mm tree Date: Thu, 02 Feb 2017 13:49:28 -0800 Message-ID: <5893a968.tdux5jJcdAPM2nPC%akpm@linux-foundation.org> Reply-To: linux-kernel@vger.kernel.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Return-path: Received: from mail.linuxfoundation.org ([140.211.169.12]:45784 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751377AbdBBVta (ORCPT ); Thu, 2 Feb 2017 16:49:30 -0500 Sender: mm-commits-owner@vger.kernel.org List-Id: mm-commits@vger.kernel.org To: oleg@redhat.com, ebiederm@xmission.com, gorcunov@openvz.org, john.stultz@linaro.org, kay.sievers@vrfy.org, khorenko@virtuozzo.com, lennart@poettering.net, mguzik@redhat.com, mhocko@suse.com, mingo@redhat.com, nicolas.pitre@linaro.org, peterz@infradead.org, ptikhomirov@virtuozzo.com, skinsbursky@virtuozzo.com, tglx@linutronix.de, xemul@virtuozzo.com, mm-commits@vger.kernel.org The patch titled Subject: exit: fix the setns() && PR_SET_CHILD_SUBREAPER interaction has been removed from the -mm tree. Its filename was exit-fix-the-setns-pr_set_child_subreaper-interaction.patch This patch was dropped because it was merged into mainline or a subsystem tree ------------------------------------------------------ From: Oleg Nesterov Subject: exit: fix the setns() && PR_SET_CHILD_SUBREAPER interaction find_new_reaper() checks same_thread_group(reaper, child_reaper) to prevent the cross-namespace reparenting but this is not enough if the exiting parent was injected by setns() + fork(). Suppose we have a process P in the root namespace and some namespace X. P does setns() to enter the X namespace, and forks the child C. C forks a grandchild G and exits. The grandchild G should be re-parented to X->child_reaper, but in this case the ->real_parent chain does not lead to ->child_reaper, so it will be wrongly reparanted to P's sub-reaper or a global init. Link: http://lkml.kernel.org/r/20170130181735.GA11285@redhat.com Signed-off-by: Oleg Nesterov Cc: "Eric W. Biederman" Cc: Pavel Tikhomirov Cc: Lennart Poettering Cc: Kay Sievers Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Cyrill Gorcunov Cc: John Stultz Cc: Thomas Gleixner Cc: Nicolas Pitre Cc: Michal Hocko Cc: Stanislav Kinsburskiy Cc: Mateusz Guzik Cc: Pavel Emelyanov Cc: Konstantin Khorenko Signed-off-by: Andrew Morton --- kernel/exit.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff -puN kernel/exit.c~exit-fix-the-setns-pr_set_child_subreaper-interaction kernel/exit.c --- a/kernel/exit.c~exit-fix-the-setns-pr_set_child_subreaper-interaction +++ a/kernel/exit.c @@ -580,15 +580,18 @@ static struct task_struct *find_new_reap return thread; if (father->signal->has_child_subreaper) { + unsigned int ns_level = task_pid(father)->level; /* * Find the first ->is_child_subreaper ancestor in our pid_ns. - * We start from father to ensure we can not look into another - * namespace, this is safe because all its threads are dead. + * We can't check reaper != child_reaper to ensure we do not + * cross the namespaces, the exiting parent could be injected + * by setns() + fork(). + * We check pid->level, this is slightly more efficient than + * task_active_pid_ns(reaper) != task_active_pid_ns(father). */ - for (reaper = father; - !same_thread_group(reaper, child_reaper); + for (reaper = father->real_parent; + task_pid(reaper)->level == ns_level; reaper = reaper->real_parent) { - /* call_usermodehelper() descendants need this check */ if (reaper == &init_task) break; if (!reaper->signal->is_child_subreaper) _ Patches currently in -mm which might be from oleg@redhat.com are