Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp823944rdb; Fri, 23 Feb 2024 00:34:01 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUqoBQzHDym3+xlxVDyIhshw8U6RISLhzJtsXoQiCRYsFksWZf97JjoSfo+wKNyK+Ug40D5GFVzBhZ1c8CuDLqC1pnyiy4coKJY3AEPAg== X-Google-Smtp-Source: AGHT+IHuCuKkBgCD8ILiwH8Vm7iTyJjRQkdRWzKF2i4LP8dChC8jIjSSS1h7VhgI2wo87AxJrTvA X-Received: by 2002:a05:6214:2469:b0:68f:b897:baf1 with SMTP id im9-20020a056214246900b0068fb897baf1mr1539401qvb.36.1708677241085; Fri, 23 Feb 2024 00:34:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708677241; cv=pass; d=google.com; s=arc-20160816; b=Fbwx+axnZ8E9egvdzC1r+u9K/rVdpyj+kMeI2B66MON3ejgXqIllPt1VKPQMa3Zk8P /lgVv1LrXb1ZIWc4mlt+COgh63Nx3toGKV/q7k8HQZ24p7EwOgii+bIkG7Duc5yM2DYF nWeMSvQ5pRqFJlZXePtAQCQfzH7hBlf7GJnQ2VLtlwA97K+hnRebSfvUDZZ7SlieCk6P bU6NHrmuq89XrVZawzX0oL4XeAtw626bFphsmOt0bwcU1+L9KQs4Q8sjYafZFP+oEYPA svfD6T0hZ8+sMwhqN9gZtFdz1/0YixD4mUM387l1mKufZhEp9SlOqEtLOWS612UVZm51 KipA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=axlpviH+mOvneMuY97bRQNJvLJNNz+qMt7CX7rvHB9M=; fh=8DYu7hEZnfOKz8raIQkeMuIl5TIwtVW8vrBSs0XLekQ=; b=hvVS+wFJLkiv6fFKzBN0LaM0FyydrgJEYGw+YaTWvc5q5yzWhqnEFi3VdoRP38nCT8 pJU7bIBlnJztYyabOMjcXP9jIzQXVtpeXrSc0nAgA1s2oKVvanQoDs86mLohWnNIqf8z bIEgKh7xD38MKm42DTIxC2qtRZGj+wJJ19YA3ymuIdMDP8UoiZfaXyWeGhQ5frjUSvoT qOgTCmm9WH6WHuxCjvkNyilpK0PNPSW16BhkN1X0l+9dVU/2kNkcjK7/keWvUJBq707c SwBpqwT3Ap77OoL+LXrNhiWSEPKL1sPfpHJHFGJe3tvBXAzMmZe9flLojc3Cq7YS03p3 j1lQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hu0xdDe4; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-77929-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77929-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c1-20020ad45ae1000000b0068f3c2447c1si15227708qvh.300.2024.02.23.00.34.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 00:34:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77929-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hu0xdDe4; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-77929-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77929-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C0DD91C24AA6 for ; Fri, 23 Feb 2024 08:34:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ACA814EB50; Fri, 23 Feb 2024 08:28:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hu0xdDe4" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8B54199B0; Fri, 23 Feb 2024 08:28:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708676890; cv=none; b=R1j1IOL826qHlEYtoAhv3d+CsGJlQjFlRIDmixmioBjIqmsHlltjEzRRNNq4nfDE4d5Pl/E8tsWc3xjPJy5y3JVU9nHUCudRb7nelXsqqLJ41m/WQnrOjrQ+DTY3yZCC2uK2blSa6WFtvdgnxxvHDn//LokzZmgGIQEN69QjEBo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708676890; c=relaxed/simple; bh=q6V2H4gtFXsWFNKk56zPdodpY1DcPJdBBy776jbpCfQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Xb7JDjoSZHK6b0Ur0nYhufq7A2C9LST3zN5BkIfc+EJrf0GrPi9r/rwqpUgcpxAJccjC7a+8nbU667IBo+BfjeHfOGH+ZBc1OIEKi0fc7Oaiw+WLuSMSGxL9fLKKr6Oh9kmoN+/gB3f6DBX2ZK6d7Neqye8dtOWWWhH+fvmRslg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hu0xdDe4; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0AD0C433F1; Fri, 23 Feb 2024 08:28:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708676889; bh=q6V2H4gtFXsWFNKk56zPdodpY1DcPJdBBy776jbpCfQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hu0xdDe4xcBEAVwr6eKhMBXxJbpLZgi9Bpm6xVwg0Uo1fwUlu5WUAnkGqOitKmGq1 tZ6lUtbEZwJ6++CltYmiYny6cfi1Z7WHDaOrsW6nqzRjTohYV2l/pleu2FK3tlJQ9u RiDhf2akStqYEi99gM2+W8bb5quxSvd9vsxhvl9InnFpC1I35omMGlD8EzAmHEUPSm 6wEycOQLd20xkQ0qaCTprFSKep8ZGEDDtu20dmBvLQGZBn+JoBoI4SElAhDemNURx9 iNG/GkSFY+VEjOtVtWQsvP3W3x3T+tIdQ1G1NyCYnbSkf6e8NZup1qc32EHSMuLSrU /0T6ZkyLaWK3Q== Date: Fri, 23 Feb 2024 09:28:01 +0100 From: Christian Brauner To: "Seth Forshee (DigitalOcean)" Cc: Serge Hallyn , Paul Moore , Eric Paris , James Morris , Alexander Viro , Jan Kara , Stephen Smalley , Ondrej Mosnacek , Casey Schaufler , Mimi Zohar , Roberto Sassu , Dmitry Kasatkin , Eric Snowberg , "Matthew Wilcox (Oracle)" , Jonathan Corbet , Miklos Szeredi , Amir Goldstein , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org, audit@vger.kernel.org, selinux@vger.kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-unionfs@vger.kernel.org Subject: Re: [PATCH v2 17/25] fs: add vfs_get_fscaps() Message-ID: <20240223-unzutreffend-streng-40cc6bcbc222@brauner> References: <20240221-idmap-fscap-refactor-v2-0-3039364623bd@kernel.org> <20240221-idmap-fscap-refactor-v2-17-3039364623bd@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20240221-idmap-fscap-refactor-v2-17-3039364623bd@kernel.org> On Wed, Feb 21, 2024 at 03:24:48PM -0600, Seth Forshee (DigitalOcean) wrote: > Provide a type-safe interface for retrieving filesystem capabilities and > a generic implementation suitable for most filesystems. Also add an > internal interface, vfs_get_fscaps_nosec(), which skips security checks > for later use from the capability code. > > Signed-off-by: Seth Forshee (DigitalOcean) > --- > fs/xattr.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ > include/linux/fs.h | 4 ++++ > 2 files changed, 68 insertions(+) > > diff --git a/fs/xattr.c b/fs/xattr.c > index 06290e4ebc03..10d1b1f78fc2 100644 > --- a/fs/xattr.c > +++ b/fs/xattr.c > @@ -181,6 +181,70 @@ xattr_supports_user_prefix(struct inode *inode) > } > EXPORT_SYMBOL(xattr_supports_user_prefix); > > +static int generic_get_fscaps(struct mnt_idmap *idmap, struct dentry *dentry, > + struct vfs_caps *caps) > +{ > + struct inode *inode = d_inode(dentry); > + struct vfs_ns_cap_data nscaps; > + int ret; > + > + ret = __vfs_getxattr(dentry, inode, XATTR_NAME_CAPS, &nscaps, sizeof(nscaps)); > + > + if (ret >= 0) > + ret = vfs_caps_from_xattr(idmap, i_user_ns(inode), caps, &nscaps, ret); > + > + return ret; > +} > + > +/** > + * vfs_get_fscaps_nosec - get filesystem capabilities without security checks > + * @idmap: idmap of the mount the inode was found from > + * @dentry: the dentry from which to get filesystem capabilities > + * @caps: storage in which to return the filesystem capabilities > + * > + * This function gets the filesystem capabilities for the dentry and returns > + * them in @caps. It does not perform security checks. > + * > + * Return: 0 on success, a negative errno on error. > + */ > +int vfs_get_fscaps_nosec(struct mnt_idmap *idmap, struct dentry *dentry, > + struct vfs_caps *caps) > +{ > + struct inode *inode = d_inode(dentry); > + > + if (inode->i_op->get_fscaps) > + return inode->i_op->get_fscaps(idmap, dentry, caps); > + return generic_get_fscaps(idmap, dentry, caps); > +} > + > +/** > + * vfs_get_fscaps - get filesystem capabilities > + * @idmap: idmap of the mount the inode was found from > + * @dentry: the dentry from which to get filesystem capabilities > + * @caps: storage in which to return the filesystem capabilities > + * > + * This function gets the filesystem capabilities for the dentry and returns > + * them in @caps. > + * > + * Return: 0 on success, a negative errno on error. > + */ > +int vfs_get_fscaps(struct mnt_idmap *idmap, struct dentry *dentry, > + struct vfs_caps *caps) > +{ > + int error; > + > + /* > + * The VFS has no restrictions on reading security.* xattrs, so > + * xattr_permission() isn't needed. Only LSMs get a say. > + */ > + error = security_inode_get_fscaps(idmap, dentry); > + if (error) > + return error; > + > + return vfs_get_fscaps_nosec(idmap, dentry, caps); > +} > +EXPORT_SYMBOL(vfs_get_fscaps); > + > int > __vfs_setxattr(struct mnt_idmap *idmap, struct dentry *dentry, > struct inode *inode, const char *name, const void *value, > diff --git a/include/linux/fs.h b/include/linux/fs.h > index 89163e0f7aad..d7cd2467e1ea 100644 > --- a/include/linux/fs.h > +++ b/include/linux/fs.h > @@ -2116,6 +2116,10 @@ extern int vfs_dedupe_file_range(struct file *file, > extern loff_t vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, > struct file *dst_file, loff_t dst_pos, > loff_t len, unsigned int remap_flags); > +extern int vfs_get_fscaps_nosec(struct mnt_idmap *idmap, struct dentry *dentry, > + struct vfs_caps *caps); > +extern int vfs_get_fscaps(struct mnt_idmap *idmap, struct dentry *dentry, > + struct vfs_caps *caps); Please drop the externs. Other than my usual complaing about this falling back to the legacy vfs_*xattr() interfaces, Reviewed-by: Christian Brauner