public inbox for linux-erofs@ozlabs.org
 help / color / mirror / Atom feed
From: Utkal Singh <singhutkal015@gmail.com>
To: hsiangkao@linux.alibaba.com
Cc: linux-erofs@lists.ozlabs.org, Utkal Singh <singhutkal015@gmail.com>
Subject: [PATCH v2] erofs-utils: lib: validate algorithm for encoded extents
Date: Sun, 15 Mar 2026 14:22:49 +0000	[thread overview]
Message-ID: <20260315142249.4333-1-singhutkal015@gmail.com> (raw)
In-Reply-To: <20260315072806.17504-1-singhutkal015@gmail.com>

Encoded extents use fmt field as algorithm index without checking
available_compr_algs bitmask. The non-encoded path already has this
check but the encoded extent path in z_erofs_map_blocks_ext() was
missing equivalent validation.

Add available_compr_algs consistency check for encoded extents,
following kernel commit 131897c65e2b.

Signed-off-by: Utkal Singh <singhutkal015@gmail.com>
---
 lib/zmap.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/lib/zmap.c b/lib/zmap.c
index 0e7af4e..a8d1ca6 100644
--- a/lib/zmap.c
+++ b/lib/zmap.c
@@ -630,8 +630,17 @@ 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)
-				map->m_algorithmformat = fmt - 1;
+			if (fmt) {
+				unsigned int afmt = fmt - 1;
+
+				if (afmt >= Z_EROFS_COMPRESSION_MAX ||
+				    !(sbi->available_compr_algs & (1 << afmt))) {
+					erofs_err("unknown algorithm %u for encoded extent, nid %llu",
+						  afmt, vi->nid | 0ULL);
+					return -EOPNOTSUPP;
+				}
+				map->m_algorithmformat = afmt;
+			}
 			else if (interlaced && !((map->m_pa | map->m_plen) & bmask))
 				map->m_algorithmformat =
 					Z_EROFS_COMPRESSION_INTERLACED;
-- 
2.43.0



  parent reply	other threads:[~2026-03-15 14:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-15  7:28 [PATCH] erofs-utils: lib: validate algorithm format before use in z_erofs_map_blocks_ext Utkal Singh
2026-03-15 10:39 ` Gao Xiang
2026-03-15 14:20 ` [PATCH v2] erofs-utils: release 1.9.1 Utkal Singh
2026-03-15 14:22 ` Utkal Singh [this message]
2026-03-16  3:11   ` [PATCH v2] erofs-utils: lib: validate algorithm for encoded extents 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=20260315142249.4333-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