Skip to contentSkip to conversation

fs/ntfs3: accept unchanged read-only fileattr flags

PATCH New Hungyu Lin 1 participant 1 message Oct 29

Subsystems (3)
lore
Share & tools
lore

Hungyu Lin

author
#0 lore raw

PATCH 1/1 fs/ntfs3: accept unchanged read-only fileattr flags

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")
---
 fs/ntfs3/file.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
fs/ntfs3/file.c +8 -4
index 52e1cd969e06..af6fb438eaa8 100644
@@ -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)