From: Utkal Singh <singhutkal015@gmail.com>
To: linux-erofs@lists.ozlabs.org
Cc: xiang@kernel.org, yifan.yfzhao@foxmail.com,
Utkal Singh <singhutkal015@gmail.com>
Subject: [PATCH] fsck.erofs: validate h_shared_count against xattr_isize
Date: Mon, 16 Mar 2026 07:38:12 +0000 [thread overview]
Message-ID: <20260316073812.30470-1-singhutkal015@gmail.com> (raw)
A crafted EROFS image can set h_shared_count to a large value in
the xattr ibody header. erofs_verify_xattr() reads this value
directly without checking if the implied shared entry area fits
within xattr_isize. This causes 'remaining' to underflow below
zero after the shared entry loop, corrupting the subsequent
while(remaining > 0) bounds check.
Validate that xattr_shared_count shared entries fit within the
available xattr body size before entering the loop.
Signed-off-by: Utkal Singh <singhutkal015@gmail.com>
---
fsck/main.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/fsck/main.c b/fsck/main.c
index cf07829..c911aa1 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -374,6 +374,12 @@ static int erofs_verify_xattr(struct erofs_inode *inode)
}
ih = (struct erofs_xattr_ibody_header *)ptr;
xattr_shared_count = ih->h_shared_count;
+ if (xattr_shared_count * xattr_entry_size > remaining - xattr_hdr_size) {
+ erofs_err("h_shared_count %u exceeds xattr_isize @ nid %llu",
+ xattr_shared_count, inode->nid | 0ULL);
+ ret = -EFSCORRUPTED;
+ goto out;
+ }
ofs = erofs_blkoff(sbi, addr) + xattr_hdr_size;
addr += xattr_hdr_size;
--
2.43.0
reply other threads:[~2026-03-16 7:38 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260316073812.30470-1-singhutkal015@gmail.com \
--to=singhutkal015@gmail.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=xiang@kernel.org \
--cc=yifan.yfzhao@foxmail.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