[PATCH] fs/ntfs3: fix oob in mi_enum_attr

From: Lizhi Xu
Date: Thu Feb 01 2024 - 22:34:07 EST


When the value of attr->size is too large, it can cause overflow when taking
the next attr. Here, off is used to determine the offset first to avoid problems.

Reported-and-tested-by: syzbot+a426cde6dee8c2884b0b@xxxxxxxxxxxxxxxxxxxxxxxxx
Signed-off-by: Lizhi Xu <lizhi.xu@xxxxxxxxxxxxx>
---
fs/ntfs3/record.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/ntfs3/record.c b/fs/ntfs3/record.c
index 53629b1f65e9..a435df98c2b1 100644
--- a/fs/ntfs3/record.c
+++ b/fs/ntfs3/record.c
@@ -243,14 +243,14 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)
off += asize;
}

- asize = le32_to_cpu(attr->size);
-
/* Can we use the first field (attr->type). */
if (off + 8 > used) {
static_assert(ALIGN(sizeof(enum ATTR_TYPE), 8) == 8);
return NULL;
}

+ asize = le32_to_cpu(attr->size);
+
if (attr->type == ATTR_END) {
/* End of enumeration. */
return NULL;
--
2.43.0