From: Gao Xiang <hsiangkao@linux.alibaba.com>
To: Utkal Singh <singhutkal015@gmail.com>, linux-erofs@lists.ozlabs.org
Cc: xiang@kernel.org, yifan.yfzhao@gmail.com
Subject: Re: [PATCH] erofs-utils: lib: validate h_shared_count in erofs_init_inode_xattrs()
Date: Tue, 17 Mar 2026 19:30:04 +0800 [thread overview]
Message-ID: <e8729997-91ca-4bf0-bb52-78eec7fc7f2f@linux.alibaba.com> (raw)
In-Reply-To: <20260317111743.84988-1-singhutkal015@gmail.com>
On 2026/3/17 19:17, Utkal Singh wrote:
> erofs_init_inode_xattrs() reads h_shared_count from the on-disk xattr
> ibody header and uses it to size a malloc and drive a loop that reads
> shared xattr IDs. If h_shared_count exceeds the space available
> within xattr_isize, the loop reads past the intended ibody region
> and the malloc is oversized.
>
> Validate that h_shared_count does not exceed the number of __le32
> entries that fit after the ibody header. Return -EFSCORRUPTED with
> a diagnostic message on failure.
>
> Reproducer:
> mkdir testdir && echo hello > testdir/a.txt
> setfattr -n user.test -v val testdir/a.txt
> mkfs.erofs test.img testdir
> # corrupt h_shared_count (offset = nid*32 + inode_size + 4) to 0xFF
> # then: fsck.erofs --extract=/tmp/out --xattrs test_corrupted.img
> # Without patch: silently processes invalid shared xattr IDs
> # With patch: returns -EFSCORRUPTED
>
> Signed-off-by: Utkal Singh <singhutkal015@gmail.com>
> ---
> lib/xattr.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/lib/xattr.c b/lib/xattr.c
> index 565070a..5888602 100644
> --- a/lib/xattr.c
> +++ b/lib/xattr.c
> @@ -1182,6 +1182,14 @@ static int erofs_init_inode_xattrs(struct erofs_inode *vi)
>
> ih = it.kaddr;
> vi->xattr_shared_count = ih->h_shared_count;
> + if (vi->xattr_shared_count >
> + (vi->xattr_isize - sizeof(struct erofs_xattr_ibody_header)) /
> + sizeof(__le32)) {
> + erofs_err("invalid h_shared_count %u in nid %llu",
> + vi->xattr_shared_count, vi->nid | 0ULL);
> + erofs_put_metabuf(&it.buf);
> + return -EFSCORRUPTED;
> + }
Again, why not `vi->xattr_shared_count * sizeof(__le32) >
vi->xattr_isize - sizeof(struct erofs_xattr_ibody_header)`?
Thanks,
Gao Xiang
next prev parent reply other threads:[~2026-03-17 11:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-17 11:17 [PATCH] erofs-utils: lib: validate h_shared_count in erofs_init_inode_xattrs() Utkal Singh
2026-03-17 11:30 ` Gao Xiang [this message]
2026-03-17 11:34 ` Utkal Singh
-- strict thread matches above, loose matches on Subject: below --
2026-03-16 20:19 Utkal Singh
2026-03-17 2:16 ` Gao Xiang
2026-03-17 2:39 ` Gao Xiang
2026-03-17 4:47 ` Utkal Singh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e8729997-91ca-4bf0-bb52-78eec7fc7f2f@linux.alibaba.com \
--to=hsiangkao@linux.alibaba.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=singhutkal015@gmail.com \
--cc=xiang@kernel.org \
--cc=yifan.yfzhao@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox