[PATCH] fs/ntfs3: accept unchanged read-only fileattr flags
From: Hungyu Lin
Date: Thu Oct 29 2026 - 18:02:54 EST
ntfs_fileattr_get() reports casefold, compression and encryption flags,
while ntfs_fileattr_set() only accepts immutable, append and nodump.
chattr preserves the reported flags when adding or removing nodump, so
chattr +d and -d fail with EOPNOTSUPP on nocase mounts and compressed
files even though neither command requests a change to those properties.
Read the current attributes and allow reported flags to be passed back.
Continue rejecting unsupported bits that are not already present, and
keep applying only the existing mutable flags. Requests that omit
read-only flags, such as chattr =d, retain their existing behavior.
Fixes: 33f29fc7c67e ("fs/ntfs3: add fileattr support")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Hungyu Lin <dennylin0707@xxxxxxxxx>
---
fs/ntfs3/file.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c
index 52e1cd969e06..af6fb438eaa8 100644
--- a/fs/ntfs3/file.c
+++ b/fs/ntfs3/file.c
@@ -134,17 +134,21 @@ int ntfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
{
struct inode *inode = d_inode(dentry);
struct ntfs_inode *ni = ntfs_i(inode);
+ struct file_kattr old_fa = {};
u32 flags = fa->flags;
unsigned int new_fl = 0;
+ int err;
- /* Avoid any operation if inode is bad. */
- if (unlikely(is_bad_ni(ni)))
- return -EINVAL;
+ err = ntfs_fileattr_get(dentry, &old_fa);
+ if (err)
+ return err;
if (fileattr_has_fsx(fa))
return -EOPNOTSUPP;
- if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL))
+ /* Accept unchanged read-only flags. */
+ if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL |
+ old_fa.flags))
return -EOPNOTSUPP;
if (flags & FS_IMMUTABLE_FL)