All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: linux-fsdevel@vger.kernel.org, Christoph Hellwig <hch@lst.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>,
	Seth Forshee <sforshee@kernel.org>,
	"Christian Brauner (Microsoft)" <brauner@kernel.org>
Subject: [PATCH v3 10/10] acl: don't depend on IOP_XATTR
Date: Wed, 01 Feb 2023 14:15:01 +0100	[thread overview]
Message-ID: <20230125-fs-acl-remove-generic-xattr-handlers-v3-10-f760cc58967d@kernel.org> (raw)
In-Reply-To: <20230125-fs-acl-remove-generic-xattr-handlers-v3-0-f760cc58967d@kernel.org>

All codepaths that don't want to implement POSIX ACLs should simply not
implement the associated inode operations instead of relying on
IOP_XATTR. That's the case for all filesystems today.

For vfs_listxattr() all filesystems that explicitly turn of xattrs for a
given inode all set inode->i_op to a dedicated set of inode operations
that doesn't implement ->listxattr().  We can remove the dependency of
vfs_listxattr() on IOP_XATTR.

Removing this dependency will allow us to decouple POSIX ACLs from
IOP_XATTR and they can still be listed even if no other xattr handlers
are implemented. Otherwise we would have to implement elaborate schemes
to raise IOP_XATTR even if sb->s_xattr is set to NULL.

Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
---
Changes in v3:
- Patch introduced.
---
 fs/posix_acl.c | 12 ++++--------
 fs/xattr.c     | 25 ++++++++++++++++++++++++-
 2 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/fs/posix_acl.c b/fs/posix_acl.c
index 7a4d89897c37..881a7fd1cacb 100644
--- a/fs/posix_acl.c
+++ b/fs/posix_acl.c
@@ -1132,12 +1132,10 @@ int vfs_set_acl(struct user_namespace *mnt_userns, struct dentry *dentry,
 	if (error)
 		goto out_inode_unlock;
 
-	if (inode->i_opflags & IOP_XATTR)
+	if (likely(!is_bad_inode(inode)))
 		error = set_posix_acl(mnt_userns, dentry, acl_type, kacl);
-	else if (unlikely(is_bad_inode(inode)))
-		error = -EIO;
 	else
-		error = -EOPNOTSUPP;
+		error = -EIO;
 	if (!error) {
 		fsnotify_xattr(dentry);
 		evm_inode_post_set_acl(dentry, acl_name, kacl);
@@ -1242,12 +1240,10 @@ int vfs_remove_acl(struct user_namespace *mnt_userns, struct dentry *dentry,
 	if (error)
 		goto out_inode_unlock;
 
-	if (inode->i_opflags & IOP_XATTR)
+	if (likely(!is_bad_inode(inode)))
 		error = set_posix_acl(mnt_userns, dentry, acl_type, NULL);
-	else if (unlikely(is_bad_inode(inode)))
-		error = -EIO;
 	else
-		error = -EOPNOTSUPP;
+		error = -EIO;
 	if (!error) {
 		fsnotify_xattr(dentry);
 		evm_inode_post_remove_acl(mnt_userns, dentry, acl_name);
diff --git a/fs/xattr.c b/fs/xattr.c
index 8743402a5e8b..56e37461014e 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -457,6 +457,28 @@ vfs_getxattr(struct user_namespace *mnt_userns, struct dentry *dentry,
 }
 EXPORT_SYMBOL_GPL(vfs_getxattr);
 
+/**
+ * vfs_listxattr - retrieve \0 separated list of xattr names
+ * @dentry: the dentry from whose inode the xattr names are retrieved
+ * @list: buffer to store xattr names into
+ * @size: size of the buffer
+ *
+ * This function returns the names of all xattrs associated with the
+ * inode of @dentry.
+ *
+ * Note, for legacy reasons the vfs_listxattr() function lists POSIX
+ * ACLs as well. Since POSIX ACLs are decoupled from IOP_XATTR the
+ * vfs_listxattr() function doesn't check for this flag since a
+ * filesystem could implement POSIX ACLs without implementing any other
+ * xattrs.
+ *
+ * However, since all codepaths that remove IOP_XATTR also assign of
+ * inode operations that either don't implement or implement a stub
+ * ->listxattr() operation.
+ *
+ * Return: On success, the size of the buffer that was used. On error a
+ *         negative error code.
+ */
 ssize_t
 vfs_listxattr(struct dentry *dentry, char *list, size_t size)
 {
@@ -466,7 +488,8 @@ vfs_listxattr(struct dentry *dentry, char *list, size_t size)
 	error = security_inode_listxattr(dentry);
 	if (error)
 		return error;
-	if (inode->i_op->listxattr && (inode->i_opflags & IOP_XATTR)) {
+
+	if (inode->i_op->listxattr) {
 		error = inode->i_op->listxattr(dentry, list, size);
 	} else {
 		error = security_inode_listsecurity(inode, list, size);

-- 
2.34.1


  parent reply	other threads:[~2023-02-01 13:16 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-01 13:14 [PATCH v3 00/10] acl: drop posix acl handlers from xattr handlers Christian Brauner
2023-02-01 13:14 ` Christian Brauner
2023-02-01 13:14 ` Christian Brauner
2023-02-01 13:14 ` [f2fs-dev] " Christian Brauner
2023-02-01 13:14 ` [PATCH v3 01/10] xattr: simplify listxattr helpers Christian Brauner
2023-02-01 13:14 ` [PATCH v3 02/10] xattr: add listxattr helper Christian Brauner
2023-02-01 13:14 ` [PATCH v3 03/10] xattr: remove unused argument Christian Brauner
2023-02-01 13:14 ` [PATCH v3 04/10] fs: drop unused posix acl handlers Christian Brauner
2023-02-01 13:14 ` [PATCH v3 05/10] fs: simplify ->listxattr() implementation Christian Brauner
2023-02-01 13:14   ` Christian Brauner
2023-02-01 13:14   ` Christian Brauner
2023-02-01 13:14   ` [f2fs-dev] " Christian Brauner
2023-02-01 13:14 ` [PATCH v3 06/10] reiserfs: rework " Christian Brauner
2023-02-01 13:14 ` [PATCH v3 07/10] fs: rename generic posix acl handlers Christian Brauner
2023-02-01 13:14 ` [PATCH v3 08/10] reiserfs: rework priv inode handling Christian Brauner
2023-02-01 13:15 ` [PATCH v3 09/10] ovl: check for ->listxattr() support Christian Brauner
2023-02-01 13:15 ` Christian Brauner [this message]
2023-02-01 13:30 ` [f2fs-dev] [PATCH v3 00/10] acl: drop posix acl handlers from xattr handlers Christoph Hellwig
2023-02-01 13:30   ` Christoph Hellwig
2023-02-01 13:30   ` Christoph Hellwig
2023-02-01 13:30   ` Christoph Hellwig
2023-02-01 13:42   ` Christian Brauner
2023-02-01 13:42     ` Christian Brauner
2023-02-01 13:42     ` Christian Brauner
2023-02-01 13:42     ` [f2fs-dev] " Christian Brauner
2023-03-06  9:26     ` Christian Brauner
2023-03-06  9:26       ` Christian Brauner
2023-03-06  9:26       ` Christian Brauner
2023-03-06  9:26       ` [f2fs-dev] " Christian Brauner
2023-03-06  9:23 ` Christian Brauner
2023-03-06  9:23   ` Christian Brauner
2023-03-06  9:23   ` Christian Brauner
2023-03-06  9:23   ` [f2fs-dev] " Christian Brauner
2023-04-26 23:07 ` patchwork-bot+f2fs
2023-04-26 23:07   ` patchwork-bot+f2fs
2023-04-26 23:07   ` patchwork-bot+f2fs
2023-04-26 23:07   ` patchwork-bot+f2fs

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230125-fs-acl-remove-generic-xattr-handlers-v3-10-f760cc58967d@kernel.org \
    --to=brauner@kernel.org \
    --cc=hch@lst.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=sforshee@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.