[PATCH v4 05/12] ntfs: initialize inherited ACLs after allocating the MFT record

From: Baolin Liu

Date: Sun Nov 15 2026 - 08:26:49 EST


From: Baolin Liu <liubaolin@xxxxxxxxxx>

ntfs_init_acl() can write EAs before __ntfs_create() allocates an MFT
record, so inherited ACLs can disappear after inode eviction.

Initialize ACLs after MFT allocation and standard attribute setup,
releasing the record locks around the ACL helpers. Refresh the mode and
use the post-ACL ctime for FILE_NAME and its index entry. Roll back EA
and EA_INFORMATION on failure.

Skip writeback while I_CREATING is set: failed creation clears I_NEW but
retains I_CREATING after freeing the MFT record.

Fixes: af0db57d4293 ("ntfs: update inode operations")
Signed-off-by: Baolin Liu <liubaolin@xxxxxxxxxx>
---
Changes since v3: add the I_CREATING guard and Fixes tag, and apply
after the cleanup fixes. Drop Reviewed-by because the code changed.

Tested cold-cache ACL inheritance and creation rollback. Forced writeback
after I_NEW was cleared in failed named and anonymous creation; no access
to the freed MFT record occurred, and subsequent creation passed remount.

fs/ntfs/inode.c | 4 ++++
fs/ntfs/namei.c | 49 +++++++++++++++++++++++++++++++++++--------------
2 files changed, 39 insertions(+), 14 deletions(-)

diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c
index 6a9f488e2775..885818f00b78 100644
--- a/fs/ntfs/inode.c
+++ b/fs/ntfs/inode.c
@@ -2955,6 +2955,10 @@ int __ntfs_write_inode(struct inode *vi, int sync)
return 0;
}

+ /* Failed creations retain I_CREATING after discard_new_inode(). */
+ if (inode_state_read_once(vi) & I_CREATING)
+ return 0;
+
/* igrab prevents vi from being evicted while mrec_lock is hold. */
if (igrab(vi) != NULL)
need_iput = true;
diff --git a/fs/ntfs/namei.c b/fs/ntfs/namei.c
index abb3675757e9..05e2747bae54 100644
--- a/fs/ntfs/namei.c
+++ b/fs/ntfs/namei.c
@@ -422,6 +422,7 @@ static struct ntfs_inode *__ntfs_create(const struct mnt_idmap *idmap, struct in
struct ntfs_volume *vol = dir_ni->vol;
struct ntfs_inode *ni;
bool rollback_data = false, rollback_sd = false, rollback_reparse = false;
+ bool rollback_ea = false;
struct file_name_attr *fn = NULL;
struct standard_information *si = NULL;
int err = 0, fn_len, si_len;
@@ -429,6 +430,7 @@ static struct ntfs_inode *__ntfs_create(const struct mnt_idmap *idmap, struct in
struct mft_record *ni_mrec, *dni_mrec;
struct super_block *sb = dir_ni->vol->sb;
struct inode *rollback_data_vi = NULL, *rollback_sd_vi = NULL;
+ struct inode *rollback_ea_vi = NULL, *rollback_eai_vi = NULL;
struct inode *rollback_rp_vi = NULL, *rollback_al_vi = NULL;
__le64 parent_mft_ref;
u64 child_mft_ref;
@@ -470,19 +472,6 @@ static struct ntfs_inode *__ntfs_create(const struct mnt_idmap *idmap, struct in

mode = vi->i_mode;

-#ifdef CONFIG_NTFS_FS_POSIX_ACL
- if (!S_ISLNK(mode) && (sb->s_flags & SB_POSIXACL)) {
- err = ntfs_init_acl(idmap, vi, dir);
- if (err) {
- iput(vi);
- return ERR_PTR(err);
- }
- } else
-#endif
- {
- vi->i_flags |= S_NOSEC;
- }
-
if (uid_valid(vol->uid))
vi->i_uid = vol->uid;

@@ -647,6 +636,24 @@ static struct ntfs_inode *__ntfs_create(const struct mnt_idmap *idmap, struct in
goto err_out;
}

+ /* ACL EAs need the allocated MFT record and initialized attributes. */
+ rollback_ea = true;
+#ifdef CONFIG_NTFS_FS_POSIX_ACL
+ if (!S_ISLNK(mode) && (sb->s_flags & SB_POSIXACL)) {
+ /* The ACL helpers acquire both the parent's and child's locks. */
+ mutex_unlock(&dir_ni->mrec_lock);
+ mutex_unlock(&ni->mrec_lock);
+ err = ntfs_init_acl(idmap, vi, dir);
+ mutex_lock_nested(&ni->mrec_lock, NTFS_INODE_MUTEX_NORMAL);
+ mutex_lock_nested(&dir_ni->mrec_lock, NTFS_INODE_MUTEX_PARENT);
+ if (err)
+ goto err_out;
+ mode = vi->i_mode;
+ }
+#endif
+ if (S_ISLNK(mode) || !(sb->s_flags & SB_POSIXACL))
+ vi->i_flags |= S_NOSEC;
+
err = ntfs_ea_set_wsl_inode(vi, dev, &ea_size,
NTFS_EA_UID | NTFS_EA_GID | NTFS_EA_MODE);
if (err)
@@ -680,7 +687,8 @@ static struct ntfs_inode *__ntfs_create(const struct mnt_idmap *idmap, struct in
if (NVolHideDotFiles(vol) && name_len > 0 && name[0] == cpu_to_le16('.'))
fn->file_attributes |= FILE_ATTR_HIDDEN;
fn->creation_time = fn->last_data_change_time = utc2ntfs(ni->i_crtime);
- fn->last_mft_change_time = fn->last_access_time = fn->creation_time;
+ fn->last_mft_change_time = utc2ntfs(inode_get_ctime(vi));
+ fn->last_access_time = fn->creation_time;
memcpy(fn->file_name, name, name_len * sizeof(__le16));

/* Add FILE_NAME attribute to inode. */
@@ -721,6 +729,15 @@ static struct ntfs_inode *__ntfs_create(const struct mnt_idmap *idmap, struct in
return ni;

err_out:
+ if (rollback_ea) {
+ if (ntfs_attr_exist(ni, AT_EA, AT_UNNAMED, 0) &&
+ ntfs_attr_remove(ni, AT_EA, AT_UNNAMED, 0, &rollback_ea_vi))
+ ntfs_error(sb, "Failed to roll back EA attribute.");
+ if (ntfs_attr_exist(ni, AT_EA_INFORMATION, AT_UNNAMED, 0) &&
+ ntfs_attr_remove(ni, AT_EA_INFORMATION, AT_UNNAMED, 0,
+ &rollback_eai_vi))
+ ntfs_error(sb, "Failed to roll back EA_INFORMATION attribute.");
+ }
if (rollback_sd) {
int rollback_err;

@@ -776,6 +793,10 @@ static struct ntfs_inode *__ntfs_create(const struct mnt_idmap *idmap, struct in
mutex_unlock(&dir_ni->mrec_lock);
mutex_unlock(&ni->mrec_lock);

+ if (rollback_ea_vi)
+ iput(rollback_ea_vi);
+ if (rollback_eai_vi)
+ iput(rollback_eai_vi);
if (rollback_al_vi)
iput(rollback_al_vi);
if (rollback_rp_vi)