Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1000929ybk; Wed, 13 May 2020 20:06:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZaR1jwmOI/Z1c8PTeYjUuqwZtegesiZ/zVsUAJhyOAG9Fdm3d1VxYIhQ3Jq877K4Sb647 X-Received: by 2002:a17:906:3607:: with SMTP id q7mr1818339ejb.81.1589425616445; Wed, 13 May 2020 20:06:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589425616; cv=none; d=google.com; s=arc-20160816; b=cnxVXKcXR+b1NSQ/shjD0pnK+APhR98B+KIRAV8fTeR1eZNcEQYi/8d4fuHA3OWYPJ W3335D4OI0400eXSAdgTjiOctmaTFDcIR12CUPNwtbXz8Tae2rYK4hf3kK/ZGshFnTQw bBqzLhafMyrEjELm+3CXiHeWYNuOJ44qxOwJfd8MruiYNTQSibFNTsuakYR3NzzYZKdI CUzZ/8WKqWRHtEBLLaCXsA0/6R76RlsZkXdjp6rnlccMwJnpYMy91XoY1cdy3OE/GO08 S2LBNPY95lnVu8EhGWjgNe6dlBG+jRRvbwm/YMU9Ul+NZ+TLSxqLbJzElM+Gwxe0moCI ZPIg== 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=RI4af4t+Hr3cwRvViCD0C0VTSsdcgl2WIZRjAD5Dbd8=; b=f/sr0ZZfUixO0/+WQx+obuOzdlH3ZnIoTTv9VIv1zX+5aa8Oy+l9nVoWg4yS2moox/ LFS9rCcRqUj0QsG7rmnlj505P4RInMmcGXkzmDrPnCScsYuZF5a2mUs31oU6gvOuM1Zh T29OZsN5jT7W+0T6cGqN8z0aw4kXSrEQ8AEfIr5V/+xYtIA8NfG5jCk6q/h48UXjPPv6 XZWO9914crGKN8rRV2MxyKLwuPSJzyCyErnnUjOg1B2EN8IJP5CXTnrGaC6g2WTbAYGt oH+IMoVNk9UZrJShnV8qCDziVh006EHdnNCAl3mV/e4ca4XlVthe1u0cP4FHrPsjYjYi TqYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ER81wy6N; 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 g17si1011074ejr.529.2020.05.13.20.06.32; Wed, 13 May 2020 20:06:56 -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=ER81wy6N; 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 S1726038AbgENDFO (ORCPT + 99 others); Wed, 13 May 2020 23:05:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725943AbgENDFN (ORCPT ); Wed, 13 May 2020 23:05:13 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05D67C05BD09 for ; Wed, 13 May 2020 20:05:13 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id f6so661963pgm.1 for ; Wed, 13 May 2020 20:05:13 -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=RI4af4t+Hr3cwRvViCD0C0VTSsdcgl2WIZRjAD5Dbd8=; b=ER81wy6Nm4qqHe6/4nA1T72QieIUsDZr9xcEPXqlwCuu1bwbRzbDDp76o/GaGyv6ZN LhIsA3q1GqyyyLFIO5q4UxMKZ/DLFp4DOO12AImeksODZzTLEOUUYcEhUXA8eb5xmUfr WADVBn7cABTbN0GqYscdMzowjTlrjm+0sez/I= 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=RI4af4t+Hr3cwRvViCD0C0VTSsdcgl2WIZRjAD5Dbd8=; b=ny5vBgxaYqmw9rEKmjp4lsJZwbGutlZxN/lyuPpDNdQF3nugTJIyExwO+vOjxJ6dek jai2MxN4kOmRDppOnlS25Pq5thJ5ta6zPHNKNoN5su9pLfEPgPP/gtFXUdte0eBkPubc rD42i8RlGOqLnFL+7zcNulFpF1JCGsd8LYzWb0ChgZ0psk8mHxGsdnxRqBqXnCpq+sZk dUqnmQfSIUbAKsp/QOn4CNBfs+f4oaydLmBKAy9ajo9jHc4VDQyyatDIxF95bsd6knIE M5f3VPhxjk8RGW2eKpLpAgOq6qnZrRzIAkd3C2fRVJyJ+A2n/EbqHvXMS7WFaugghscm j3bg== X-Gm-Message-State: AOAM531FJ1xQgxd27AcR3p59VkOB5/Y2MzYQ80W1fVILMKW+3khZvi1Y R43BXdUEJz3b193GfWhlvedhSg== X-Received: by 2002:aa7:958f:: with SMTP id z15mr2213370pfj.10.1589425512261; Wed, 13 May 2020 20:05:12 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id z7sm818011pff.47.2020.05.13.20.05.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2020 20:05:11 -0700 (PDT) Date: Wed, 13 May 2020 20:05:09 -0700 From: Kees Cook To: Stephen Smalley Cc: =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= , linux-kernel , Aleksa Sarai , Alexei Starovoitov , Al Viro , Andy Lutomirski , Christian Heimes , Daniel Borkmann , Deven Bowers , Eric Chiang , Florian Weimer , James Morris , Jan Kara , Jann Horn , Jonathan Corbet , Lakshmi Ramasubramanian , Matthew Garrett , Matthew Wilcox , Michael Kerrisk , =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= , Mimi Zohar , Philippe =?iso-8859-1?Q?Tr=E9buchet?= , Scott Shell , Sean Christopherson , Shuah Khan , Steve Dower , Steve Grubb , Thibaut Sautereau , Vincent Strubel , kernel-hardening@lists.openwall.com, linux-api@vger.kernel.org, linux-integrity@vger.kernel.org, LSM List , Linux FS Devel Subject: Re: [PATCH v5 3/6] fs: Enable to enforce noexec mounts or file exec through O_MAYEXEC Message-ID: <202005132002.91B8B63@keescook> References: <20200505153156.925111-1-mic@digikod.net> <20200505153156.925111-4-mic@digikod.net> <202005131525.D08BFB3@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202005131525.D08BFB3@keescook> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 13, 2020 at 04:27:39PM -0700, Kees Cook wrote: > Like, couldn't just the entire thing just be: > > diff --git a/fs/namei.c b/fs/namei.c > index a320371899cf..0ab18e19f5da 100644 > --- a/fs/namei.c > +++ b/fs/namei.c > @@ -2849,6 +2849,13 @@ static int may_open(const struct path *path, int acc_mode, int flag) > break; > } > > + if (unlikely(mask & MAY_OPENEXEC)) { > + if (sysctl_omayexec_enforce & OMAYEXEC_ENFORCE_MOUNT && > + path_noexec(path)) > + return -EACCES; > + if (sysctl_omayexec_enforce & OMAYEXEC_ENFORCE_FILE) > + acc_mode |= MAY_EXEC; > + } > error = inode_permission(inode, MAY_OPEN | acc_mode); > if (error) > return error; > FYI, I've confirmed this now. Effectively with patch 2 dropped, patch 3 reduced to this plus the Kconfig and sysctl changes, the self tests pass. I think this makes things much cleaner and correct. -- Kees Cook