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.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=no 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 55D22C433E0 for ; Wed, 15 Jul 2020 06:35:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 33A5A20663 for ; Wed, 15 Jul 2020 06:35:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Hg0tU0+y" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728643AbgGOGfS (ORCPT ); Wed, 15 Jul 2020 02:35:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725823AbgGOGfR (ORCPT ); Wed, 15 Jul 2020 02:35:17 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95CACC061755; Tue, 14 Jul 2020 23:35:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=qSg+PUUB7zK5a9dQGwJP247iiVUMgqkLMGBe7H5+8IA=; b=Hg0tU0+yfdK1zhN7ROWTj8tohj eB/xJBNswDsFwk5dn+wlkCV6rvCNV7E2VsACe+fx8KzGxvXPXZAeHkZ4bilECeZFumrz/zh6xB0jH FzItDU4fuuMkS0+i5VmBkEIGKyd79ePHlbcC5bc56Vn1GVFEy5nD8+LrK6Eif6rXZng9MoLAT+5l+ z4uDj/4SJiQI4i3gH20Xr7TiV61oWc/MsVzWwU3PsVwKjIU5xSKTUJJenuRpscCOcGoQaF9NruPdk UO7Lqz5TR2vmrDxdA6UVTuZjrk4k4kxmmkAILKCZI8QRYfgYnZigkkQrtDRDnyc5eWBY+/kDriIEg mnJUc6Pw==; Received: from hch by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jvb0d-0000sE-OZ; Wed, 15 Jul 2020 06:35:15 +0000 Date: Wed, 15 Jul 2020 07:35:15 +0100 From: Christoph Hellwig To: "Eric W. Biederman" Cc: linux-kernel@vger.kernel.org, Linus Torvalds , Kees Cook , Andy Lutomirski , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Al Viro , Luis Chamberlain , linux-fsdevel@vger.kernel.org, Tetsuo Handa , linux-security-module@vger.kernel.org, "Serge E. Hallyn" , James Morris , Kentaro Takeda , Casey Schaufler , John Johansen , Christoph Hellwig Subject: Re: [PATCH 4/7] exec: Move bprm_mm_init into alloc_bprm Message-ID: <20200715063515.GD32470@infradead.org> References: <871rle8bw2.fsf@x220.int.ebiederm.org> <87eepe6x7p.fsf@x220.int.ebiederm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87eepe6x7p.fsf@x220.int.ebiederm.org> X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 14, 2020 at 08:30:02AM -0500, Eric W. Biederman wrote: > > Currently it is necessary for the usermode helper code and the code that > launches init to use set_fs so that pages coming from the kernel look like > they are coming from userspace. > > To allow that usage of set_fs to be removed cleanly the argument copying > from userspace needs to happen earlier. Move the allocation and > initialization of bprm->mm into alloc_bprm so that the bprm->mm is > available early to store the new user stack into. This is a prerequisite > for copying argv and envp into the new user stack early before ther rest of > exec. > > To keep the things consistent the cleanup of bprm->mm is moved into > free_bprm. So that bprm->mm will be cleaned up whenever bprm->mm is > allocated and free_bprm are called. > > Moving bprm_mm_init earlier is safe as it does not depend on any files, > current->in_execve, current->fs->in_exec, bprm->unsafe, or the if the file > table is shared. (AKA bprm_mm_init does not depend on any of the code that > happens between alloc_bprm and where it was previously called.) > > This moves bprm->mm cleanup after current->fs->in_exec is set to 0. This > is safe because current->fs->in_exec is only used to preventy taking an > additional reference on the fs_struct. > > This moves bprm->mm cleanup after current->in_execve is set to 0. This is > safe because current->in_execve is only used by the lsms (apparmor and > tomoyou) and always for LSM specific functions, never for anything to do > with the mm. > > This adds bprm->mm cleanup into the successful return path. This is safe > because being on the successful return path implies that begin_new_exec > succeeded and set brpm->mm to NULL. As bprm->mm is NULL bprm cleanup I am > moving into free_bprm will do nothing. > > Signed-off-by: "Eric W. Biederman" Looks good, Reviewed-by: Christoph Hellwig