<div dir="ltr"><p>Hi Gao Xiang,</p>
<p>Thanks for the review. I just sent v3 which uses the multiplication form as you suggested.</p>
<p>Best regards,
Utkal Singh</p></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Tue, 17 Mar 2026 at 17:00, Gao Xiang <<a href="mailto:hsiangkao@linux.alibaba.com">hsiangkao@linux.alibaba.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
On 2026/3/17 19:17, Utkal Singh wrote:<br>
> erofs_init_inode_xattrs() reads h_shared_count from the on-disk xattr<br>
> ibody header and uses it to size a malloc and drive a loop that reads<br>
> shared xattr IDs. If h_shared_count exceeds the space available<br>
> within xattr_isize, the loop reads past the intended ibody region<br>
> and the malloc is oversized.<br>
> <br>
> Validate that h_shared_count does not exceed the number of __le32<br>
> entries that fit after the ibody header. Return -EFSCORRUPTED with<br>
> a diagnostic message on failure.<br>
> <br>
> Reproducer:<br>
> mkdir testdir && echo hello > testdir/a.txt<br>
> setfattr -n user.test -v val testdir/a.txt<br>
> mkfs.erofs test.img testdir<br>
> # corrupt h_shared_count (offset = nid*32 + inode_size + 4) to 0xFF<br>
> # then: fsck.erofs --extract=/tmp/out --xattrs test_corrupted.img<br>
> # Without patch: silently processes invalid shared xattr IDs<br>
> # With patch: returns -EFSCORRUPTED<br>
> <br>
> Signed-off-by: Utkal Singh <<a href="mailto:singhutkal015@gmail.com" target="_blank">singhutkal015@gmail.com</a>><br>
> ---<br>
> lib/xattr.c | 8 ++++++++<br>
> 1 file changed, 8 insertions(+)<br>
> <br>
> diff --git a/lib/xattr.c b/lib/xattr.c<br>
> index 565070a..5888602 100644<br>
> --- a/lib/xattr.c<br>
> +++ b/lib/xattr.c<br>
> @@ -1182,6 +1182,14 @@ static int erofs_init_inode_xattrs(struct erofs_inode *vi)<br>
> <br>
> ih = it.kaddr;<br>
> vi->xattr_shared_count = ih->h_shared_count;<br>
> + if (vi->xattr_shared_count ><br>
> + (vi->xattr_isize - sizeof(struct erofs_xattr_ibody_header)) /<br>
> + sizeof(__le32)) {<br>
> + erofs_err("invalid h_shared_count %u in nid %llu",<br>
> + vi->xattr_shared_count, vi->nid | 0ULL);<br>
> + erofs_put_metabuf(&it.buf);<br>
> + return -EFSCORRUPTED;<br>
> + }<br>
<br>
Again, why not `vi->xattr_shared_count * sizeof(__le32) ><br>
vi->xattr_isize - sizeof(struct erofs_xattr_ibody_header)`?<br>
<br>
Thanks,<br>
Gao Xiang<br>
</blockquote></div>