Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp605798ybk; Fri, 15 May 2020 08:54:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgyrQ/IZV2GOkqU0oyQuEweV6z4b7ddbVHu3I3KE8/cgmzOgMKTkFjp6QHkLi/l64wM8Tj X-Received: by 2002:a17:906:951:: with SMTP id j17mr3463532ejd.352.1589558059739; Fri, 15 May 2020 08:54:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589558059; cv=none; d=google.com; s=arc-20160816; b=s7w3LzYDXfGQcdFfloKgkSOks5clmFSd/6RF3J30UQtcXJDYw/vEGMilldjoobOpkn teNurGxqjo98RjAGiTKZixSdabvyDf2JKtXPMmShSX9+Fqum8/kuSvfomQyRFWfIuMu+ 6/msbLJsVbYZq/N2QlC0UelRBc2P+aNjoY+6ni0I2g5n2yzfIE+JTwL++BNsSDKula36 g2qwixah185O6wAuu6HXLJJ8h9pYMERHNRxa5piyz7sAv6oFV7a8jNtVysAsVXT39jT6 s5+x4U9ejZ8mSZy8gtQ1waQUGkdb+nUJZuZ9r7/tPqI8PqsMZrS5JzKph4rAenKXz7s5 /wAw== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=maNQlt0vCXUutQdGjL8vBhpeTRE+KVofJhs1eAnXh6g=; b=zw6LHji+Z6l9/gUvi7/v7bmYrdZGFVhI2Eimj+G1F8OhTtrbpM4JLxGqP5Aa9+xFh3 +yIq4745NsfM6WlTeEMpTKZgvv62f5DphF4JvwznhhfMR4c3DDh13MRhijh5t99R9NxK t3DuHJUJ077oKhSquX6aU/Zc7kJ9KVJr9Gh4MZeWIuyFxL+z0EIZTF9hi3fNb/IQEyjD SXwLg0nSzAk626UhrexukDaBfzZph+FqNiR1AAK/HngvxVKPT7bV5pwUxnVao2lnW12Z P25nsUVQApc71SVAHSyBPtonVcxgWyLk+Xd3h/AiaHX7BX7Fvtm9YKSMR+KiQvwjyZhH cU/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=XbNk7MuQ; 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 i12si1547915edn.103.2020.05.15.08.53.54; Fri, 15 May 2020 08:54:19 -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=XbNk7MuQ; 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 S1726584AbgEOPuW (ORCPT + 99 others); Fri, 15 May 2020 11:50:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726227AbgEOPuT (ORCPT ); Fri, 15 May 2020 11:50:19 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A55CDC061A0C for ; Fri, 15 May 2020 08:50:18 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id k19so1020411pll.9 for ; Fri, 15 May 2020 08:50:18 -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=maNQlt0vCXUutQdGjL8vBhpeTRE+KVofJhs1eAnXh6g=; b=XbNk7MuQ57Rts4Z0qNTKjgNqv1OpA6t+Nc11jH0CcE5DjXS7oVuq2I56+d2MDC75jJ nDjDvlSzADQw/PQCIl8/DxXmgfrveGmE6Hw9eY461U1BxfLAfoewmC1zHAQ7NjHaBVwq 48yzco9HijnVPOEH6uI2cCSke9LuzsUIGaAQQ= 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:content-transfer-encoding :in-reply-to; bh=maNQlt0vCXUutQdGjL8vBhpeTRE+KVofJhs1eAnXh6g=; b=JRvWjrWTUZFTusIuZ3+8q6XjBJq0aQV7CUVFTfYidsGa+tYLAhFYdyCO7nqFojDoZk mvYhlpJSqVRmKadAfgd8WPHzB6fayA+jsRvEjtrHYOgbf+xMyvt++7QsPZi5LyLDS3Mu 09kqqeJRhgMBc2n5tHK7mWMJ6EllFcWC3RYEPl2JAdf1O+vjKA535nuhkUvUIqlu/jxJ IFYjhpiA35omMrqRhUeRLM6EEoFv+fSnyXg5rKmS/sIHhX9sDbT0XoKAWh/Rq24TAEfh YWdgehLabic84naeu+djUCAw6u7O1lZ31Vfzzx+pUBB8X/7kzuNm0JzgGWRb0Fs88Tgc uUAw== X-Gm-Message-State: AOAM531EgJNVag5ZkAHrNAjdPC3qR0X1cEWoGH/jr56Gl8JRyV3+1bKP Mkk3pSqzmcOAISt42oxLGUqDTg== X-Received: by 2002:a17:90a:5584:: with SMTP id c4mr459126pji.51.1589557818127; Fri, 15 May 2020 08:50:18 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id b24sm2247218pfi.4.2020.05.15.08.50.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2020 08:50:17 -0700 (PDT) Date: Fri, 15 May 2020 08:50:16 -0700 From: Kees Cook To: Florian Weimer Cc: =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= , Al Viro , Aleksa Sarai , Andy Lutomirski , Mimi Zohar , Stephen Smalley , Christian Heimes , Deven Bowers , Tetsuo Handa , John Johansen , Kentaro Takeda , "Lev R. Oshvang ." , Alexei Starovoitov , Daniel Borkmann , Eric Chiang , James Morris , Jan Kara , Jann Horn , Jonathan Corbet , Lakshmi Ramasubramanian , Matthew Garrett , Matthew Wilcox , Michael Kerrisk , =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= , Philippe =?iso-8859-1?Q?Tr=E9buchet?= , Scott Shell , Sean Christopherson , Shuah Khan , Steve Dower , Steve Grubb , Thibaut Sautereau , Vincent Strubel , linux-kernel , kernel-hardening@lists.openwall.com, linux-api@vger.kernel.org, linux-integrity@vger.kernel.org, LSM List , Linux FS Devel Subject: Re: How about just O_EXEC? (was Re: [PATCH v5 3/6] fs: Enable to enforce noexec mounts or file exec through O_MAYEXEC) Message-ID: <202005150847.2B1ED8F81@keescook> References: <202005131525.D08BFB3@keescook> <202005132002.91B8B63@keescook> <202005140830.2475344F86@keescook> <202005142343.D580850@keescook> <87a729wpu1.fsf@oldenburg2.str.redhat.com> <202005150732.17C5EE0@keescook> <87r1vluuli.fsf@oldenburg2.str.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <87r1vluuli.fsf@oldenburg2.str.redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 15, 2020 at 04:43:37PM +0200, Florian Weimer wrote: > * Kees Cook: > > > On Fri, May 15, 2020 at 10:43:34AM +0200, Florian Weimer wrote: > >> * Kees Cook: > >> > >> > Maybe I've missed some earlier discussion that ruled this out, but I > >> > couldn't find it: let's just add O_EXEC and be done with it. It actually > >> > makes the execve() path more like openat2() and is much cleaner after > >> > a little refactoring. Here are the results, though I haven't emailed it > >> > yet since I still want to do some more testing: > >> > https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/log/?h=kspp/o_exec/v1 > >> > >> I think POSIX specifies O_EXEC in such a way that it does not confer > >> read permissions. This seems incompatible with what we are trying to > >> achieve here. > > > > I was trying to retain this behavior, since we already make this > > distinction between execve() and uselib() with the MAY_* flags: > > > > execve(): > > struct open_flags open_exec_flags = { > > .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC, > > .acc_mode = MAY_EXEC, > > > > uselib(): > > static const struct open_flags uselib_flags = { > > .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC, > > .acc_mode = MAY_READ | MAY_EXEC, > > > > I tried to retain this in my proposal, in the O_EXEC does not imply > > MAY_READ: > > That doesn't quite parse for me, sorry. > > The point is that the script interpreter actually needs to *read* those > files in order to execute them. I think I misunderstood what you meant (Micka?l got me sorted out now). If O_EXEC is already meant to be "EXEC and _not_ READ nor WRITE", then yes, this new flag can't be O_EXEC. I was reading the glibc documentation (which treats it as a permission bit flag, not POSIX, which treats it as a complete mode description). -- Kees Cook