Skip to contentSkip to conversation

ntfs: apply Windows name checks only with windows_names

PATCH In review Namjae Jeon 2 participants 4 messages Jul 24 – Jul 27 NTFS filesystem

lore
Share & tools
lore

Namjae Jeon

author maintainer
#0 lore raw

PATCH 1/2 ntfs: apply Windows name checks only with windows_names

The windows_names mount option is documented to reject names containing characters forbidden by Windows. However, ntfs_check_bad_windows_name() unconditionally rejects those characters before checking the mount option.

Move the character validation after the option check so a default NTFS mount accepts POSIX names such as names containing ':'. Mounts using windows_names retain the existing Windows-compatible validation, including reserved device names and trailing spaces or dots.

---
 fs/ntfs/namei.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/ntfs/namei.c +3 -3
index cd403b1d99ee..aee7aabaf059 100644
@@ -61,12 +61,12 @@ static int ntfs_check_bad_windows_name(struct ntfs_volume *vol,
 				       const __le16 *wc,
 				       unsigned int wc_len)
 {
-	if (ntfs_check_bad_char(wc, wc_len))
-		return -EINVAL;
-
 	if (!NVolCheckWindowsNames(vol))
 		return 0;
 
+	if (ntfs_check_bad_char(wc, wc_len))
+		return -EINVAL;
+
 	/* Check for trailing space or dot. */
 	if (wc_len > 0 &&
 	    (wc[wc_len - 1] == cpu_to_le16(' ') ||
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

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

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.

---
 fs/ntfs/file.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
fs/ntfs/file.c +7 -4
index c8e49f83fd92..a6855d62e1fc 100644
@@ -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);
Signature · 1 line
2.25.1
maintainer Reviewed-by on v1 2/2
#2 lore raw

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

2026년 7월 25일 (토) 오전 12:49, Namjae Jeon <[email protected]>님이 작성:

Quoted 6 lines

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.

Quoted 6 lines

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.

Looks good to me.

Quoted 33 lines
---
 fs/ntfs/file.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
fs/ntfs/file.c +7 -5
index c8e49f83fd92..a6855d62e1fc 100644
@@ -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

Signature · 2 lines
Thanks,
Hyunchul
maintainer Reviewed-by on v1 1/2
#3 lore raw
In reply to Namjae Jeon

2026년 7월 25일 (토) 오전 12:49, Namjae Jeon <[email protected]>님이 작성:

Quoted 11 lines

The windows_names mount option is documented to reject names containing characters forbidden by Windows. However, ntfs_check_bad_windows_name() unconditionally rejects those characters before checking the mount option.

Move the character validation after the option check so a default NTFS mount accepts POSIX names such as names containing ':'. Mounts using windows_names retain the existing Windows-compatible validation, including reserved device names and trailing spaces or dots.

Looks good to me.

Quoted 27 lines
---
 fs/ntfs/namei.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/ntfs/namei.c +3 -4
index cd403b1d99ee..aee7aabaf059 100644
@@ -61,12 +61,12 @@ static int ntfs_check_bad_windows_name(struct ntfs_volume *vol,
                                       const __le16 *wc,
                                       unsigned int wc_len)
 {
-       if (ntfs_check_bad_char(wc, wc_len))
-               return -EINVAL;
-
        if (!NVolCheckWindowsNames(vol))
                return 0;
 
+       if (ntfs_check_bad_char(wc, wc_len))
+               return -EINVAL;
+
        /* Check for trailing space or dot. */
        if (wc_len > 0 &&
            (wc[wc_len - 1] == cpu_to_le16(' ') ||
--

2.25.1

Signature · 2 lines
Thanks,
Hyunchul