Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp22767ybk; Tue, 12 May 2020 14:11:40 -0700 (PDT) X-Google-Smtp-Source: APiQypLz646HJlxX7sqU3MO4fevNJu7Qa0wgzTiY0KJIORyWCzMPKwRHTBOqOSYopzByIlLkWbFm X-Received: by 2002:a17:906:7a4f:: with SMTP id i15mr11045700ejo.71.1589317900725; Tue, 12 May 2020 14:11:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589317900; cv=none; d=google.com; s=arc-20160816; b=XdNOGg8YIYlC2TpWQSIYAOvW1AeJ+mxs5XW3AvY7TiKPoU8eQkqYEzWZAArO4FZrLC n73VetXLLLGm10SHOHuG980EriWE7Vdo5+Am9/pzweHEAqME6MSuoapsb9az9c2873Vz /y3mL3d5oy2HOGECrEBxd9uwgmBSP8l8RfDRkZhrIQAUhxUL8cW+p5/BtexIpE93RuKR FZK2yTteyJCzAHxUkEvolkhDG6isQcpSc0TpcZa5tBzv6hLuQBJXJNV7dWSq6cE++h/7 VztrO+qCnD9gXIemXukxmsVd0rsfMJu8Xjl//mbmy03wYBTQJvjZPgCZjbK6C5ycNOW/ HEvQ== 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=4SiIjIE0HqgktULUkxH4huGvPI4IR97vaLn7SaMgRvw=; b=CiV7MOHksfB/SgBgwwQOfxUZZabnW/kTYLBngtbWsAkh4skRkGy/1miK4svPtZ2eQf 4zT4IK4kXYwttKrYjTfm5+yL+hxf2nRaWUPqCbsrQPEpaiKkiDGInxDxjfMqA+U/TYG9 /bBg9lGB4idMruiRsJZVjfw2ohg8Gvq2bhEnHR3aURW5Fty3VoDb+xPYu1jl6aFQEBfU PycvWhDCXNoMSHQKI0ZuW9NMcG1UJYRtqGRc2dqdCc7scIUglOLSgXedUVBbR4uu5qSb t8qJh5cGY4E8QxhHb9k/IrBg1DwtItNldeDzIW2z1cz/3rQ/Uh6xOvttoNtd6ig8HNug wqxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kvOR1LBv; 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 x20si1941899edi.323.2020.05.12.14.11.17; Tue, 12 May 2020 14:11:40 -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=kvOR1LBv; 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 S1731156AbgELVJo (ORCPT + 99 others); Tue, 12 May 2020 17:09:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726324AbgELVJn (ORCPT ); Tue, 12 May 2020 17:09:43 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C113BC061A0F for ; Tue, 12 May 2020 14:09:43 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id j21so6748599pgb.7 for ; Tue, 12 May 2020 14:09:43 -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=4SiIjIE0HqgktULUkxH4huGvPI4IR97vaLn7SaMgRvw=; b=kvOR1LBvbXHsTdtL2TP6eGDZfFC1ooMf5iQTDsBYgNoJtSbpgX4ulckTUbNODBqoP7 riZzlWq93xqkYi3zXErNHAHy+/gZ9NrBfN7Gye2AF282HV8iGeljGnl6WQLR0VRh/DEO vErb11z8cHI5SW+sUPYZCGttNjJuR7vSpITj4= 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=4SiIjIE0HqgktULUkxH4huGvPI4IR97vaLn7SaMgRvw=; b=W3Rqw8e5XEEuTkr5cVqIVqpRdczkVjJrFDiZXivFgWGdOpymg9g9oMcHCw/YAKgiwJ 2IwW0LHKafjlh/v+ZUFNfQBYmq0JX0jzdn+/WB3mk8sZWGmxqMRKBHssp1ZcBIVtvrSd oiwiymGgXhK6n/GdLfjTFEBbjcWiQ15gphRUko6tWKwETPywuKTJsgi+0jv60XGdM9hp W3wMkCnl3neXfijRzO4gZGIng40Uns3uzmh44APVRtwgvLN5ebDzSlcOf5gvl9l0R6+E UzGpk5QM245hytnLrB6hoQr2qBtJvNiqkRjvRl+bhWUF9F94RhaOyspOiW9IaaylCduH xIrQ== X-Gm-Message-State: AOAM532ZKNNBZuzcLYEz9Df3yBFEZqnBX8lcxJ/gGLS7tbcJS1cR53xy h4rrkWtBCBDXZmowkVHD+VTgeQ== X-Received: by 2002:a63:c04a:: with SMTP id z10mr8594229pgi.430.1589317783313; Tue, 12 May 2020 14:09:43 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id g17sm2433251pgg.43.2020.05.12.14.09.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2020 14:09:42 -0700 (PDT) Date: Tue, 12 May 2020 14:09:41 -0700 From: Kees Cook To: =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= Cc: linux-kernel@vger.kernel.org, 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, linux-security-module@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH v5 2/6] fs: Add a MAY_EXECMOUNT flag to infer the noexec mount property Message-ID: <202005121407.A339D31A@keescook> References: <20200505153156.925111-1-mic@digikod.net> <20200505153156.925111-3-mic@digikod.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200505153156.925111-3-mic@digikod.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 05, 2020 at 05:31:52PM +0200, Micka?l Sala?n wrote: > This new MAY_EXECMOUNT flag enables to check if the underlying mount > point of an inode is marked as executable. This is useful to implement > a security policy taking advantage of the noexec mount option. > > This flag is set according to path_noexec(), which checks if a mount > point is mounted with MNT_NOEXEC or if the underlying superblock is > SB_I_NOEXEC. > > Signed-off-by: Micka?l Sala?n > Reviewed-by: Philippe Tr?buchet > Reviewed-by: Thibaut Sautereau > Cc: Aleksa Sarai > Cc: Al Viro > Cc: Kees Cook > --- > fs/namei.c | 2 ++ > include/linux/fs.h | 2 ++ > 2 files changed, 4 insertions(+) > > diff --git a/fs/namei.c b/fs/namei.c > index a320371899cf..33b6d372e74a 100644 > --- a/fs/namei.c > +++ b/fs/namei.c > @@ -2849,6 +2849,8 @@ static int may_open(const struct path *path, int acc_mode, int flag) > break; > } > > + /* Pass the mount point executability. */ > + acc_mode |= path_noexec(path) ? 0 : MAY_EXECMOUNT; > error = inode_permission(inode, MAY_OPEN | acc_mode); > if (error) > return error; > diff --git a/include/linux/fs.h b/include/linux/fs.h > index 313c934de9ee..79435fca6c3e 100644 > --- a/include/linux/fs.h > +++ b/include/linux/fs.h > @@ -103,6 +103,8 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset, > #define MAY_NOT_BLOCK 0x00000080 > /* the inode is opened with O_MAYEXEC */ > #define MAY_OPENEXEC 0x00000100 > +/* the mount point is marked as executable */ > +#define MAY_EXECMOUNT 0x00000200 > > /* > * flags in file.f_mode. Note that FMODE_READ and FMODE_WRITE must correspond I find this name unintuitive, but I cannot think of anything better, since I think my problem is that "MAY" doesn't map to the language I want to use to describe what this flag is indicating. Reviewed-by: Kees Cook -- Kees Cook