From: lei lu <llfamsec@gmail.com>
To: almaz.alexandrovich@paragon-software.com, ntfs3@lists.linux.dev
Cc: lei lu <llfamsec@gmail.com>
Subject: [PATCH] ntfs3: Add a check for attr_names and oatbl
Date: Wed, 29 May 2024 04:09:00 +0800 [thread overview]
Message-ID: <20240528200900.17980-1-llfamsec@gmail.com> (raw)
This patch fixes two issues. First, if ane->off is a large offset,
it will trigger out-of-bound write on oe. Second, if ane->name_bytes
is too large, it will trigger out-of-bound read on the next ane. We
also should add a check before visiting the fixed members of ane and oe.
Signed-off-by: lei lu <llfamsec@gmail.com>
---
fs/ntfs3/fslog.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/fs/ntfs3/fslog.c b/fs/ntfs3/fslog.c
index 855519713bf7..5f7c8bdbb69a 100644
--- a/fs/ntfs3/fslog.c
+++ b/fs/ntfs3/fslog.c
@@ -3740,6 +3740,7 @@ int log_replay(struct ntfs_inode *ni, bool *initialized)
u32 i, bytes_per_attr_entry;
u32 vbo, tail, off, dlen;
u32 saved_len, rec_len, transact_id;
+ u32 attr_names_len, oatbl_len;
bool use_second_page;
struct RESTART_AREA *ra2, *ra = NULL;
struct CLIENT_REC *ca, *cr;
@@ -4246,6 +4247,7 @@ int log_replay(struct ntfs_inode *ni, bool *initialized)
err = -ENOMEM;
goto out;
}
+ attr_names_len = rec_len;
lcb_put(lcb);
lcb = NULL;
@@ -4285,6 +4287,7 @@ int log_replay(struct ntfs_inode *ni, bool *initialized)
err = -ENOMEM;
goto out;
}
+ oatbl_len = t32;
log->open_attr_tbl = oatbl;
@@ -4315,15 +4318,30 @@ int log_replay(struct ntfs_inode *ni, bool *initialized)
check_attribute_names2:
if (rst->attr_names_len && oatbl) {
struct ATTR_NAME_ENTRY *ane = attr_names;
+ struct ATTR_NAME_ENTRY *attr_names_end =
+ (struct ATTR_NAME_ENTRY *)Add2Ptr(attr_names, attr_name_len);
+ struct OPEN_ATTR_ENTRY *oatbl_end =
+ (struct OPEN_ATTR_ENTRY *)Add2Ptr(oatbl, oatbl_len);
while (ane->off) {
/* TODO: Clear table on exit! */
oe = Add2Ptr(oatbl, le16_to_cpu(ane->off));
+ if (oe + 1 > oatbl_end) {
+ err = -EINVAL;
+ goto out;
+ }
+
t16 = le16_to_cpu(ane->name_bytes);
oe->name_len = t16 / sizeof(short);
oe->ptr = ane->name;
oe->is_attr_name = 2;
+
ane = Add2Ptr(ane,
sizeof(struct ATTR_NAME_ENTRY) + t16);
+ if (ane > attr_names_end ||
+ ane + 1 > attr_names_end) {
+ err = -EINVAL;
+ goto out;
+ }
}
}
--
2.34.1
next reply other threads:[~2024-05-28 20:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-28 20:09 lei lu [this message]
2024-05-29 1:53 ` [PATCH] ntfs3: Add a check for attr_names and oatbl kernel test robot
2024-05-29 1:53 ` kernel test robot
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=20240528200900.17980-1-llfamsec@gmail.com \
--to=llfamsec@gmail.com \
--cc=almaz.alexandrovich@paragon-software.com \
--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