]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ntfs: not change 0-byte $DATA attribute to non-resident
authorHyunchul Lee <hyc.lee@gmail.com>
Thu, 28 May 2026 02:15:35 +0000 (11:15 +0900)
committerNamjae Jeon <linkinjeon@kernel.org>
Fri, 5 Jun 2026 15:20:15 +0000 (00:20 +0900)
When ntfs_resident_attr_resize() cannot grow a resident attribute in
place, it retries after converting other resident attributes to
non-resident to free space in the MFT recrord.

Do not select zero-length resident $DATA attributes for this conversion.
fsck treats 0-byte non-resident $DATA attribute as corruptions.

Cc: stable@vger.kernel.org # v7.1
Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
fs/ntfs/attrib.c

index 9d676375f25cb0fc14a9eac656d4388cca2b9f5c..2872b4ce183512537b0f6aac209ef4c10f8fdaa8 100644 (file)
@@ -4537,10 +4537,12 @@ attr_resize_again:
        while (!(err = ntfs_attr_lookup(AT_UNUSED, NULL, 0, 0, 0, NULL, 0, ctx))) {
                struct inode *tvi;
                struct attr_record *a;
+               u32 value_len;
 
                a = ctx->attr;
                if (a->non_resident || a->type == AT_ATTRIBUTE_LIST)
                        continue;
+               value_len = le32_to_cpu(a->data.resident.value_length);
 
                if (ntfs_attr_can_be_non_resident(vol, a->type))
                        continue;
@@ -4552,6 +4554,8 @@ attr_resize_again:
                if (le32_to_cpu(a->length) <= (sizeof(struct attr_record) - sizeof(s64)) +
                                ((a->name_length * sizeof(__le16) + 7) & ~7) + 8)
                        continue;
+               if (a->type == AT_DATA && !value_len)
+                       continue;
 
                if (a->type == AT_DATA)
                        tvi = ntfs_iget(sb, base_ni->mft_no);
@@ -4564,8 +4568,7 @@ attr_resize_again:
                        continue;
                }
 
-               if (ntfs_attr_make_non_resident(NTFS_I(tvi),
-                   le32_to_cpu(ctx->attr->data.resident.value_length))) {
+               if (ntfs_attr_make_non_resident(NTFS_I(tvi), value_len)) {
                        iput(tvi);
                        continue;
                }