From: Shirong Zhao <shxzhaosr@163.com>
To: almaz.alexandrovich@paragon-software.com
Cc: ntfs3@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH] fs/ntfs3: validate INDEX_ROOT size before reading its fields
Date: Wed, 28 Oct 2026 10:44:43 +0800 [thread overview]
Message-ID: <20261028024443.25-1-shxzhaosr@163.com> (raw)
check_index_root() reads root->index_block_size and
root->index_block_clst before checking that the resident data is
large enough. check_attr() accepts a resident attribute with
data_size == 0 and data_off == asize, and mi->mrec is exactly
record_size bytes, so a crafted $LogFile record can make the
first read go past the end of the allocation.
Use resident_data_ex() so the attribute is validated before the
fields are read.
Signed-off-by: Shirong Zhao <shxzhaosr@163.com>
---
fs/ntfs3/fslog.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/fs/ntfs3/fslog.c b/fs/ntfs3/fslog.c
index 2460a4a..e208f4c 100644
--- a/fs/ntfs3/fslog.c
+++ b/fs/ntfs3/fslog.c
@@ -2721,15 +2721,21 @@ static inline bool check_index_root(const struct ATTRIB *attr,
struct ntfs_sb_info *sbi)
{
bool ret;
- const struct INDEX_ROOT *root = resident_data(attr);
- u8 index_bits = le32_to_cpu(root->index_block_size) >=
+ const struct INDEX_ROOT *root;
+ u8 index_bits;
+ u8 block_clst;
+
+ root = resident_data_ex(attr, sizeof(struct INDEX_ROOT));
+ if (!root)
+ return false;
+
+ index_bits = le32_to_cpu(root->index_block_size) >=
sbi->cluster_size ?
sbi->cluster_bits :
SECTOR_SHIFT;
- u8 block_clst = root->index_block_clst;
+ block_clst = root->index_block_clst;
- if (le32_to_cpu(attr->res.data_size) < sizeof(struct INDEX_ROOT) ||
- (root->type != ATTR_NAME && root->type != ATTR_ZERO) ||
+ if ((root->type != ATTR_NAME && root->type != ATTR_ZERO) ||
(root->type == ATTR_NAME &&
root->rule != NTFS_COLLATION_TYPE_FILENAME) ||
(le32_to_cpu(root->index_block_size) !=
--
2.53.0
reply other threads:[~2026-10-28 2:45 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261028024443.25-1-shxzhaosr@163.com \
--to=shxzhaosr@163.com \
--cc=almaz.alexandrovich@paragon-software.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ntfs3@lists.linux.dev \
/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®