From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0965C2D0FA for ; Tue, 12 May 2020 21:09:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7CD2920740 for ; Tue, 12 May 2020 21:09:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="kvOR1LBv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731253AbgELVJo (ORCPT ); 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-Google-Smtp-Source: ABdhPJxt840LEl+4pcP5gOb8tskJnRcbgXJ1+UHrDACNk2Ju97S34FmnGoVr6OI4La30DBmSgA2nPQ== 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