mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] fs/ntfs3: accept unchanged read-only fileattr flags
@ 2026-12-04  8:21 Hungyu Lin
  0 siblings, 0 replies; only message in thread
From: Hungyu Lin @ 2026-12-04  8:21 UTC (permalink / raw)
  To: almaz.alexandrovich
  Cc: ntfs3, linux-fsdevel, linux-kernel, cel, liubaolin, dennylin0707, stable

ntfs_fileattr_get() reports FS_CASEFOLD_FL on nocase mounts and
FS_COMPR_FL or FS_ENCRYPT_FL on compressed or encrypted files, but
ntfs_fileattr_set() only accepts FS_IMMUTABLE_FL, FS_APPEND_FL and
FS_NODUMP_FL.

chattr reads the flags, changes one bit and writes them all back, so
chattr +d, -d, +i, -i, +a and -a all fail with EOPNOTSUPP on a nocase
mount and on compressed or encrypted files. FS_IOC_FSSETXATTR fails
there even when nothing changes, because vfs_fileattr_set() adds the
reported flags back before calling ntfs_fileattr_set().

Fix this by also accepting these flags when ntfs_fileattr_get() would
report them, as hfsplus does for FS_CASEFOLD_FL. They are not changed,
and setting one that is not already reported still fails with
EOPNOTSUPP.

Fixes: 33f29fc7c67e ("fs/ntfs3: add fileattr support")
Cc: stable@vger.kernel.org
Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
---
v2: Describe the full impact, and build an allowed mask the way hfsplus
    does instead of calling ntfs_fileattr_get() from ntfs_fileattr_set().
v1: https://lore.kernel.org/all/20261029220203.80532-1-dennylin0707@gmail.com/

 fs/ntfs3/file.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c
index a02244e3b532..54d02684f420 100644
--- a/fs/ntfs3/file.c
+++ b/fs/ntfs3/file.c
@@ -134,8 +134,10 @@ int ntfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
 		      struct file_kattr *fa)
 {
 	struct inode *inode = d_inode(dentry);
+	struct ntfs_sb_info *sbi = inode->i_sb->s_fs_info;
 	struct ntfs_inode *ni = ntfs_i(inode);
 	u32 flags = fa->flags;
+	u32 allowed = FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL;
 	unsigned int new_fl = 0;
 
 	/* Avoid any operation if inode is bad. */
@@ -145,7 +147,16 @@ int ntfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
 	if (fileattr_has_fsx(fa))
 		return -EOPNOTSUPP;
 
-	if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL))
+	if (sbi->options->nocase)
+		allowed |= FS_CASEFOLD_FL;
+
+	if (is_compressed(ni))
+		allowed |= FS_COMPR_FL;
+
+	if (is_encrypted(ni))
+		allowed |= FS_ENCRYPT_FL;
+
+	if (flags & ~allowed)
 		return -EOPNOTSUPP;
 
 	if (flags & FS_IMMUTABLE_FL)
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-04  8:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-04  8:21 [PATCH v2] fs/ntfs3: accept unchanged read-only fileattr flags Hungyu Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®