Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6396519rwi; Tue, 18 Oct 2022 11:50:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Jg3zQtWSEywo8/H+dL5uhA3fdzsKatUklSHSFwKb0QqjIlckKeCkc9ykx78llVsSkvnPp X-Received: by 2002:a05:6402:274c:b0:45d:4015:cd8c with SMTP id z12-20020a056402274c00b0045d4015cd8cmr4014463edd.268.1666119036191; Tue, 18 Oct 2022 11:50:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666119036; cv=none; d=google.com; s=arc-20160816; b=aWNma6iFzvq7fL+UPd4yaJUz3A4z4O6uwLuWVhiZeVo1viaMiIz5zPVkWry9YkxPNg zUaIjwqhJFLac5mtXRijlwxvS8Io6zgHbypJu5/D0/HRAYov1EwXmR43y7kAPNfAuhQE lLCKhrXOIv4pDuPJXVNc4ARjnMCG/Q/Vae4u08D6aeWsUjbeD6mmxUC38BHLHywgfsXO LNLRwv/MlHJVdMxazOvrU41m6EpuXUjbtePaZu/PtE9/1CnH+/sINxyOHRSd2ktF8ZNw +xYxPBDIsB98rMwQYDxlT94QAKswU6gUoMMiKl/Kmge2rt5zEZH1IrOA25FPBc6ERMTE 5tpg== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=XnD0cUVp+TOTlgr52vU4IJ+UQNYJwnMUoL+t7q45VyE=; b=COswBe5raigX5TLsPsNPkkYIaFHgEq5QUt1x4I3eWJtzeyylp4Gq/2ihB9VCR9svLg u8eFzaQVKyvAscnZ1nIDfNEWg+uh8hCqFG+j9qLPz3AkYyXdjyQkUBjNaJZWCrFw5U7T R1F61+q9f0CBgGNYqFPXRglflIYZoafBOfjLgmHgvLICmkdQ7sbe8kNKmBGis/66p0LU r4ITe1PV9rzln97lN6pB/WVy5zYc0YGWOuiKT8V/3nJi1/HEfBlPVhoOQDkqHSuxOl3n jp8TpN+11OKWm4N/DZE75dPzjEy8U8wNHVl0obPdLyGweQ5oujrkHBL2q/Ek4RKS2ga3 4+uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=knjecM+J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ds1-20020a170907724100b0078e18bd3073si12904551ejc.820.2022.10.18.11.50.10; Tue, 18 Oct 2022 11:50:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=knjecM+J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S229841AbiJRSZh (ORCPT + 99 others); Tue, 18 Oct 2022 14:25:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230168AbiJRSZV (ORCPT ); Tue, 18 Oct 2022 14:25:21 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70540DF08 for ; Tue, 18 Oct 2022 11:25:06 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id f23so14642839plr.6 for ; Tue, 18 Oct 2022 11:25:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=XnD0cUVp+TOTlgr52vU4IJ+UQNYJwnMUoL+t7q45VyE=; b=knjecM+JwXsRjmXTN38QTXdo60yLmZbtz3TiWB6dKs1qQ30ZMLuU5uJKsLks+W19SL MhCYYnb+l60NN2dFy1uHPJPAONKJjdBvZIKuQ839w8pnHn6FV3rCq6AXDJoeopNRIXa7 NAdJf2F6f8oMnGxEvBxeISjz0+pS8DGQ57Cvc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=XnD0cUVp+TOTlgr52vU4IJ+UQNYJwnMUoL+t7q45VyE=; b=jbOe5sLsW+uK52HjHyMp8zh0+V+NRd6wk1tYMV3aq0XznxhhLOdUVlvjL0WSlOU2es Wp1N36TpR1WIXzdh0vonUwL5rVUvboCbKDLmdOmLLuWaFxMDWRNcwMc03kzDNrHJN2dr DlHJ1R1V7M/VqyiD5bXMZjc8ciOUBvB+TwlvLDR/QdThJsE5hFp+5IujtJpXnOMuvbdd LT/o8ZSlEztfTZX2IMVK/sJ5iXkIfvSa7dmJGb51i9YcamGOAnBNJ9Jz8A8iOh9YegEV IA8z0dD1qA10glTLMyfXOoHjRjzb7QV3S5SYYzAnQYpH7iwnQ8+DN1svilDyipfgIbn/ iT7Q== X-Gm-Message-State: ACrzQf3YXI7zYNI2SPxEdF3tIgBwGkfO0HZ8rG/Psl5hG1fVNvZTM8AO 8O/PXnUEDXODk2MSHr6brIBT3w== X-Received: by 2002:a17:902:ea85:b0:17f:88c1:7015 with SMTP id x5-20020a170902ea8500b0017f88c17015mr4189852plb.49.1666117504543; Tue, 18 Oct 2022 11:25:04 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id m4-20020a170902f64400b00176b84eb29asm8884968plg.301.2022.10.18.11.25.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Oct 2022 11:25:03 -0700 (PDT) Date: Tue, 18 Oct 2022 11:25:02 -0700 From: Kees Cook To: Christian Brauner Cc: Mimi Zohar , John Johansen , Paul Moore , James Morris , "Serge E. Hallyn" , linux-security-module@vger.kernel.org, =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= , KP Singh , Casey Schaufler , linux-kernel@vger.kernel.org, linux-integrity@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH 6/9] fs: Introduce file_to_perms() helper Message-ID: <202210181124.73B5B7ECCE@keescook> References: <20221013222702.never.990-kees@kernel.org> <20221013223654.659758-6-keescook@chromium.org> <20221018141037.zzpfjzutqbutbpiy@wittgenstein> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221018141037.zzpfjzutqbutbpiy@wittgenstein> X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 Tue, Oct 18, 2022 at 04:10:37PM +0200, Christian Brauner wrote: > On Thu, Oct 13, 2022 at 03:36:51PM -0700, Kees Cook wrote: > > Extract the logic used by LSM file hooks to be able to reconstruct the > > access mode permissions from an open. > > > > Cc: John Johansen > > Cc: Paul Moore > > Cc: James Morris > > Cc: "Serge E. Hallyn" > > Cc: linux-security-module@vger.kernel.org > > Signed-off-by: Kees Cook > > --- > > include/linux/fs.h | 22 ++++++++++++++++++++++ > > security/apparmor/include/file.h | 18 ++++-------------- > > 2 files changed, 26 insertions(+), 14 deletions(-) > > > > diff --git a/include/linux/fs.h b/include/linux/fs.h > > index 9eced4cc286e..814f10d4132e 100644 > > --- a/include/linux/fs.h > > +++ b/include/linux/fs.h > > @@ -993,6 +993,28 @@ static inline struct file *get_file(struct file *f) > > #define get_file_rcu(x) atomic_long_inc_not_zero(&(x)->f_count) > > #define file_count(x) atomic_long_read(&(x)->f_count) > > > > +/* Calculate the basic MAY_* flags needed for a given file. */ > > +static inline u8 file_to_perms(struct file *file) > > As long as there aren't multiple users of this and especially none in > the vfs proper please don't move this into fs.h. It's overloaded enough > as it is and we have vague plans on splitting it further in the future. Sure -- this can live in a security .h file somewhere. -- Kees Cook