From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A9CBC10F27 for ; Tue, 10 Mar 2020 20:44:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9044822522 for ; Tue, 10 Mar 2020 20:44:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="eHf9WnjY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9044822522 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CE8726B0003; Tue, 10 Mar 2020 16:44:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C991A6B0006; Tue, 10 Mar 2020 16:44:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B86E06B0007; Tue, 10 Mar 2020 16:44:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0007.hostedemail.com [216.40.44.7]) by kanga.kvack.org (Postfix) with ESMTP id 9CFC96B0003 for ; Tue, 10 Mar 2020 16:44:12 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 57351181AEF0B for ; Tue, 10 Mar 2020 20:44:12 +0000 (UTC) X-FDA: 76580629944.15.limit54_7951aa02a23c X-HE-Tag: limit54_7951aa02a23c X-Filterd-Recvd-Size: 7691 Received: from mail-pj1-f67.google.com (mail-pj1-f67.google.com [209.85.216.67]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Mar 2020 20:44:11 +0000 (UTC) Received: by mail-pj1-f67.google.com with SMTP id y7so926233pjn.1 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=PPAF0h1E0Vc6sdrCEhFx4RZ0fV20MCRur+7ox2nvj9/N7QVQx016BTQGqEjV3Qn4gp NIkNS8Z1ob1ioo7JIyJAwRGsulweCiKCrB7RmvX8Cr2m6PvhaqZWFV9qfo6iR2a+kVR9 1dkjW5m5Jrj8cfjReGt/uR7spcwX2vihGsOUF4vWQ1X8zgBsvm+DkDidMqB5rEpAxkno QVm0Azy3amfCIKWlSd0nFNWsLSt5da89ZVvjHuzUl2tFVYY8e/WF8z4tnRF5w+oWWBfW dWaXlkCBN1O6oA2Ap+C7U+Nwd1QljRaIq6F/Bk5gBCGwfQVHFIaxIBIdRwzHO4MIIgsZ Wodw== X-Gm-Message-State: ANhLgQ3BRfPHPdXZ+2YZsoUaZh3nPdb3qh6lclVkLmPLI0x/Vy7NBAdQ Smd+KEm1ARnHeFsgs4+Pkkh8pw== X-Google-Smtp-Source: ADFU+vueXlCI7IpLmS/tzrctbYyGFJWCavdSXGaTgdpbGe7iJ4PA/I36iG3t3Co2w1uOjvrwaTysEw== 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> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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