[SRU][J][PATCH 2/2] fs/ntfs3: Sequential field availability check in mi_enum_attr()
Massimiliano Pellizzer
massimiliano.pellizzer at canonical.com
Thu Jan 23 14:46:38 UTC 2025
From: Konstantin Komarov <almaz.alexandrovich at paragon-software.com>
The code is slightly reformatted to consistently check field availability
without duplication.
Fixes: 556bdf27c2dd ("ntfs3: Add bounds checking to mi_enum_attr()")
Signed-off-by: Konstantin Komarov <almaz.alexandrovich at paragon-software.com>
(backported from commit 090f612756a9720ec18b0b130e28be49839d7cb5)
[mpellizzer: backported considering differences in context due to a
missing commit 013ff63b649475, which adds more attributes checks but
does not affect the patch]
CVE-2024-50248
Signed-off-by: Massimiliano Pellizzer <massimiliano.pellizzer at canonical.com>
---
fs/ntfs3/record.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/fs/ntfs3/record.c b/fs/ntfs3/record.c
index 05d5fb58c9db..7c2c1b42cf9f 100644
--- a/fs/ntfs3/record.c
+++ b/fs/ntfs3/record.c
@@ -228,6 +228,7 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)
}
/* Can we use the first field (attr->type). */
+ /* NOTE: this code also checks attr->size availability. */
if (off + 8 > used) {
static_assert(ALIGN(sizeof(enum ATTR_TYPE), 8) == 8);
return NULL;
@@ -244,10 +245,6 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)
return NULL;
asize = le32_to_cpu(attr->size);
- if (asize < SIZEOF_RESIDENT) {
- /* Impossible 'cause we should not return such attribute. */
- return NULL;
- }
/* Check overflow and boundary. */
if (off + asize < off || off + asize > used)
@@ -276,6 +273,10 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)
}
/* Check some nonresident fields. */
+ /* Can we use memory including attr->nres.valid_size? */
+ if (asize < SIZEOF_NONRESIDENT)
+ return NULL;
+
if (attr->name_len &&
le16_to_cpu(attr->name_off) + sizeof(short) * attr->name_len >
le16_to_cpu(attr->nres.run_off)) {
@@ -283,12 +284,9 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)
}
if (attr->nres.svcn || !is_attr_ext(attr)) {
- if (asize + 8 < SIZEOF_NONRESIDENT)
- return NULL;
-
if (attr->nres.c_unit)
return NULL;
- } else if (asize + 8 < SIZEOF_NONRESIDENT_EX)
+ } else if (asize < SIZEOF_NONRESIDENT_EX)
return NULL;
return attr;
--
2.43.0
More information about the kernel-team
mailing list