Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1981156ybj; Wed, 6 May 2020 08:35:12 -0700 (PDT) X-Google-Smtp-Source: APiQypIraQHr5dvxQlT8jWFqg8wAhBb3WWLAFlgkg7aBB9Nwg5DaBmExYC6bxAVku+OMiM2T7vmH X-Received: by 2002:a17:906:3198:: with SMTP id 24mr7351648ejy.39.1588779312570; Wed, 06 May 2020 08:35:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588779312; cv=none; d=google.com; s=arc-20160816; b=M5/EmazOxTYa6ELc4PZ/emJB4UsMV01kAoUoXeddnx9wk03IF/o296r89Ou+Khjcas 8ArsE+kFgHyi3Seat07b2Kp+OBrd6/dLYiAvnH2K6p1OpxSgK3MsjmVr/ZOvkdZsq6LI SAOHDyU3No2ZkFuuqrcfV96iceI4dBCFoGO/1mVpiApuNQuBog/sy8yPzPu78xjfniAx 3o96PXApldm8Uur7bJHTqh6eMmNyRU3qTnoWIp3Nt7RAyCjuZGxoR2G457KY8hl6m7H4 pV8YIXsWInaqhBgh/z2sSyLR8rClFJ0nxsgaoYuIeIIkav9XbmJ5ksjcMcrhfUMf4jmy NIMw== 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=QdMtxniSWK3PkWXNKwBL1UPHuRFtnVNhLkmVLBdfg9k=; b=o9iMfZuFPcFuDtQHy7OCdPTU47yiTHF5eJKRbBE38p1h3zsZU+omFgi1cEXE3j1yQe vmumbCkLBokmrFzGBt75CvfwTPbfXhfoH4DNDWfqtjFwI/YHe+sPf/wTYkRGSda/+6ZQ H9aGyxOogEoZG+N+OtZCiU14k+WRbOVXOInRlb3f3Op6NUYAIy4TaWhfPxWcSDMyHKdb XCMPrioLz0fwtik8n2/XKfb6vfT2vO5vbc4por48uh3JgrmKVkRfsRC2NPll5Rm8fjQs T0/YcvAOjtfOpX/BLF2F/sjTeS1jvEWMvl16xPTKrIeFBQKh0ZJ6VGtkm7mxlMsatMpP xGPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="Q/9X3Hqp"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id j21si1162311edt.523.2020.05.06.08.34.48; Wed, 06 May 2020 08:35:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="Q/9X3Hqp"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1730054AbgEFPai (ORCPT + 99 others); Wed, 6 May 2020 11:30:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729931AbgEFPag (ORCPT ); Wed, 6 May 2020 11:30:36 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B22DC061A0F for ; Wed, 6 May 2020 08:30:36 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id q24so1045499pjd.1 for ; Wed, 06 May 2020 08:30:36 -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=QdMtxniSWK3PkWXNKwBL1UPHuRFtnVNhLkmVLBdfg9k=; b=Q/9X3HqpDpP1bpMyEce6+77MmK6MN+XVjRdiAxqecgTGYNf3lBxevqb2kiejal14bb WjYaodQ0NtKSLfkI4ehZZNQCWbD4wu0b8/wpICLtZi+IHB10p/r0x/OfvVfBgznsLkHH mBJthd/pdvQ9+cBWw2Oz5oYEAiMhlyPElCbek= 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=QdMtxniSWK3PkWXNKwBL1UPHuRFtnVNhLkmVLBdfg9k=; b=O5R+YuaAOTNTFQFpo7FdHVmGwM0Gtgfv4Mgqchci6y8HV4ebNB/f+3d6+J6BMJZO4d 17n54GWr4Fm2KO6KnSltnEVXiD129mIEH4RDNyJ+BmEOAm4qtoi7fpvoBctc3ZeqjKlM SDutyj50QlhCU4MUUMjSnYV02UdCx+sRYQMedAS5R/7a39n1RE4gBwwuzhe53k2BnUG3 ILz+QsoQu7v4GXpmLwOIdl3MnjDFqXmmNIrEO8f1I44MnqKQEC8ykhnVWXuvN1BZ/K0U SeuqN4klg3QV9daImGj/f2NNgrHHjIUmfF9ZkgUjgAQDx/Vxe1IotAL5Jc6/scwmG25I D+Tg== X-Gm-Message-State: AGi0Puash/pJbOrpTFMUf9BEiWMJbzSK5s5AsPTtbIh2vv9IpscbYJhl 1Pe6CrrRf6wn1sMrEna0iVDb/g== X-Received: by 2002:a17:90a:21ce:: with SMTP id q72mr9815638pjc.0.1588779036158; Wed, 06 May 2020 08:30:36 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 82sm2099813pfv.214.2020.05.06.08.30.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 May 2020 08:30:34 -0700 (PDT) Date: Wed, 6 May 2020 08:30:33 -0700 From: Kees Cook To: "Eric W. Biederman" Cc: linux-kernel@vger.kernel.org, Linus Torvalds , Oleg Nesterov , Jann Horn , Greg Ungerer , Rob Landley , Bernd Edlinger , linux-fsdevel@vger.kernel.org, Al Viro , Alexey Dobriyan , Andrew Morton Subject: Re: [PATCH 6/7] exec: Move most of setup_new_exec into flush_old_exec Message-ID: <202005060829.A09C366D0@keescook> References: <87h7wujhmz.fsf@x220.int.ebiederm.org> <87ftcei2si.fsf@x220.int.ebiederm.org> <202005051354.C7E2278688@keescook> <87368ddsc9.fsf@x220.int.ebiederm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87368ddsc9.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 Wed, May 06, 2020 at 09:57:10AM -0500, Eric W. Biederman wrote: > Kees Cook writes: > > > On Tue, May 05, 2020 at 02:45:33PM -0500, Eric W. Biederman wrote: > >> > >> The current idiom for the callers is: > >> > >> flush_old_exec(bprm); > >> set_personality(...); > >> setup_new_exec(bprm); > >> > >> In 2010 Linus split flush_old_exec into flush_old_exec and > >> setup_new_exec. With the intention that setup_new_exec be what is > >> called after the processes new personality is set. > >> > >> Move the code that doesn't depend upon the personality from > >> setup_new_exec into flush_old_exec. This is to facilitate future > >> changes by having as much code together in one function as possible. > > > > Er, I *think* this is okay, but I have some questions below which > > maybe you already investigated (and should perhaps get called out in > > the changelog). > > I will see if I can expand more on the review that I have done. > > I saw this as moving thre lines and the personality setting later in the > code, rather than moving a bunch of lines up > > AKA these lines: > >> + arch_pick_mmap_layout(me->mm, &bprm->rlim_stack); > >> + > >> + arch_setup_new_exec(); > >> + > >> + /* Set the new mm task size. We have to do that late because it may > >> + * depend on TIF_32BIT which is only updated in flush_thread() on > >> + * some architectures like powerpc > >> + */ > >> + me->mm->task_size = TASK_SIZE; > > > I verified carefully that only those three lines can depend upon the > personality changes. > > Your concern if anything depends on those moved lines I haven't looked > at so closely so I will go back through and do that. I don't actually > expect anything depends upon those three lines because they should only > be changing architecture specific state. But that is general handwaving > not actually careful review which tends to turn up suprises in exec. Right -- I looked through all of it (see my last email) and I think it's all okay, but I was curious if you'd looked too. :) > Speaking of while I was looking through the lsm hooks again I just > realized that 613cc2b6f272 ("fs: exec: apply CLOEXEC before changing > dumpable task flags") only fixed half the problem. So I am going to > take a quick detour fix that then come back to this. As that directly > affects this code motion. Oh yay. :) Thanks for catching it! -- Kees Cook