erofs: use on-disk blkszbits for lz4 max pcluster bound
Subsystems (2)
PATCH 1/1 erofs: use on-disk blkszbits for lz4 max pcluster bound
z_erofs_load_lz4_config() rejects a valid LZ4 image when the kernel's page size differs from the image's block size. It bounds the on-disk max_pclusterblks with erofs_blknr(sb, Z_EROFS_PCLUSTER_MAX_SIZE), which expands to Z_EROFS_PCLUSTER_MAX_SIZE >> sb->s_blocksize_bits.
At the point this runs, sb->s_blocksize_bits still holds PAGE_SHIFT:erofs_fc_fill_super() seeds s_blocksize_bits to PAGE_SHIFT before reading the superblock, and only corrects it down to the on-disk blkszbits after erofs_read_superblock() returns. The LZ4 config is parsed inside erofs_read_superblock(), before that correction, so the bound is computed with the wrong shift.
On a 64K-page kernel mounting a 4K-block image (e.g. one built with mkfs.erofs -C 262144 on a 4K-page host), the bound evaluates to 1 MiB >> 16 = 16 blocks instead of the correct 1 MiB >> 12 = 256 blocks. The image's legitimate max_pclusterblks of 64 then fails the check, mount returns -EINVAL, and booting from such an image as the root filesystem panics:
erofs (device dm-0): too large lz4 pclusterblks 64
Kernel panic - not syncing: VFS: Unable to mount root fs
sbi->blkszbits already holds the on-disk block size at this point, so compute the bound from it directly. This makes the check independent of the host page size and of superblock-parse ordering.
commit 3acea5fc3354 ("erofs: avoid hardcoded blocksize for subpage block support") already handled the same ordering hazard for the superblock checksum path by using sbi->blkszbits in erofs_superblock_csum_verify(); the lz4 config path was missed.
---
Tested on arm64 (Graviton) with CONFIG_ARM64_64K_PAGES=y (64K pages), mounting an LZ4 EROFS image built on a 4K-page host with 4K blocks and a large pcluster (mkfs.erofs -zlz4 -C 262144 -b 4096, max_pclusterblks=64):
- Before: mount fails, dmesg "erofs: too large lz4 pclusterblks 64".
- After: mounts cleanly; file contents verified byte-for-byte.
A 4K-page kernel mounts the same image before and after (no regression).
fs/erofs/decompressor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/erofs/decompressor.c +1 -1
@@ -27,7 +27,7 @@ static int z_erofs_load_lz4_config(struct super_block *sb,if (!sbi->lz4.max_pclusterblks) { sbi->lz4.max_pclusterblks =1 ;/* reserved case */ }else if (sbi->lz4.max_pclusterblks > -erofs_blknr (sb,Z_EROFS_PCLUSTER_MAX_SIZE )) { +Z_EROFS_PCLUSTER_MAX_SIZE >> sbi->blkszbits) {erofs_err (sb,"too large lz4 pclusterblks %u" , sbi->lz4.max_pclusterblks);return -EINVAL ;
Signature · 1 line
2.50.1