From: DaeMyung Kang <charsyam@gmail.com>
To: Namjae Jeon <linkinjeon@kernel.org>, Hyunchul Lee <hyc.lee@gmail.com>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
DaeMyung Kang <charsyam@gmail.com>
Subject: [PATCH 2/2] ntfs: validate resident file name attribute length
Date: Sun, 24 May 2026 14:42:38 +0900 [thread overview]
Message-ID: <20260524054238.3129288-3-charsyam@gmail.com> (raw)
In-Reply-To: <20260524054238.3129288-1-charsyam@gmail.com>
ntfs_attr_find() and ntfs_external_attr_find() check that generic
resident attribute values fit in their attribute records and that
fixed-size resident values are large enough. For $FILE_NAME, however,
the fixed part is not enough: the value also contains a variable-length
UTF-16 name whose length is stored in file_name_length.
A crafted image can set a small resident value_length while leaving
file_name_length large. Callers then trust file_name_length and read
past the resident value when converting or comparing the name. This was
reproduced with a crafted image under KASAN as a slab-out-of-bounds read
from the kmalloc-1k MFT record copy, for example through:
ntfs_lookup()
ntfs_iget()
ntfs_read_locked_inode()
ntfs_attr_name_get()
ntfs_ucstonls()
utf16s_to_utf8s()
Validate $FILE_NAME before lookup can return the current attribute,
including the AT_UNUSED enumeration case where callers inspect returned
attributes directly. Reuse the same self-contained helper for both the
base-record lookup path and the attribute-list lookup path. Log a
specific corruption message at the rejection point, matching the
existing attribute-name validation in ntfs_attr_find().
Reject non-resident $FILE_NAME records too: the format requires
$FILE_NAME to be resident and callers treat returned records as
resident.
Fixes: 6ceb4cc81ef3 ("ntfs: add bound checking to ntfs_attr_find")
Signed-off-by: DaeMyung Kang <charsyam@gmail.com>
---
fs/ntfs/attrib.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c
index 421c6cdcbb53..5643a097eb11 100644
--- a/fs/ntfs/attrib.c
+++ b/fs/ntfs/attrib.c
@@ -595,6 +595,37 @@ static u32 ntfs_resident_attr_min_value_length(const __le32 type)
}
}
+static bool ntfs_file_name_attr_is_valid(const struct attr_record *a)
+{
+ const struct file_name_attr *fn;
+ u32 attr_len = le32_to_cpu(a->length);
+ u32 value_length;
+ u16 value_offset;
+ u32 file_name_size;
+
+ if (a->non_resident)
+ return false;
+
+ if (attr_len < offsetof(struct attr_record, data.resident.reserved) +
+ sizeof(a->data.resident.reserved))
+ return false;
+
+ value_length = le32_to_cpu(a->data.resident.value_length);
+ value_offset = le16_to_cpu(a->data.resident.value_offset);
+
+ if (value_length > attr_len || value_offset > attr_len - value_length)
+ return false;
+
+ if (value_length < ntfs_resident_attr_min_value_length(AT_FILE_NAME))
+ return false;
+
+ fn = (const struct file_name_attr *)((const u8 *)a + value_offset);
+ file_name_size = fn->file_name_length * sizeof(__le16);
+
+ return file_name_size <=
+ value_length - offsetof(struct file_name_attr, file_name);
+}
+
/*
* ntfs_attr_find - find (next) attribute in mft record
* @type: attribute type to find
@@ -705,6 +736,13 @@ static int ntfs_attr_find(const __le32 type, const __le16 *name,
}
}
+ if (a->type == AT_FILE_NAME &&
+ !ntfs_file_name_attr_is_valid(a)) {
+ ntfs_error(vol->sb,
+ "Corrupt $FILE_NAME attribute in MFT record %llu\n",
+ ctx->ntfs_ino->mft_no);
+ break;
+ }
if (type == AT_UNUSED)
return 0;
if (a->type != type)
@@ -1252,6 +1290,14 @@ static int ntfs_external_attr_find(const __le32 type,
ctx->attr = a;
+ if (a->type == AT_FILE_NAME &&
+ !ntfs_file_name_attr_is_valid(a)) {
+ ntfs_error(vol->sb,
+ "Corrupt $FILE_NAME attribute in MFT record %llu\n",
+ ctx->ntfs_ino->mft_no);
+ break;
+ }
+
if (a->non_resident) {
u32 min_len;
u16 mp_offset;
--
2.43.0
next prev parent reply other threads:[~2026-05-24 5:42 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-24 5:42 [PATCH 0/2] ntfs: fix link name free and $FILE_NAME validation DaeMyung Kang
2026-05-24 5:42 ` [PATCH 1/2] ntfs: free link name from ntfs_name_cache DaeMyung Kang
2026-05-25 12:51 ` Namjae Jeon
2026-05-24 5:42 ` DaeMyung Kang [this message]
2026-05-25 6:38 ` [PATCH 2/2] ntfs: validate resident file name attribute length Namjae Jeon
2026-05-25 16:32 ` [PATCH v2] ntfs: validate resident attribute values on lookup DaeMyung Kang
2026-05-26 0:08 ` Namjae Jeon
2026-05-26 1:05 ` CharSyam
2026-05-26 13:31 ` [PATCH v3] " DaeMyung Kang
2026-05-27 23:48 ` Namjae Jeon
2026-05-28 5:56 ` Hyunchul Lee
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260524054238.3129288-3-charsyam@gmail.com \
--to=charsyam@gmail.com \
--cc=hyc.lee@gmail.com \
--cc=linkinjeon@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®