Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp3728420ybk; Tue, 19 May 2020 11:31:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUfdKIRea4RGyaYpQDvhmYcM0qZSZgkb6Db1zzEwg5vKv7RJ5gBcJTnP7EH62fEuCgsYU4 X-Received: by 2002:a17:906:9383:: with SMTP id l3mr523957ejx.520.1589913082369; Tue, 19 May 2020 11:31:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589913082; cv=none; d=google.com; s=arc-20160816; b=bwr5ozUmY2Mc1cIVKYzi7hkmCx81Dffrug7udFpAq2tx4GJ/slaLZsYEiyj9h3JRuv Fc2pG22QPvdiRKFcD5f+YI/tlVWiDiHMzw5nMVq3U9LQIf5nTg5nWSORr59Bjedxrw2H apAJE07hi8S2Bwd5yslvUbMEjP4coeicbBI0U02Y8wbIJtFTfx7iT+n5ZUmHcs/2t3c8 zf4VsR1Dc7h5b59xB8cjsxXqWuuHdc1u6pQLvJFTDWyDGpND0VtxeaQttN+DsrUN5/k0 1iWK834YjDfGQ6pE8Tgjx+3lyTgFAZgBppvTRI5rhkdrPqJM0V1qrYO27LSkuVVIXdWQ tpNw== 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=X+EjBfM39k69WBHN4/ekIWimO/d9vuhDt/Vo5vtGtAE=; b=OLITQrmcjMTCELbXS2sI2O/I6j6jZNZQSNovUVQEqN8V42NDFFoAer+KU1KwuTaAsD XhSpQ1zaa44kI47iXxVlWXB+f+51FtFdbcUinT3NjhwbdTL3stDFQV0YIidE4n9s1Do5 pkzynU2CA4pEDoTYnWruCPQ20eV7OPZVXLFkwEUFQhQFrHON/6dQRXfPQUT3dKBuPqSS xFgjSx1SQUCw6mfKqvAtIdkDQEQaH4KiSdSCdZCdigSwbqHxomx7IgVfRagHBFBpSKlf j6UVXxsUJMWszAPQDYFpNhkdfl/vymeI/Vvh3txlO9qmoy866fC2q7R0SxtHkdAkdSdJ KfNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=k5wm3j0Z; 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 hb7si355284ejb.533.2020.05.19.11.30.58; Tue, 19 May 2020 11:31:22 -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=k5wm3j0Z; 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 S1729403AbgESS12 (ORCPT + 99 others); Tue, 19 May 2020 14:27:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727066AbgESS12 (ORCPT ); Tue, 19 May 2020 14:27:28 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4467C08C5C2 for ; Tue, 19 May 2020 11:27:27 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id n15so309335pfd.0 for ; Tue, 19 May 2020 11:27:27 -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=X+EjBfM39k69WBHN4/ekIWimO/d9vuhDt/Vo5vtGtAE=; b=k5wm3j0ZFUD/z29kzyzWM3Ts6RzjmHfYKcvUqUD9IACZssyAf8JKWmEbFUkn1OrPKf pmVYFVlyr+dS+hfCae3pARec9ZCRZUODOa9jm2cfESVBmVjP7xV6lP6DmtlCnPUWY0PB JgYQESHA/aXh2EEkWDGlvcKEmdovXGAJygOBA= 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=X+EjBfM39k69WBHN4/ekIWimO/d9vuhDt/Vo5vtGtAE=; b=GAamdKrnK1b/pmApLaWo7myi2wwjAjuzK1iSzTCCI9cYNOQViON6gTcPBkSYW5fv0M tihBzKrd8AWERtpAO3BK0GmHkNgyeAP56RR5QhtM5/MHyFgOhIGDGMTp6Qn+jY4ZEEj+ R13mg5BAaSqXmlgbRXXvvMa/KK1LG5sR2IKzenahvzVJMjj7XaHKeWqmKeaCac2zGQFF tUbmYQ0a0dv/Co4clVFLlnXfaO8eDhEFShQyKYj7r2H5ew1BoWRQhxxcpMs07aXXKLq+ MSGRBCS2TLu2CB1HRy5mHYUXjDjG4Qd0HNTgLDf82rrxgVE3HD8Wfmw/6JTv31iTk8e5 Slvg== X-Gm-Message-State: AOAM532cYmSjDkFyziRmAAqnXXvH59KhIZFAZkjGDx74hqQjCPiOSGGZ hZEJWjJWn68S1JEvEk5QpXfqWw== X-Received: by 2002:a62:76cc:: with SMTP id r195mr401180pfc.116.1589912847368; Tue, 19 May 2020 11:27:27 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id l3sm217492pju.38.2020.05.19.11.27.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 11:27:26 -0700 (PDT) Date: Tue, 19 May 2020 11:27:25 -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 , Casey Schaufler , linux-security-module@vger.kernel.org, James Morris , "Serge E. Hallyn" , Andy Lutomirski Subject: Re: [PATCH v2 4/8] exec: Allow load_misc_binary to call prepare_binfmt unconditionally Message-ID: <202005191122.0A1FD07@keescook> References: <87h7wujhmz.fsf@x220.int.ebiederm.org> <87sgga6ze4.fsf@x220.int.ebiederm.org> <87v9l4zyla.fsf_-_@x220.int.ebiederm.org> <877dx822er.fsf_-_@x220.int.ebiederm.org> <87imgszrwo.fsf_-_@x220.int.ebiederm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87imgszrwo.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 Mon, May 18, 2020 at 07:31:51PM -0500, Eric W. Biederman wrote: > > Add a flag preserve_creds that binfmt_misc can set to prevent > credentials from being updated. This allows binfmt_misc to always > call prepare_binfmt. Allowing the credential computation logic to be typo: prepare_binprm() > consolidated. > > Not replacing the credentials with the interpreters credentials is > safe because because an open file descriptor to the executable is > passed to the interpreter. As the interpreter does not need to > reopen the executable it is guaranteed to see the same file that > exec sees. Yup, looks good. Note below on comment. Reviewed-by: Kees Cook > [...] > diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h > index 8605ab4a0f89..dbb5614d62a2 100644 > --- a/include/linux/binfmts.h > +++ b/include/linux/binfmts.h > @@ -26,6 +26,8 @@ struct linux_binprm { > unsigned long p; /* current top of mem */ > unsigned long argmin; /* rlimit marker for copy_strings() */ > unsigned int > + /* It is safe to use the creds of a script (see binfmt_misc) */ > + preserve_creds:1, How about: /* * A binfmt handler will set this to True before calling * prepare_binprm() if it is safe to reuse the previous * credentials, based on bprm->file (see binfmt_misc). */ -- Kees Cook