Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1057880ybh; Tue, 10 Mar 2020 13:45:04 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuzJuLHfp+cMlWwetBcqQi+hT7nj76xbz6St4BNtw2agFg58yWSm7QSlH9K+RGELfwgin/g X-Received: by 2002:a9d:66d1:: with SMTP id t17mr17452737otm.235.1583873104778; Tue, 10 Mar 2020 13:45:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583873104; cv=none; d=google.com; s=arc-20160816; b=OamyN2sO+zbgsnOvQjcQP8jq8iDDqg8SUuqdGzzzozPDUNe0Tz2OvfJj8wdny2kFEA xKvvsVmWhfa9cyvl5C+WUMdWT7WKh/s4dKbvME/evFCvmDEfQ9bEUpU6iZ1s4rzNfYSW WaHKilZZBdNVl/OuPiZqmRtbdYh2SZ7LH/rc83FZga/Q50U25xvjvAY5Q8H0h2l0EpxX 79NdB8z93teoAOs+vuIJak9lziyxltyPjk8sqFAk7mHm8/X7ypPhDsyTYrFNJ1Gx1jSp C+MrbcPkhTrTs2MmifOjKCGbf6cOMJFCSIAPkP2vASvwkh5Tjbd14tiuVPl/avL9PxYo 6w8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=099TGIbMGOF3GLWL/lcf16vXSWx45mM4eXf6iexqK48=; b=H0XzTFs2HG57ZSJARV3gI0p50jxecy80cW0liTr3Q6fY4jUAv9KbKkcvsSYIbpp2V2 d0HZwRtJxZ/A0WdXoftIBV1yOSeyrla551+MM75C4jj1gogw2ZUNDzP2UJbRM2om9ojM pXdx4BfYEytf/6vGt0aGfOKyQkfTAcPs0nu4gV4nHm7IUjEywNWA1m0orhpXE5Qd9egr mT/fi7cL4YoKX1m9RdZiYBaNlLYGwjJfi9AxXQ1YAn4KCtTAPy3rWcp2DpSy/licEwcS 9J5ndeUCVz4SJ76gwcUt10bssQmSjPzK6oXlRM2iRg2d3pzB2mNafMFsYWvEp54WO/xH Herg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=eHf9WnjY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l25si6309185oie.234.2020.03.10.13.44.52; Tue, 10 Mar 2020 13:45:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=eHf9WnjY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726729AbgCJUoM (ORCPT + 99 others); Tue, 10 Mar 2020 16:44:12 -0400 Received: from mail-pj1-f67.google.com ([209.85.216.67]:52544 "EHLO mail-pj1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726273AbgCJUoM (ORCPT ); Tue, 10 Mar 2020 16:44:12 -0400 Received: by mail-pj1-f67.google.com with SMTP id f15so922714pjq.2 for ; Tue, 10 Mar 2020 13:44:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=099TGIbMGOF3GLWL/lcf16vXSWx45mM4eXf6iexqK48=; b=eHf9WnjYVqdE3DUP7usldr/Zn8V1+Arq8UsrYtew5+29RS2x609pIGI1hnVIsnD1a7 Xw7DIDoceUaWSr8wHASF9JD5ass2A0tQ6Fz8HXxuf2yNUsJvmiWSpk2Sp3FUBjBm7vzs U0PMba7d6qyGRdRQBOV5q7h2Qx2RgU6AzQn3I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=099TGIbMGOF3GLWL/lcf16vXSWx45mM4eXf6iexqK48=; b=dSzkJt1aIxCA1K5WiDwDee8fyLXH2ib1sffbuEvXwMwKjgo71plxiXBrs+Qyx1bfka iSmdqTN9/pzM9Ycd32D5U6Zaye+bsBDEWW+58rEMSZe/314kUGblKktl3Io09GkJ4wwG 47BZN3jbU2wGnwhNuMo9yo5E+v/s2O7x4QDZMf2P1XDfRp4XQjg0olaEG3OfimhviNRL yYE6DHqdZnVP7mFsnmgYINgE4otY/jfQsO8vSbqYF4K9cOF5BdvFAgQHC1MdtrZ6kmB5 r0Ew430bREpDydbMt0wz6TH+x1IrFEdnMw6U6rCaD9HSiDy3UZoiWyMEd/Yo7EdWVIXg HqNg== X-Gm-Message-State: ANhLgQ0BMkpZtNigkf0j4OlLmESnOE1QH5gAA4xs88sb7NtzAPSgMgXc 2RujER1p/I7izDxzUNzmTMHZgA== X-Received: by 2002:a17:902:ac83:: with SMTP id h3mr22299518plr.86.1583873050871; Tue, 10 Mar 2020 13:44:10 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id w206sm6074394pfc.54.2020.03.10.13.44.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Mar 2020 13:44:10 -0700 (PDT) Date: Tue, 10 Mar 2020 13:44:09 -0700 From: Kees Cook To: "Eric W. Biederman" Cc: Bernd Edlinger , Christian Brauner , Jann Horn , Jonathan Corbet , Alexander Viro , Andrew Morton , Alexey Dobriyan , Thomas Gleixner , Oleg Nesterov , Frederic Weisbecker , Andrei Vagin , Ingo Molnar , "Peter Zijlstra (Intel)" , Yuyang Du , David Hildenbrand , Sebastian Andrzej Siewior , Anshuman Khandual , David Howells , James Morris , Greg Kroah-Hartman , Shakeel Butt , Jason Gunthorpe , Christian Kellner , Andrea Arcangeli , Aleksa Sarai , "Dmitry V. Levin" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" , "stable@vger.kernel.org" , "linux-api@vger.kernel.org" Subject: Re: [PATCH v2 4/5] exec: Move exec_mmap right after de_thread in flush_old_exec Message-ID: <202003101337.AC1A30576@keescook> References: <87v9nlii0b.fsf@x220.int.ebiederm.org> <87a74xi4kz.fsf@x220.int.ebiederm.org> <87r1y8dqqz.fsf@x220.int.ebiederm.org> <87tv32cxmf.fsf_-_@x220.int.ebiederm.org> <87v9ne5y4y.fsf_-_@x220.int.ebiederm.org> <875zfe5xzb.fsf_-_@x220.int.ebiederm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <875zfe5xzb.fsf_-_@x220.int.ebiederm.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Mar 08, 2020 at 04:38:00PM -0500, Eric W. Biederman wrote: > > I have read through the code in exec_mmap and I do not see anything > that depends on sighand or the sighand lock, or on signals in anyway > so this should be safe. > > This rearrangement of code has two siginficant benefits. It makes > the determination of passing the point of no return by testing bprm->mm > accurate. All failures prior to that point in flush_old_exec are > either truly recoverable or they are fatal. Agreed. Though I see a use of "current", which maybe you want to parameterize to a "me" argument in acct_arg_size(). (Though looking at the callers, perhaps there is no benefit?) > > Futher this consolidates all of the possible indefinite waits for > userspace together at the top of flush_old_exec. The possible wait > for a ptracer on PTRACE_EVENT_EXIT, the possible wait for a page fault > to be resolved in clear_child_tid, and the possible wait for a page > fault in exit_robust_list. > > This consolidation allows the creation of a mutex to replace > cred_guard_mutex that is not held of possible indefinite userspace > waits. Which will allow removing deadlock scenarios from the kernel. > > Signed-off-by: "Eric W. Biederman" > --- > fs/exec.c | 24 ++++++++++++------------ > 1 file changed, 12 insertions(+), 12 deletions(-) > > diff --git a/fs/exec.c b/fs/exec.c > index 215d86f77b63..d820a7272a76 100644 > --- a/fs/exec.c > +++ b/fs/exec.c > @@ -1272,18 +1272,6 @@ int flush_old_exec(struct linux_binprm * bprm) > if (retval) > goto out; > > -#ifdef CONFIG_POSIX_TIMERS > - exit_itimers(me->signal); > - flush_itimer_signals(); > -#endif I think this comment: /* * This is called by do_exit or de_thread, only when there are no more * references to the shared signal_struct. */ void exit_itimers(struct signal_struct *sig) Refers to there being other threads, yes? Not that the signal table is private yet? > - > - /* > - * Make the signal table private. > - */ > - retval = unshare_sighand(me); > - if (retval) > - goto out; > - > /* > * Must be called _before_ exec_mmap() as bprm->mm is > * not visibile until then. This also enables the update > @@ -1307,6 +1295,18 @@ int flush_old_exec(struct linux_binprm * bprm) > */ > bprm->mm = NULL; > > +#ifdef CONFIG_POSIX_TIMERS > + exit_itimers(me->signal); > + flush_itimer_signals(); > +#endif I've mostly convinced myself that there are no "side-effects" from having these timers expire as the mm is going away. I think some kind of comment of that intent should be explicitly stated here above the timer work. Beyond that: Reviewed-by: Kees Cook -Kees > + > + /* > + * Make the signal table private. > + */ > + retval = unshare_sighand(me); > + if (retval) > + goto out; > + > set_fs(USER_DS); > me->flags &= ~(PF_RANDOMIZE | PF_FORKNOEXEC | PF_KTHREAD | > PF_NOFREEZE | PF_NO_SETAFFINITY); > -- > 2.25.0 > -- Kees Cook