From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756454AbbJUVun (ORCPT ); Wed, 21 Oct 2015 17:50:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47355 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750910AbbJUVum (ORCPT ); Wed, 21 Oct 2015 17:50:42 -0400 Date: Wed, 21 Oct 2015 23:47:03 +0200 From: Oleg Nesterov To: Denys Vlasenko Cc: Andrew Morton , Dmitry Vyukov , Alexander Potapenko , Eric Dumazet , Jan Kratochvil , Julien Tinnes , Kees Cook , Kostya Serebryany , Linus Torvalds , "Michael Kerrisk (man-pages)" , Pedro Alves , Robert Swiecki , Roland McGrath , syzkaller@googlegroups.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] wait/ptrace: always assume __WALL if the child is traced Message-ID: <20151021214703.GA1810@redhat.com> References: <20151020171740.GA29290@redhat.com> <20151020171754.GA29304@redhat.com> <20151020153155.e03f4219da4014efe6f810b0@linux-foundation.org> <5627EE9E.8040600@redhat.com> <5627F607.4050506@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5627F607.4050506@redhat.com> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/21, Denys Vlasenko wrote: > > On 10/21/2015 09:59 PM, Denys Vlasenko wrote: > > On 10/21/2015 12:31 AM, Andrew Morton wrote: > >> Well, to fix this a distro needs to roll out a new kernel. Or a new > >> init(8). Is there any reason to believe that distributing/deploying a > >> new kernel is significantly easier for everyone? Because fixing init > >> sounds like a much preferable solution to this problem. > > > > People will continue to write new init(8) implementations, > > and they will miss this obscure case. > > > > Before this bug was found, it was considered possible to use > > a shell script as init process. What now, every shell needs to add > > __WALL to its waitpids? Why not? I think it can safely use __WALL too. > > The use of PTRACE_TRACEME in this reproducer is clearly pathological: > > PTRACE_TRACEME was never intended to be used to attach to unsuspecting > > processes. Sure. But people do the things which were never intended to be used all the time. We simply can not know if this "feature" already has a creative user or not. As for the patch, > --- a/kernel/ptrace.c > +++ b/kernel/ptrace.c > @@ -385,6 +385,17 @@ static int ptrace_traceme(void) > write_lock_irq(&tasklist_lock); > /* Are we already being traced? */ > if (!current->ptrace) { > + struct pid_namespace *pid_ns; > + > + pid_ns = task_active_pid_ns(current->parent); > + if (current->parent == pid_ns->child_reaper) { Well, at least this needs same_thread_group(parent, child_reaper). Plus we have PR_SET_CHILD_SUBREAPER so we also need to traverse the ->real_parent list if has_subreaper. Finally it is not clear which ->child_reaper we should use after setns(pidns_fd). This all is fixable (although this again reminds me about a bug with CHILD_SUBREAPER we probably need to fix first). But I didn't even try to consider this option because it can break something. And honestly, personally I don't like it. If we believe that we can do this because "PTRACE_TRACEME was never intended to be used to attach to unsuspecting processes", then we need a more generic change, imo. See http://marc.info/?l=linux-kernel&m=144536282305282 . Just in case, it is not that I think "parent_exec_id != self_exec_id" is all we need. This needs more discussion. Oleg.