Re: [PATCH v5 11/31] ntfs: handle source record removal failure during attribute moves

From: Xuewen Wang

Date: Mon Nov 09 2026 - 22:30:22 EST




在 2026/11/9 10:31, Hyunchul Lee 写道:
On Mon, Nov 02, 2026 at 03:35:12PM +0800, Xuewen Wang wrote:
From: Xuewen Wang <wangxuewen@xxxxxxxxxx>

ntfs_attr_record_move_to() ignores failure to remove the source attribute
after copying it. It can update the attribute-list reference and report
success with both copies present.

Check removal before changing the list entry. On failure, attempt to
remove the destination copy, mark its record dirty and unmap it, leaving
the list pointing to the source. Report destination cleanup failure
separately.

Shrinking a record to zero needs no extra space, so failure indicates
inconsistent record accounting. Return and report EFSCORRUPTED even if
cleanup also fails.

Fixes: 495e90fa3348 ("ntfs: update attrib operations")

This patch has the Fixes tag, but it calls
ntfs_report_file_metadata_error(), which is introduced in patch 3.
If this patch is backported to a stable tree with patch 3, it could fail
to build.

Hi Hyunchul,

Thank you for your review. You are right about the dependency.

Would it make sense to reorganize the series so that the bug-fix patches come first and use the existing error-handling mechanisms, without depending on the new reporting helpers?

I would then add calls to the new helpers at those sites in a separate patch at the end of the series.

Would this approach work for you?

Thanks,
Xuewen
Signed-off-by: Xuewen Wang <wangxuewen@xxxxxxxxxx>
---
fs/ntfs/attrib.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c
index 5af8ac41af17..f1c99e0d8dca 100644
--- a/fs/ntfs/attrib.c
+++ b/fs/ntfs/attrib.c
@@ -3578,7 +3578,17 @@ int ntfs_attr_record_move_to(struct ntfs_attr_search_ctx *ctx, struct ntfs_inode
nctx->attr->instance = nctx->mrec->next_attr_instance;
nctx->mrec->next_attr_instance =
cpu_to_le16((le16_to_cpu(nctx->mrec->next_attr_instance) + 1) & 0xffff);
- ntfs_attr_record_resize(ctx->mrec, a, 0);
+ err = ntfs_attr_record_resize(ctx->mrec, a, 0);
+ if (err) {
+ err = -EFSCORRUPTED;
+ ntfs_report_file_metadata_error(VFS_I(ni), -EFSCORRUPTED);
+ if (ntfs_attr_record_resize(ni_mrec, nctx->attr, 0))
+ ntfs_report_file_metadata_error(VFS_I(ni),
+ -EFSCORRUPTED);
+ mark_mft_record_dirty(ni);
+ unmap_mft_record(ni);
+ goto put_err_out;
+ }
mark_mft_record_dirty(ctx->ntfs_ino);
mark_mft_record_dirty(ni);