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=-7.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 91659C433EB for ; Tue, 14 Jul 2020 21:38:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6F7C42064C for ; Tue, 14 Jul 2020 21:38:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="NAZytOoW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728030AbgGNViF (ORCPT ); Tue, 14 Jul 2020 17:38:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727021AbgGNViF (ORCPT ); Tue, 14 Jul 2020 17:38:05 -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 32B3CC061794 for ; Tue, 14 Jul 2020 14:38:05 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id mn17so17772pjb.4 for ; Tue, 14 Jul 2020 14:38:05 -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=7s2UJ6qLwDdlKEbAp3tWyPT6USXGH2ifsrFreEv7ly0=; b=NAZytOoWm9VM1GiubiKSe5di3Ui40jvz1ad82fuA7hPshCWsD0sAPqWNxkIB+tXufO 8PDJesbqttfMwvM2r7RKiFJ9S+8rHPWoa6LAzcb3J++j0xsfn0w9xNRN8vff0eI2UJqT LqupB3U64BjXWhiq32HiGxHkrYkMi3pWzOPqo= 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=7s2UJ6qLwDdlKEbAp3tWyPT6USXGH2ifsrFreEv7ly0=; b=jxmY/mh151z3wJy63sU8knW2aIOYzsOWS5RQ4wYOsmr2gvH1XIWalICnz7Hvqst6MJ EVJrT1XQ9oxZNZgjBJIIfWcuW7VQcSkty6vLgTSNOJ6rB2R9pp9MVCX4fIKM49gs0o+C 0Ncfqy4FRzBf0eQIO569639Xt5zVtztyVZk5j3ocCnivRhK2x6jDFtWEtkeV0nfnPcY1 30mhyoAQToGxwY3DLDCDTxjeZ8F6FWHjMwkBw9kSuvIjmYBC9k9OsH+fCrqe8H9akcKk 5F2RdLr/8B288KbEErr/+FhT3DPTwv6iFQcFJuN7TL60gVx2GPfqpoEEIqPIVSqijtyR zmzg== X-Gm-Message-State: AOAM533hcpMcRU8usn3yvJPVT1Sflumuh803SRJupYUlPI1tzzkciyDq esGgc1WpjdDuQLRuos0GBPKxRQ== X-Google-Smtp-Source: ABdhPJwm5N5VxmpvPXn/mRlZiisE39r8Uxn0Rr9gGkAApwpLxa53XG+7io8auKb4gwouc1z/xyDDeQ== X-Received: by 2002:a17:902:7241:: with SMTP id c1mr5704992pll.79.1594762684784; Tue, 14 Jul 2020 14:38:04 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id h15sm112092pfo.192.2020.07.14.14.38.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2020 14:38:04 -0700 (PDT) Date: Tue, 14 Jul 2020 14:38:03 -0700 From: Kees Cook To: "Eric W. Biederman" Cc: linux-kernel@vger.kernel.org, Linus Torvalds , 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 5/7] exec: Factor bprm_execve out of do_execve_common Message-ID: <202007141438.9E5B93B@keescook> References: <871rle8bw2.fsf@x220.int.ebiederm.org> <878sfm6x6x.fsf@x220.int.ebiederm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <878sfm6x6x.fsf@x220.int.ebiederm.org> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Tue, Jul 14, 2020 at 08:30:30AM -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. Factor bprm_execve > out of do_execve_common to separate out the copying of arguments > to the newe stack, and the rest of exec. > > In separating bprm_execve from do_execve_common the copying > of the arguments onto the new stack happens earlier. > > As the copying of the arguments does not depend any security hooks, > files, the file table, current->in_execve, current->fs->in_exec, > bprm->unsafe, or creds this is safe. > > Likewise the security hook security_creds_for_exec does not depend upon > preventing the argument copying from happening. > > In addition to making it possible to implement kernel_execve that > performs the copying differently, this separation of bprm_execve from > do_execve_common makes for a nice separation of responsibilities making > the exec code easier to navigate. > > Signed-off-by: "Eric W. Biederman" Reviewed-by: Kees Cook -- Kees Cook