erofs-utils: refuse block sizes larger than EROFS_MAX_BLOCK_SIZE
authorGao Xiang <hsiangkao@linux.alibaba.com>
Sat, 3 Jun 2023 13:31:29 +0000 (21:31 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Tue, 6 Jun 2023 14:19:27 +0000 (22:19 +0800)
The maximum supported block size is EROFS_MAX_BLOCK_SIZE.

[ Gao Xiang: shifted values can also overflow and need to be fixed. ]
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20230603133130.34364-1-hsiangkao@linux.alibaba.com
lib/super.c

index 17f849eb4bd4b3c904ef7a45a2b8e42ae3755e3d..820c883461c5ed8196932397ebcd65545bf74bce 100644 (file)
@@ -88,15 +88,14 @@ int erofs_read_superblock(void)
        sbi.feature_compat = le32_to_cpu(dsb->feature_compat);
 
        sbi.blkszbits = dsb->blkszbits;
-       /* 9(512 bytes) + LOG_SECTORS_PER_BLOCK == LOG_BLOCK_SIZE */
-       if (sbi.blkszbits < 9) {
-               erofs_err("blksize %d isn't supported on this platform",
-                         erofs_blksiz());
+       if (sbi.blkszbits < 9 ||
+           sbi.blkszbits > ilog2(EROFS_MAX_BLOCK_SIZE)) {
+               erofs_err("blksize %llu isn't supported on this platform",
+                         erofs_blksiz() | 0ULL);
                return ret;
-       }
-
-       if (!check_layout_compatibility(&sbi, dsb))
+       } else if (!check_layout_compatibility(&sbi, dsb)) {
                return ret;
+       }
 
        sbi.primarydevice_blocks = le32_to_cpu(dsb->blocks);
        sbi.meta_blkaddr = le32_to_cpu(dsb->meta_blkaddr);