Linux EXT4 FS development
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: tytso@mit.edu
Cc: linux-ext4@vger.kernel.org
Subject: [PATCH 23/29] fuse2fs: check for supported xattr name prefixes
Date: Wed, 21 May 2025 15:40:55 -0700	[thread overview]
Message-ID: <174786677959.1383760.12099114841852662650.stgit@frogsfrogsfrogs> (raw)
In-Reply-To: <174786677421.1383760.15289906755026332870.stgit@frogsfrogsfrogs>

From: Darrick J. Wong <djwong@kernel.org>

Ignore any xattr calls for name prefixes that the kernel doesn't also
support.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 lib/ext2fs/ext2fsP.h |    3 +++
 misc/fuse2fs.c       |   37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)


diff --git a/lib/ext2fs/ext2fsP.h b/lib/ext2fs/ext2fsP.h
index d1f2105e9813ca..428081c9e2ff38 100644
--- a/lib/ext2fs/ext2fsP.h
+++ b/lib/ext2fs/ext2fsP.h
@@ -214,4 +214,7 @@ typedef void (*ext2_exit_fn)(void *);
 errcode_t ext2fs_add_exit_fn(ext2_exit_fn fn, void *data);
 errcode_t ext2fs_remove_exit_fn(ext2_exit_fn fn, void *data);
 
+#define ARRAY_SIZE(array)			\
+        (sizeof(array) / sizeof(array[0]))
+
 #define EXT2FS_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2*!!(cond)]))
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 74bbe661a417e5..28b77d367cf705 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -2443,6 +2443,27 @@ static int op_statfs(const char *path EXT2FS_ATTR((unused)),
 	return 0;
 }
 
+static const char *valid_xattr_prefixes[] = {
+	"user.",
+	"trusted.",
+	"security.",
+	"gnu.",
+	"system.",
+};
+
+static int validate_xattr_name(const char *name)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(valid_xattr_prefixes); i++) {
+		if (!strncmp(name, valid_xattr_prefixes[i],
+					strlen(valid_xattr_prefixes[i])))
+			return 1;
+	}
+
+	return 0;
+}
+
 static int op_getxattr(const char *path, const char *key, char *value,
 		       size_t len)
 {
@@ -2456,6 +2477,9 @@ static int op_getxattr(const char *path, const char *key, char *value,
 	errcode_t err;
 	int ret = 0;
 
+	if (!validate_xattr_name(key))
+		return -ENODATA;
+
 	FUSE2FS_CHECK_CONTEXT(ff);
 	fs = ff->fs;
 	pthread_mutex_lock(&ff->bfl);
@@ -2626,6 +2650,9 @@ static int op_setxattr(const char *path EXT2FS_ATTR((unused)),
 	if (flags & ~(XATTR_CREATE | XATTR_REPLACE))
 		return -EOPNOTSUPP;
 
+	if (!validate_xattr_name(key))
+		return -EINVAL;
+
 	FUSE2FS_CHECK_CONTEXT(ff);
 	fs = ff->fs;
 	pthread_mutex_lock(&ff->bfl);
@@ -2714,6 +2741,16 @@ static int op_removexattr(const char *path, const char *key)
 	errcode_t err;
 	int ret = 0;
 
+	/*
+	 * Once in a while libfuse gives us a no-name xattr to delete as part
+	 * of clearing ACLs.  Just pretend we cleared them.
+	 */
+	if (key[0] == 0)
+		return 0;
+
+	if (!validate_xattr_name(key))
+		return -ENODATA;
+
 	FUSE2FS_CHECK_CONTEXT(ff);
 	fs = ff->fs;
 	pthread_mutex_lock(&ff->bfl);


  parent reply	other threads:[~2025-05-21 22:40 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-21 22:34 [PATCHSET 1/6] fuse2fs: even more bug fixes Darrick J. Wong
2025-05-21 22:35 ` [PATCH 01/29] libext2fs: fix unix io manager invalidation Darrick J. Wong
2025-05-21 22:35 ` [PATCH 02/29] libext2fs: fix livelock in the unix io manager Darrick J. Wong
2025-05-21 22:35 ` [PATCH 03/29] fuse2fs: clean up error messages Darrick J. Wong
2025-05-21 22:35 ` [PATCH 04/29] fuse2fs: fix cache size parsing Darrick J. Wong
2025-05-21 22:36 ` [PATCH 05/29] fuse2fs: compact all the boolean flags in struct fuse2fs Darrick J. Wong
2025-05-21 22:36 ` [PATCH 06/29] fuse2fs: support XATTR_CREATE/REPLACE in setxattr Darrick J. Wong
2025-05-21 22:36 ` [PATCH 07/29] fuse2fs: fix error return handling in op_truncate Darrick J. Wong
2025-05-21 22:37 ` [PATCH 08/29] fuse2fs: flip parameter order in __translate_error Darrick J. Wong
2025-05-21 22:37 ` [PATCH 09/29] fuse2fs: fix CLI argument parsing leaks Darrick J. Wong
2025-05-21 22:37 ` [PATCH 10/29] fuse2fs: allow some control over acls Darrick J. Wong
2025-05-21 22:37 ` [PATCH 11/29] fuse2fs: enable processing of acls in the kernel Darrick J. Wong
2025-05-21 22:38 ` [PATCH 12/29] fuse2fs: make removexattr work correctly Darrick J. Wong
2025-05-21 22:38 ` [PATCH 13/29] fuse2fs: implement O_TRUNC correctly Darrick J. Wong
2025-05-21 22:38 ` [PATCH 14/29] fuse2fs: rearrange check_inum_access parameters a bit Darrick J. Wong
2025-05-21 22:38 ` [PATCH 15/29] fuse2fs: make filesystem corruption a hard error Darrick J. Wong
2025-05-21 22:39 ` [PATCH 16/29] fuse2fs: make internal state " Darrick J. Wong
2025-05-21 22:39 ` [PATCH 17/29] fuse2fs: make bad magic numbers report a corruption error too Darrick J. Wong
2025-05-21 22:39 ` [PATCH 18/29] fuse2fs: return EPERM for write access to EXT2_IMMUTABLE_FL files Darrick J. Wong
2025-05-21 22:39 ` [PATCH 19/29] fuse2fs: check the immutable flag in more places Darrick J. Wong
2025-05-21 22:40 ` [PATCH 20/29] fuse2fs: implement O_APPEND correctly Darrick J. Wong
2025-05-21 22:40 ` [PATCH 21/29] fuse2fs: decode fuse_main error codes Darrick J. Wong
2025-05-21 22:40 ` [PATCH 22/29] fuse2fs: fix fallocate zero range Darrick J. Wong
2025-05-21 22:40 ` Darrick J. Wong [this message]
2025-05-21 22:41 ` [PATCH 24/29] fuse2fs: fix return value handling Darrick J. Wong
2025-05-21 22:41 ` [PATCH 25/29] fuse2fs: fix removing ea inodes when freeing a file Darrick J. Wong
2025-05-21 22:41 ` [PATCH 26/29] fuse2fs: fix post-EOF preallocation clearing on truncation Darrick J. Wong
2025-05-21 22:41 ` [PATCH 27/29] fuse2fs: also ignore the nodelalloc mount option Darrick J. Wong
2025-05-21 22:42 ` [PATCH 28/29] fuse2fs: propagate default ACLs to new children Darrick J. Wong
2025-05-21 22:42 ` [PATCH 29/29] fuse2fs: fix group membership checking in op_chmod Darrick J. Wong
2025-05-23 14:03 ` [PATCHSET 1/6] fuse2fs: even more bug fixes Theodore Ts'o
2025-05-29  1:37   ` Darrick J. Wong

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=174786677959.1383760.12099114841852662650.stgit@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox