mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] qnx6: fix divide-by-zero and silent magic check in qnx6_mmi_fill_super()
@ 2026-11-20 22:03 Arbab Haider
  0 siblings, 0 replies; only message in thread
From: Arbab Haider @ 2026-11-20 22:03 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: linux-kernel, akpm, syzbot+6a0633f11d3fb88860bf, stable, Arbab Haider

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().

Reported-by: syzbot+6a0633f11d3fb88860bf@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=6a0633f11d3fb88860bf
Fixes: 5d026c724220 ("fs: initial qnx6fs addition")
Cc: stable@vger.kernel.org
Signed-off-by: Arbab Haider <arbabhaider649@gmail.com>
---
 fs/qnx6/super_mmi.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/fs/qnx6/super_mmi.c b/fs/qnx6/super_mmi.c
index b8afb6f38..bb4243872 100644
--- a/fs/qnx6/super_mmi.c
+++ b/fs/qnx6/super_mmi.c
@@ -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) {
-- 
2.53.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-20 22:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20 22:03 [PATCH] qnx6: fix divide-by-zero and silent magic check in qnx6_mmi_fill_super() Arbab Haider

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®