Content-Type: multipart/mixed; boundary="===============7017405302532667438==" MIME-Version: 1.0 From: eadavis@sina.com To: kbuild-all@lists.01.org Subject: [PATCH v4] fs/ntfs3: Fix buffer overflow and integer overflow Date: Mon, 19 Sep 2022 21:32:02 +0800 Message-ID: <20220919133202.308766-1-eadavis@sina.com> In-Reply-To: List-Id: --===============7017405302532667438== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: eadaivs 1) If we call find_ea() if "bytes" less than 8 then the unpacked_ea_size() is an out of bounds read. 2) The *off + unpacked_ea_size() can have an integer overflow. Link: https://syzkaller.appspot.com/bug?extid=3Dc4d950787fd5553287b7 Reported-by: syzbot+c4d950787fd5553287b7(a)syzkaller.appspotmail.com Signed-off-by: eadaivs --- Changes in v4: Separate out the issue with the buffer overflow and the integer overflow. fs/ntfs3/xattr.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/fs/ntfs3/xattr.c b/fs/ntfs3/xattr.c index afd0ddad826f..3cd1a24c7bcc 100644 --- a/fs/ntfs3/xattr.c +++ b/fs/ntfs3/xattr.c @@ -41,17 +41,23 @@ static inline size_t packed_ea_size(const struct EA_FUL= L *ea) * * Assume there is at least one xattr in the list. */ -static inline bool find_ea(const struct EA_FULL *ea_all, u32 bytes, +static inline bool find_ea(const struct EA_FULL *ea_all, size_t bytes, const char *name, u8 name_len, u32 *off) { + const struct EA_FULL *ea; + u32 next_off; *off =3D 0; = - if (!ea_all || !bytes) + if (!ea_all || bytes < sizeof(*ea)) return false; = for (;;) { - const struct EA_FULL *ea =3D Add2Ptr(ea_all, *off); - u32 next_off =3D *off + unpacked_ea_size(ea); + *ea =3D Add2Ptr(ea_all, *off); + + if (sizeof(*ea) + *off > bytes) + return false; + + next_off =3D size_add(*off, unpacked_ea_size(ea)); = if (next_off > bytes) return false; @@ -61,8 +67,6 @@ static inline bool find_ea(const struct EA_FULL *ea_all, = u32 bytes, return true; = *off =3D next_off; - if (next_off >=3D bytes) - return false; } } = -- = 2.37.2 --===============7017405302532667438==--