Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3466868pxb; Mon, 4 Apr 2022 17:54:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1j+tI3Z2FTZ8Tk231ZEyHPL8gjmHy2wLCedzSv+RUlH9k+q+ByvDH9+YbqQU5yF1L70JU X-Received: by 2002:a05:6a00:98e:b0:4fb:1162:b2a5 with SMTP id u14-20020a056a00098e00b004fb1162b2a5mr819952pfg.12.1649120055095; Mon, 04 Apr 2022 17:54:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649120055; cv=none; d=google.com; s=arc-20160816; b=RYwCeVMNUoz8s9s4r/JJMPKol4WOQb9uFfoUHX5y5cVjiaguB2NkEPPQMVbE9Ivct9 jK64q2oqYXTk/nb2d02P1YURpmOpjA6CEF+yl50U0mHpdtuptx0EUicA6uURJIM5TL/m Orm3hVd6Ttw6G2zxIWQNO0oMlbOjDHPDNBoZ6VkJ75ik2IQ6MEC/73VqcXbPcxT4Cg2v KaGP0TXn84cPVc+L9g82VgkHBHpQGqFE6CFsYhSJcfp2HUBXPeEn/v1FiD7qX02Fhk1D 7OMiBx3Vwf4wILKfAVLeu/NM3kCVnejYbti6q+uj3z6AI8v6Tr3cnaYksojUykuPjHtK f1Rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=gk7YExpjD17yvmNb1YnkwGsNAfvivwtdanWcpr+eU8Y=; b=z+H2yALb4U+OsxKJMyafJMs/cUAZKEej3ocbCoPjuQ9G3j396KNbApo2BOENlTKRa1 5u97cGyFM+in5bkFB5Y/Xm/84XWyVR/VPcJxyPS7pKy0iSht3QVhIt0WYKLu8WCUJSEY RX+7SBjUeUcNsR4lbRJBU5k6YGroI9K51ZNARri7+XMZ22AP1r7v8lNHEvxFsHqXo0Qg bep+CEgeZIuZykQvp4U4a1rF0qaDCWg1FQwHGcOfVRvod0efTVyQurLgbqd86w4bStay 8br8KWCzNEXO7hEDee/JQOyK+L+vGlMJAilnnVmi9yAyNpEBwfXDm3zmdgmVGVckXiWW bi+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=b4kGzhYd; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id p9-20020a17090a428900b001c5c6abfe10si534152pjg.12.2022.04.04.17.54.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 17:54:15 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=b4kGzhYd; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5B4AC11BCF9; Mon, 4 Apr 2022 17:02:20 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235219AbiDDXEh (ORCPT + 99 others); Mon, 4 Apr 2022 19:04:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234810AbiDDXEQ (ORCPT ); Mon, 4 Apr 2022 19:04:16 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D1B231370 for ; Mon, 4 Apr 2022 15:25:22 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id w7so10282641pfu.11 for ; Mon, 04 Apr 2022 15:25:22 -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:content-transfer-encoding:in-reply-to; bh=gk7YExpjD17yvmNb1YnkwGsNAfvivwtdanWcpr+eU8Y=; b=b4kGzhYdOOBuJA+ydGgqp1rlD/EHbApMFe6NjPa2BcD1b0AjYblro2TW6cHiJwXv1j cIHnWLN+29p+1lVvytOTxUDuVRYGoz8mHzrqWSCMqfa4dNIB3FqIE70xRvHTuuJ9+Prg IMeR3KfPWdMGhvmBnaqnoUY8yhUtgAAzPiOJQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=gk7YExpjD17yvmNb1YnkwGsNAfvivwtdanWcpr+eU8Y=; b=JBKwUMvVbCG5OJjtFbI4i7Cz4otaDGxptYc/Qx7SFg5Hu+0W1tAJC+ORWeBhWWDIDY K+2AqnneqgKn0lN9z82AvkORG6BBWT3aXA22AZp4nVLM5tYAK2Lu428/lRymHYhzcJcs XY9/Xeedqziql3uGRQEklTI542LwFCYtKVEbD1E44oYg4a2WeYjncKDUR0qgdnbSXGWI OGoSOIN7Zj+Fo+iLFmTc5njPCKA45nQb//OZ6phV/ewpF3ea9izMYNvIFLXOBkJ8gmb/ AUPC3NTHd7KHAnOkZONFrX3dPU2Q6uCvObm9MVQNHiTpIxLb/B1RA50Kq3QNRfEQ9xcs 9TaQ== X-Gm-Message-State: AOAM532c3xSzzPFy9pv2i5Cni1Bqd+Dof9TX43hDnA/dcn8M7eir/xm7 0rIOz5ufscrp0X4ca8wveBr1hw== X-Received: by 2002:a62:7b43:0:b0:4fa:6936:6986 with SMTP id w64-20020a627b43000000b004fa69366986mr318150pfc.13.1649111121830; Mon, 04 Apr 2022 15:25:21 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id q9-20020a056a0002a900b004fde4893cf8sm8710271pfs.200.2022.04.04.15.25.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 15:25:21 -0700 (PDT) Date: Mon, 4 Apr 2022 15:25:19 -0700 From: Kees Cook To: Linus Torvalds Cc: =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= , Al Viro , Andrew Morton , Christian Heimes , Geert Uytterhoeven , James Morris , Luis Chamberlain , Mimi Zohar , Muhammad Usama Anjum , Paul Moore , Philippe =?iso-8859-1?Q?Tr=E9buchet?= , Shuah Khan , Steve Dower , Thibaut Sautereau , Vincent Strubel , linux-fsdevel , linux-integrity , Linux Kernel Mailing List , LSM List , Christian Brauner Subject: Re: [GIT PULL] Add trusted_for(2) (was O_MAYEXEC) Message-ID: <202204041451.CC4F6BF@keescook> References: <20220321161557.495388-1-mic@digikod.net> <202204041130.F649632@keescook> <816667d8-2a6c-6334-94a4-6127699d4144@digikod.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 04, 2022 at 02:28:19PM -0700, Linus Torvalds wrote: > Now, what I *think* you mean is > > (1) user-space executable loaders want to be able to test the *same* > policy as the kernel does for execve() Right. The script interpreter wants to ask "if this file were actually an ELF going through execve(), would the kernel allow it?" > (2) access(path, EXECVE_OK) will do the same permission checks as > "execve()" would do for that path Maybe. I defer to Micka?l here, but my instinct is to avoid creating an API that can be accidentally misused. I'd like this to be fd-only based, since that removes path name races. (e.g. trusted_for() required an fd.) > (3) if you already have the fd open, use "faccess(fd, NULL, > F_OK_TO_EXECUTE, AT_EMPTY_PATH)" Yes, specifically faccessat2(). (And continuing the race thought above, yes, there could still be races if the content of the file could be changed, but that case is less problematic under real-world conditions.) > (4) maybe we want to add a flag for the "euid vs real uid", and that > would be in the "flags" field, since that changes the actual *lookup* > semantics > > Note that that (4) is something that some normal user space has wanted > in the past too (GNU libcs has a "eaccess()" thing for "effective uid > access"). I think this already exists as AT_EACCESS? It was added with faccessat2() itself, if I'm reading the history correctly. And I just need to say that the thought of setuid script interpreters still makes me sad. :) > - I really want the exact semantics very clearly defined. I think > it's ok to say "exact same security check as for 'execve()'", but even > then we need to have that discussion about > > (a) "what about suid bits that user space cannot react to" What do you mean here? Do you mean setid bits on the file itself? > (b) that whole "effective vs real" discussion I think this is handled with AT_EACCESS? -- Kees Cook