fs/ntfs3: accept unchanged read-only fileattr flags
Subsystems (3)
PATCH v2 1/1 fs/ntfs3: accept unchanged read-only fileattr flags
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.
---
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/[email protected]/
fs/ntfs3/file.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
fs/ntfs3/file.c +12 -1
@@ -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 )
Signature · 1 line
2.43.0