[PATCH v2] fs/ntfs3: accept unchanged read-only fileattr flags
From: Hungyu Lin
Date: Fri Dec 04 2026 - 03:22:03 EST
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@xxxxxxxxxxxxxxx
Signed-off-by: Hungyu Lin <dennylin0707@xxxxxxxxx>
---
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@xxxxxxxxx/
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