[PATCH 2/2] ntfs: preserve chmod mode before applying mount masks

Namjae Jeon <[email protected]> Sat, 25 Jul 2026 00:49:00 +0900
Newsgroups dev.linux.lists.ntfs
Message-ID <[email protected]>
fmask and dmask must continue to constrain the effective permissions
of every file on a mount. Applying either mask before persisting an
ATTR_MODE change, however, stores the masked mode in . later remount with
a less restrictive mask then cannot restore the mode that chmod requested.

Store the requested mode in  first, then apply the mount mask to
the in-memory inode. This retains the mount-wide access restriction
without making it permanent. Also return failures while writing the
WSL inode EA to the caller.

Signed-off-by: Namjae Jeon <[email protected]>
---
 fs/ntfs/file.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
index c8e49f83fd92..a6855d62e1fc 100644
--- a/fs/ntfs/file.c
+++ b/fs/ntfs/file.c
@@ -342,14 +342,17 @@ int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 		if (ia_valid & ATTR_MODE)
 			flags |= NTFS_EA_MODE;
 
+		mutex_lock(&ni->mrec_lock);
+		err = ntfs_ea_set_wsl_inode(vi, 0, NULL, flags);
+		mutex_unlock(&ni->mrec_lock);
+		if (err)
+			goto out;
+
+		/* Apply mount masks after saving the unmasked POSIX mode. */
 		if (S_ISDIR(vi->i_mode))
 			vi->i_mode &= ~vol->dmask;
 		else
 			vi->i_mode &= ~vol->fmask;
-
-		mutex_lock(&ni->mrec_lock);
-		ntfs_ea_set_wsl_inode(vi, 0, NULL, flags);
-		mutex_unlock(&ni->mrec_lock);
 	}
 
 	mark_inode_dirty(vi);
-- 
2.25.1