[PATCH v4 02/12] ntfs: discard attribute inodes after failed initialization
From: Baolin Liu
Date: Sun Nov 15 2026 - 08:26:57 EST
From: Dandan Wu <wudandan@xxxxxxxxxx>
When nonresident attribute initialization fails, ntfs_attr_add() removes
the records but can leave the inode cached with its old runlist and base
inode reference. After creation rollback frees the MFT record, reuse can
find stale attribute state and fail even after space becomes available.
After successful removal, clear the attribute inode's dirty state and
link count and remove it from the inode hash before dropping its
reference.
Fixes: 495e90fa3348 ("ntfs: update attrib operations")
Reviewed-by: Baolin Liu <liubaolin@xxxxxxxxxx>
Signed-off-by: Dandan Wu <wudandan@xxxxxxxxxx>
---
New in v4.
Tested repeated creation with a 3236-byte inherited ACL on full volumes
with 512-byte/4 KiB clusters. After freeing space, regular-file, O_TMPFILE,
directory and FIFO creation succeeded without stale EA state.
fs/ntfs/attrib.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c
index a18d74a9f685..a88dc62c6a4e 100644
--- a/fs/ntfs/attrib.c
+++ b/fs/ntfs/attrib.c
@@ -3039,8 +3039,13 @@ int ntfs_attr_add(struct ntfs_inode *ni, __le32 type,
(val && (ntfs_inode_attr_pwrite(attr_vi, 0, size, val, false) != size))) {
err = -EIO;
ntfs_error(sb, "Failed to initialize just added attribute");
- if (ntfs_attr_rm(attr_ni))
+ if (ntfs_attr_rm(attr_ni)) {
ntfs_error(sb, "Failed to remove just added attribute");
+ } else {
+ NInoClearDirty(attr_ni);
+ clear_nlink(attr_vi);
+ remove_inode_hash(attr_vi);
+ }
iput(attr_vi);
goto err_out;
}