From: Hui Peng <benquike@gmail.com>
To: brauner@kernel.org, jack@suse.cz, jlayton@kernel.org
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] minix: validate s_imap_blocks and s_zmap_blocks in minix_check_superblock()
Date: Sat, 19 Sep 2026 22:26:21 +0000 [thread overview]
Message-ID: <20260919222621.3796976-1-benquike@gmail.com> (raw)
In minix_check_superblock() and minix_fill_super() (fs/minix/inode.c),
verify that s_imap_blocks and s_zmap_blocks are large enough to cover
s_ninodes + 1 and s_zones, and check the return value of
sb_set_blocksize() to prevent out-of-bounds bitmap array reads in
minix_count_free_inodes() and minix_new_inode().
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Assisted-by: LLM
Signed-off-by: Hui Peng <benquike@gmail.com>
---
diff --git a/fs/minix/inode.c b/fs/minix/inode.c
index daf83e4ff25c..b0857dfc1b46 100644
--- a/fs/minix/inode.c
+++ b/fs/minix/inode.c
@@ -185,15 +185,15 @@ static bool minix_check_superblock(struct super_block *sb)
return false;
}
- if (sbi->s_ninodes < 1 || sbi->s_firstdatazone <= 4 ||
- sbi->s_firstdatazone >= sbi->s_nzones)
+ if (sbi->s_ninodes == 0 || sbi->s_ninodes == UINT_MAX ||
+ sbi->s_firstdatazone <= 4 || sbi->s_firstdatazone >= sbi->s_nzones)
return false;
/* Apparently minix can create filesystems that allocate more blocks for
* the bitmaps than needed. We simply ignore that, but verify it didn't
* create one with not enough blocks and bail out if so.
*/
- block = minix_blocks_needed(sbi->s_ninodes, sb->s_blocksize);
+ block = minix_blocks_needed((u64)sbi->s_ninodes + 1, sb->s_blocksize);
if (sbi->s_imap_blocks < block) {
printk("MINIX-fs: file system does not have enough "
"imap blocks allocated. Refusing to mount.\n");
@@ -201,7 +201,7 @@ static bool minix_check_superblock(struct super_block *sb)
}
block = minix_blocks_needed(
- (sbi->s_nzones - sbi->s_firstdatazone + 1),
+ (u64)sbi->s_nzones - sbi->s_firstdatazone + 1,
sb->s_blocksize);
if (sbi->s_zmap_blocks < block) {
printk("MINIX-fs: file system does not have enough "
next reply other threads:[~2026-09-19 22:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-19 22:26 Hui Peng [this message]
2026-09-22 5:11 ` Jeremy Bingham
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260919222621.3796976-1-benquike@gmail.com \
--to=benquike@gmail.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=jlayton@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®