From: Utkal Singh <singhutkal015@gmail.com>
To: hsiangkao@linux.alibaba.com
Cc: linux-erofs@lists.ozlabs.org, Utkal Singh <singhutkal015@gmail.com>
Subject: [PATCH] erofs-utils: lib: validate algorithm format before use in z_erofs_map_blocks_ext
Date: Sun, 15 Mar 2026 07:28:06 +0000 [thread overview]
Message-ID: <20260315072806.17504-1-singhutkal015@gmail.com> (raw)
The fmt field read from the on-disk extent is used directly as an index
without bounds checking. A crafted image could set fmt to a value
exceeding Z_EROFS_COMPRESSION_MAX, causing out-of-bounds access.
Add a bounds check before using fmt-1 as algorithm format index,
returning -EOPNOTSUPP for unknown algorithm formats.
Signed-off-by: Utkal Singh <singhutkal015@gmail.com>
---
lib/zmap.c | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/lib/zmap.c b/lib/zmap.c
index 0e7af4e..ac5daca 100644
--- a/lib/zmap.c
+++ b/lib/zmap.c
@@ -630,8 +630,14 @@ static int z_erofs_map_blocks_ext(struct erofs_inode *vi,
if (map->m_plen & Z_EROFS_EXTENT_PLEN_PARTIAL)
map->m_flags |= EROFS_MAP_PARTIAL_REF;
map->m_plen &= Z_EROFS_EXTENT_PLEN_MASK;
- if (fmt)
+ if (fmt) {
+ if (fmt - 1 >= Z_EROFS_COMPRESSION_MAX) {
+ erofs_err("unknown algorithm format %u for encoded extent, nid %llu",
+ fmt - 1, vi->nid | 0ULL);
+ return -EOPNOTSUPP;
+ }
map->m_algorithmformat = fmt - 1;
+ }
else if (interlaced && !((map->m_pa | map->m_plen) & bmask))
map->m_algorithmformat =
Z_EROFS_COMPRESSION_INTERLACED;
@@ -738,10 +744,18 @@ int z_erofs_map_blocks_iter(struct erofs_inode *vi,
else
err = z_erofs_map_blocks_fo(vi, map, flags);
}
- if (!err && (map->m_flags & EROFS_MAP_ENCODED) &&
- __erofs_unlikely(map->m_plen > Z_EROFS_PCLUSTER_MAX_SIZE ||
- map->m_llen > Z_EROFS_PCLUSTER_MAX_DSIZE))
- err = -EOPNOTSUPP;
+ if (!err && (map->m_flags & EROFS_MAP_ENCODED)) {
+ if (__erofs_unlikely(map->m_plen >
+ Z_EROFS_PCLUSTER_MAX_SIZE ||
+ map->m_llen > Z_EROFS_PCLUSTER_MAX_DSIZE)) {
+ err = -EOPNOTSUPP;
+ } else if (map->m_pa && map->m_plen &&
+ map->m_pa + map->m_plen < map->m_pa) {
+ erofs_err("bogus physical extent: pa %" PRIu64 " plen %" PRIu64,
+ map->m_pa, map->m_plen);
+ err = -EFSCORRUPTED;
+ }
+ }
if (err)
map->m_llen = 0;
}
--
2.43.0
next reply other threads:[~2026-03-15 7:28 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-15 7:28 Utkal Singh [this message]
2026-03-15 10:39 ` [PATCH] erofs-utils: lib: validate algorithm format before use in z_erofs_map_blocks_ext Gao Xiang
2026-03-15 14:20 ` [PATCH v2] erofs-utils: release 1.9.1 Utkal Singh
2026-03-15 14:22 ` [PATCH v2] erofs-utils: lib: validate algorithm for encoded extents Utkal Singh
2026-03-16 3:11 ` Yifan Zhao
2026-03-16 5:33 ` 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=20260315072806.17504-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