ext4_iget() validates in-inode xattrs when it reads an inode. However, ext4_xattr_ibody_list() fetches the inode-table data again with ext4_get_inode_loc() and passes the entries to ext4_xattr_list_entries() without validating this read. If the re-read data contains a malformed xattr entry, the listing loop can advance beyond the valid in-inode xattr area and read invalid memory. Validate the in-inode xattrs from this read with xattr_check_inode() before listing them. If validation fails, skip the listing and return the error after releasing the inode-table buffer. Reported-by: syzbot+3fbf2337de43f5581aec@syzkaller.appspotmail.com Closes: https://syzbot.org/bug?extid=3fbf2337de43f5581aec Co-developed-by: Jinning Zhang <25031212117@stu.xidian.edu.cn> Signed-off-by: Jinning Zhang <25031212117@stu.xidian.edu.cn> Co-developed-by: Bin Yu Signed-off-by: Bin Yu Signed-off-by: Haoli Zhang <26031212468@stu.xidian.edu.cn> --- fs/ext4/xattr.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -790,9 +790,11 @@ return error; raw_inode = ext4_raw_inode(&iloc); header = IHDR(inode, raw_inode); - error = ext4_xattr_list_entries(dentry, IFIRST(header), - buffer, buffer_size); + error = xattr_check_inode(inode, header, ITAIL(inode, raw_inode)); + if (!error) + error = ext4_xattr_list_entries(dentry, IFIRST(header), + buffer, buffer_size); brelse(iloc.bh); return error; }