Skip to content

Commit a8f659c

Browse files
fs/ntfs3: Add more checks in mi_enum_attr (part 2)
Add offset check before access to attr->non_res field as mentioned in [1]. [1] https://lore.kernel.org/ntfs3/20241010110005.42792-1-llfamsec@gmail.com/ Suggested-by: lei lu <llfamsec@gmail.com> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
1 parent 045fff6 commit a8f659c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

fs/ntfs3/record.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)
212212
return NULL;
213213

214214
if (off >= used || off < MFTRECORD_FIXUP_OFFSET_1 ||
215-
!IS_ALIGNED(off, 4)) {
215+
!IS_ALIGNED(off, 8)) {
216216
return NULL;
217217
}
218218

@@ -236,8 +236,11 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)
236236
off += asize;
237237
}
238238

239-
/* Can we use the first field (attr->type). */
240-
/* NOTE: this code also checks attr->size availability. */
239+
/*
240+
* Can we use the first fields:
241+
* attr->type,
242+
* attr->size
243+
*/
241244
if (off + 8 > used) {
242245
static_assert(ALIGN(sizeof(enum ATTR_TYPE), 8) == 8);
243246
return NULL;
@@ -259,10 +262,17 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)
259262

260263
asize = le32_to_cpu(attr->size);
261264

265+
if (!IS_ALIGNED(asize, 8))
266+
return NULL;
267+
262268
/* Check overflow and boundary. */
263269
if (off + asize < off || off + asize > used)
264270
return NULL;
265271

272+
/* Can we use the field attr->non_res. */
273+
if (off + 9 > used)
274+
return NULL;
275+
266276
/* Check size of attribute. */
267277
if (!attr->non_res) {
268278
/* Check resident fields. */

0 commit comments

Comments
 (0)