Re: [PATCH] ext4: validate in-inode xattrs before listing

From: Jan Kara

Date: Wed Nov 18 2026 - 07:42:32 EST


On Tue 17-11-26 17:01:47, Haoli Zhang wrote:
> 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@xxxxxxxxxxxxxxxxxxxxxxxxx
> Closes: https://syzbot.org/bug?extid=3fbf2337de43f5581aec
> Co-developed-by: Jinning Zhang <25031212117@xxxxxxxxxxxxxxxxx>
> Signed-off-by: Jinning Zhang <25031212117@xxxxxxxxxxxxxxxxx>
> Co-developed-by: Bin Yu <byu@xxxxxxxxxxxxx>
> Signed-off-by: Bin Yu <byu@xxxxxxxxxxxxx>
> Signed-off-by: Haoli Zhang <26031212468@xxxxxxxxxxxxxxxxx>

So it is an interesting observation that although in-inode xattrs were
verified during iget(), the bh backing the inode can be evicted from memory
after iget() and reread from disk (with possibly new content if someone is
corrupting underlying storage). The problem isn't really very serious but
it would be kind of nice to fix. However there are many places that use
in-inode xattr space without verifying it, not just ext4_listxattr(), and
verifying in all of them will get expensive and likely cause performance
regression and in practice, the bh is very rarely reread from the disk.

I've been thinking for a while about possible fixes but either they get
complex, cost quite some memory, or cost runtime performance so for now I'm
inclined to declare such type of malicious media not really worth fixing.

Honza

> ---
> 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;
> }
>
--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR