Skip to contentSkip to conversation

fs/qnx6: fix divide-by-zero in qnx6_mmi_fill_super()

RFC PATCH syzbot 1 participant 1 message Oct 19 QNX6 filesystem

lore
Share & tools
lore

syzbot

author syzbot
#0 lore raw

When mounting a qnx6 filesystem with the "mmi_fs" option on a device containing invalid or all-zero superblock data with MS_SILENT (SB_SILENT) set, a divide error occurs in qnx6_mmi_fill_super():

Oops: divide error: 0000 [#1] SMP
RIP: 0010:qnx6_mmi_fill_super+0x228/0x870 fs/qnx6/super_mmi.c:68
Call Trace:
 <TASK>
 qnx6_fill_super+0x174/0x1380 fs/qnx6/inode.c:318
 get_tree_bdev_flags+0x430/0x4f0 fs/super.c:1872
 vfs_get_tree+0x92/0x2a0 fs/super.c:1932
 fc_mount fs/namespace.c:1282 [inline]
 do_new_mount_fc fs/namespace.c:3898 [inline]
 do_new_mount+0x325/0xb00 fs/namespace.c:3974
 do_mount fs/namespace.c:4338 [inline]
 __do_sys_mount fs/namespace.c:4556 [inline]
 __se_sys_mount+0x31d/0x420 fs/namespace.c:4533
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x166/0x520 arch/x86/entry/syscall_64.c:84
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
 </TASK>

This happens due to two issues in qnx6_mmi_fill_super(). First, when validating the first superblock magic number (sb1->sb_magic), the goto statement was mistakenly placed inside the "if (!silent)" block. The silent flag is only intended to suppress error messages during filesystem probing; placing "goto out;" inside the condition allowed execution to continue despite a magic mismatch when silent was non-zero. If the device data is zeroed, the subsequent CRC-32 check over zero bytes also matches a zero checksum. Second, qnx6_mmi_fill_super() calculated the secondary superblock offset by dividing QNX6_SUPERBLOCK_AREA by sb1->sb_blocksize before verifying or setting the block size via sb_set_blocksize(). With an invalid or zeroed superblock, sb1->sb_blocksize is zero, resulting in a divide-by-zero crash.

Fix this by moving "goto out;" outside of the "if (!silent)" block so that magic mismatches are always fatal, and reordering sb_set_blocksize() and the buffer head reload before calculating the offset. In addition, compute the superblock offset using bit shifts with s->s_blocksize_bits, aligning the implementation with qnx6_fill_super().

Fixes 5d026c724220 ("fs: initial qnx6fs addition")
Assisted-by Gemini:gemini-4-argon Gemini:gemini-3.8-flash syzbot
Reported-by [email protected]

To: <[email protected]>
To: "Kai Bankett" <[email protected]>
Cc: "Kees Cook" <[email protected]>

---

fs/qnx6/super_mmi.c +6 -7
index b8afb6f38..fe02e51e1 100644
@@ -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,10 +63,6 @@ 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))) {
 		pr_err("unable to set blocksize\n");
@@ -80,6 +75,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 = 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) {

base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222

Signature · 9 lines
This is an AI-generated patch subject to moderation.
Reply with '#syz upstream' to Sign-off the patch as a human author
and send it to the upstream kernel mailing lists.
Reply with '#syz reject' to reject it ('#syz unreject' to undo).

See https://goo.gle/syzbot-ai-patches for information about AI-generated patches.
You can comment on the patch as usual, syzbot will try to address
the comments and send a new version of the patch if necessary.
syzbot engineers can be reached at [email protected].