* [PATCH] erofs: fix EFSCORRUPTED on multi-algorithm images in z_erofs_map_sanity_check()
@ 2026-06-01 8:51 Zhan Xusheng
2026-06-01 8:56 ` Gao Xiang
0 siblings, 1 reply; 2+ messages in thread
From: Zhan Xusheng @ 2026-06-01 8:51 UTC (permalink / raw)
To: Gao Xiang; +Cc: linux-kernel, Zhan Xusheng
Commit a5242d37c83a ("erofs: error out obviously illegal extents in
advance") changed the per-extent algorithm presence check from "is the
bit set" to "is the only bit set":
- !(sbi->available_compr_algs & (1 << map->m_algorithmformat))
+ (sbi->available_compr_algs ^ BIT(map->m_algorithmformat))
`available_compr_algs` is a bitmap of every compression algorithm
available in the image (z_erofs_parse_cfgs() iterates it with
for_each_set_bit()), so an image that enables more than one algorithm
has multiple bits set. XOR is zero only when the bitmap is exactly
BIT(map->m_algorithmformat); for any image with two or more algorithms
the test is non-zero for every extent and the read fails with
-EFSCORRUPTED ("inconsistent algorithmtype %u").
Reproducer (mkfs.erofs from erofs-utils 1.7.1):
$ mkdir src
$ yes A | head -c 100K > src/a
$ head -c 64K /dev/zero > src/b
$ mkfs.erofs -zlz4:deflate multi.erofs src
$ mount -t erofs -o loop multi.erofs /mnt
$ cat /mnt/a >/dev/null
cat: /mnt/a: Structure needs cleaning
$ dmesg | tail
erofs (device loop0): inconsistent algorithmtype 0 for nid 46
erofs (device loop0): read error -117 @ 0 of nid 46
The erofs on-disk format (Z_EROFS_COMPRESSION_MAX = 4 with LZ4, LZMA,
DEFLATE, ZSTD) and the kernel parser explicitly support
multi-algorithm images, and erofs-utils 1.7.1 generates them via the
"-z X:Y" syntax.
Restore the original per-bit presence check.
Fixes: a5242d37c83a ("erofs: error out obviously illegal extents in advance")
Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
---
fs/erofs/zmap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c
index a72db36096ca..e1a02a2c8406 100644
--- a/fs/erofs/zmap.c
+++ b/fs/erofs/zmap.c
@@ -716,7 +716,7 @@ static int z_erofs_map_sanity_check(struct inode *inode,
}
if (map->m_algorithmformat < Z_EROFS_COMPRESSION_MAX) {
- if (sbi->available_compr_algs ^ BIT(map->m_algorithmformat)) {
+ if (!(sbi->available_compr_algs & BIT(map->m_algorithmformat))) {
erofs_err(inode->i_sb, "inconsistent algorithmtype %u for nid %llu",
map->m_algorithmformat, EROFS_I(inode)->nid);
return -EFSCORRUPTED;
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] erofs: fix EFSCORRUPTED on multi-algorithm images in z_erofs_map_sanity_check()
2026-06-01 8:51 [PATCH] erofs: fix EFSCORRUPTED on multi-algorithm images in z_erofs_map_sanity_check() Zhan Xusheng
@ 2026-06-01 8:56 ` Gao Xiang
0 siblings, 0 replies; 2+ messages in thread
From: Gao Xiang @ 2026-06-01 8:56 UTC (permalink / raw)
To: Zhan Xusheng, Gao Xiang; +Cc: linux-kernel, Zhan Xusheng
On 2026/6/1 16:51, Zhan Xusheng wrote:
> Commit a5242d37c83a ("erofs: error out obviously illegal extents in
> advance") changed the per-extent algorithm presence check from "is the
> bit set" to "is the only bit set":
> - !(sbi->available_compr_algs & (1 << map->m_algorithmformat))
> + (sbi->available_compr_algs ^ BIT(map->m_algorithmformat))
>
> `available_compr_algs` is a bitmap of every compression algorithm
> available in the image (z_erofs_parse_cfgs() iterates it with
> for_each_set_bit()), so an image that enables more than one algorithm
> has multiple bits set. XOR is zero only when the bitmap is exactly
> BIT(map->m_algorithmformat); for any image with two or more algorithms
> the test is non-zero for every extent and the read fails with
> -EFSCORRUPTED ("inconsistent algorithmtype %u").
>
> Reproducer (mkfs.erofs from erofs-utils 1.7.1):
> $ mkdir src
> $ yes A | head -c 100K > src/a
> $ head -c 64K /dev/zero > src/b
> $ mkfs.erofs -zlz4:deflate multi.erofs src
> $ mount -t erofs -o loop multi.erofs /mnt
> $ cat /mnt/a >/dev/null
> cat: /mnt/a: Structure needs cleaning
> $ dmesg | tail
> erofs (device loop0): inconsistent algorithmtype 0 for nid 46
> erofs (device loop0): read error -117 @ 0 of nid 46
>
> The erofs on-disk format (Z_EROFS_COMPRESSION_MAX = 4 with LZ4, LZMA,
> DEFLATE, ZSTD) and the kernel parser explicitly support
> multi-algorithm images, and erofs-utils 1.7.1 generates them via the
> "-z X:Y" syntax.
>
> Restore the original per-bit presence check.
>
> Fixes: a5242d37c83a ("erofs: error out obviously illegal extents in advance")
> Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
Thanks, that is an awkward regression:
Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Thanks,
Gao Xiang
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-01 8:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-01 8:51 [PATCH] erofs: fix EFSCORRUPTED on multi-algorithm images in z_erofs_map_sanity_check() Zhan Xusheng
2026-06-01 8:56 ` Gao Xiang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome