fs/ntfs3: accept unchanged read-only fileattr flags
Subsystems (3)
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")
Signed-off-by Hungyu Lin <[email protected]>
--- fs/ntfs3/file.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
fs/ntfs3/file.c +8 -4
@@ -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 )