From: Utkal Singh <singhutkal015@gmail.com>
To: linux-erofs@lists.ozlabs.org
Cc: hsiangkao@linux.alibaba.com, Utkal Singh <singhutkal015@gmail.com>
Subject: [PATCH] erofs-utils: lib: validate h_shared_count in erofs_init_inode_xattrs()
Date: Mon, 16 Mar 2026 20:19:19 +0000 [thread overview]
Message-ID: <20260316201919.41839-1-singhutkal015@gmail.com> (raw)
erofs_init_inode_xattrs() reads h_shared_count directly from the on-disk
xattr ibody header and uses it to size a heap allocation and drive a
read loop without checking whether the implied shared xattr array fits
within xattr_isize.
A crafted EROFS image with a large h_shared_count but a minimal
xattr_isize causes the subsequent loop to read shared xattr entries
beyond the xattr ibody boundary, interpreting unrelated on-disk data
as shared xattr IDs. This affects every library consumer -- dump.erofs,
erofsfuse, and the rebuild path (lib/rebuild.c) -- none of which call
the fsck-only erofs_verify_xattr() before reaching this code.
Validate that h_shared_count fits within the available xattr body space
before allocating or reading. Use a division-based check to avoid any
theoretical overflow in the multiplication.
The subtraction is safe because callers above already reject
xattr_isize < sizeof(struct erofs_xattr_ibody_header).
Signed-off-by: Utkal Singh <singhutkal015@gmail.com>
---
lib/xattr.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/lib/xattr.c b/lib/xattr.c
index 565070a..6891812 100644
--- a/lib/xattr.c
+++ b/lib/xattr.c
@@ -1182,6 +1182,16 @@ static int erofs_init_inode_xattrs(struct erofs_inode *vi)
ih = it.kaddr;
vi->xattr_shared_count = ih->h_shared_count;
+ /* validate h_shared_count fits within xattr_isize */
+ if (vi->xattr_shared_count >
+ (vi->xattr_isize - sizeof(struct erofs_xattr_ibody_header)) /
+ sizeof(u32)) {
+ erofs_err("bogus h_shared_count %u (xattr_isize %u) @ nid %llu",
+ vi->xattr_shared_count, vi->xattr_isize,
+ vi->nid | 0ULL);
+ erofs_put_metabuf(&it.buf);
+ return -EFSCORRUPTED;
+ }
vi->xattr_shared_xattrs = malloc(vi->xattr_shared_count * sizeof(uint));
if (!vi->xattr_shared_xattrs) {
erofs_put_metabuf(&it.buf);
--
2.43.0
next reply other threads:[~2026-03-16 20:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-16 20:19 Utkal Singh [this message]
2026-03-17 2:16 ` [PATCH] erofs-utils: lib: validate h_shared_count in erofs_init_inode_xattrs() Gao Xiang
2026-03-17 2:39 ` Gao Xiang
2026-03-17 4:47 ` Utkal Singh
-- strict thread matches above, loose matches on Subject: below --
2026-03-17 11:17 Utkal Singh
2026-03-17 11:30 ` Gao Xiang
2026-03-17 11:34 ` 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=20260316201919.41839-1-singhutkal015@gmail.com \
--to=singhutkal015@gmail.com \
--cc=hsiangkao@linux.alibaba.com \
--cc=linux-erofs@lists.ozlabs.org \
/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