qnx6: fix divide-by-zero and silent magic check in qnx6_mmi_fill_super()
Subsystems (3)
PATCH 1/1 qnx6: fix divide-by-zero and silent magic check in qnx6_mmi_fill_super()
syzbot reported a divide error in qnx6_mmi_fill_super() when mounting an all-zero block device with MS_SILENT and the "mmi_fs" mount option:
Oops: divide error: 0000 [#1] SMP KASAN PTI RIP: 0010:qnx6_mmi_fill_super+0x228/0x870 fs/qnx6/super_mmi.c:68
Two issues combine to trigger this crash:
1. When sb1->sb_magic does not match QNX6_SUPER_MAGIC, "goto out;" is nested inside "if (!silent)", so mounting with MS_SILENT falls through instead of aborting. An all-zero superblock then passes the crc32_be() check because crc32_be(0, zeros, 504) == 0.
2. The second superblock offset divides QNX6_SUPERBLOCK_AREA by fs32_to_cpu(sbi, sb1->sb_blocksize) before sb_set_blocksize() validates the blocksize, causing a divide-by-zero when sb_blocksize is 0.
Fix both by moving "goto out;" outside "if (!silent)" (matching the sb2 magic check) and validating sb1->sb_blocksize against QNX6_SUPERBLOCK_AREA and sb_set_blocksize() before computing the second superblock offset using a 64-bit addition and s->s_blocksize_bits, matching qnx6_fill_super().
--- fs/qnx6/super_mmi.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
fs/qnx6/super_mmi.c +8 -8
@@ -51,10 +51,9 @@ struct qnx6_super_block *qnx6_mmi_fill_super(struct super_block *s, int silent) sb1 = (struct qnx6_mmi_super_block *)bh1->b_data; sbi =QNX6_SB (s);if (fs32_to_cpu (sbi, sb1->sb_magic) !=QNX6_SUPER_MAGIC ) { -if (!silent) { +if (!silent)pr_err ("wrong signature (magic) in superblock #1.\n" ); - goto out; - } + goto out; }/* checksum check - start at byte 8 and end at byte 512 */
@@ -64,12 +63,9 @@ struct qnx6_super_block *qnx6_mmi_fill_super(struct super_block *s, int silent) goto out; } -/* calculate second superblock blocknumber */ - offset =fs32_to_cpu (sbi, sb1->sb_num_blocks) +QNX6_SUPERBLOCK_AREA / -fs32_to_cpu (sbi, sb1->sb_blocksize); -/* set new blocksize */ -if (!sb_set_blocksize (s,fs32_to_cpu (sbi, sb1->sb_blocksize))) { +if (fs32_to_cpu (sbi, sb1->sb_blocksize) >QNX6_SUPERBLOCK_AREA || + !sb_set_blocksize (s,fs32_to_cpu (sbi, sb1->sb_blocksize))) {pr_err ("unable to set blocksize\n" ); goto out; }
@@ -80,6 +76,10 @@ struct qnx6_super_block *qnx6_mmi_fill_super(struct super_block *s, int silent) goto out; sb1 = (struct qnx6_mmi_super_block *)bh1->b_data; +/* calculate second superblock blocknumber */ + offset = (u64 )fs32_to_cpu (sbi, sb1->sb_num_blocks) + + (QNX6_SUPERBLOCK_AREA >> s->s_blocksize_bits); +/* read second superblock */ bh2 =sb_bread (s, offset);if (!bh2) {
Signature · 1 line
2.53.0