Skip to content

Commit 8c97a6d

Browse files
LATENTBOUNCEbrauner
authored andcommitted
minix: Add required sanity checking to minix_check_superblock()
The fs/minix implementation of the minix filesystem does not currently support any other value for s_log_zone_size than 0. This is also the only value supported in util-linux; see mkfs.minix.c line 511. In addition, this patch adds some sanity checking for the other minix superblock fields, and moves the minix_blocks_needed() checks for the zmap and imap also to minix_check_super_block(). This also closes a related syzbot bug report. Signed-off-by: Jori Koolstra <jkoolstra@xs4all.nl> Link: https://patch.msgid.link/20251208153947.108343-1-jkoolstra@xs4all.nl Reviewed-by: Jan Kara <jack@suse.cz> Reported-by: syzbot+5ad0824204c7bf9b67f2@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=5ad0824204c7bf9b67f2 Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 8f0b4cc commit 8c97a6d

1 file changed

Lines changed: 29 additions & 21 deletions

File tree

fs/minix/inode.c

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,38 @@ static int minix_reconfigure(struct fs_context *fc)
170170
static bool minix_check_superblock(struct super_block *sb)
171171
{
172172
struct minix_sb_info *sbi = minix_sb(sb);
173+
unsigned long block;
173174

174-
if (sbi->s_imap_blocks == 0 || sbi->s_zmap_blocks == 0)
175+
if (sbi->s_log_zone_size != 0) {
176+
printk("minix-fs error: zone size must equal block size. "
177+
"s_log_zone_size > 0 is not supported.\n");
178+
return false;
179+
}
180+
181+
if (sbi->s_ninodes < 1 || sbi->s_firstdatazone <= 4 ||
182+
sbi->s_firstdatazone >= sbi->s_nzones)
175183
return false;
176184

185+
/* Apparently minix can create filesystems that allocate more blocks for
186+
* the bitmaps than needed. We simply ignore that, but verify it didn't
187+
* create one with not enough blocks and bail out if so.
188+
*/
189+
block = minix_blocks_needed(sbi->s_ninodes, sb->s_blocksize);
190+
if (sbi->s_imap_blocks < block) {
191+
printk("MINIX-fs: file system does not have enough "
192+
"imap blocks allocated. Refusing to mount.\n");
193+
return false;
194+
}
195+
196+
block = minix_blocks_needed(
197+
(sbi->s_nzones - sbi->s_firstdatazone + 1),
198+
sb->s_blocksize);
199+
if (sbi->s_zmap_blocks < block) {
200+
printk("MINIX-fs: file system does not have enough "
201+
"zmap blocks allocated. Refusing to mount.\n");
202+
return false;
203+
}
204+
177205
/*
178206
* s_max_size must not exceed the block mapping limitation. This check
179207
* is only needed for V1 filesystems, since V2/V3 support an extra level
@@ -293,26 +321,6 @@ static int minix_fill_super(struct super_block *s, struct fs_context *fc)
293321
minix_set_bit(0,sbi->s_imap[0]->b_data);
294322
minix_set_bit(0,sbi->s_zmap[0]->b_data);
295323

296-
/* Apparently minix can create filesystems that allocate more blocks for
297-
* the bitmaps than needed. We simply ignore that, but verify it didn't
298-
* create one with not enough blocks and bail out if so.
299-
*/
300-
block = minix_blocks_needed(sbi->s_ninodes, s->s_blocksize);
301-
if (sbi->s_imap_blocks < block) {
302-
printk("MINIX-fs: file system does not have enough "
303-
"imap blocks allocated. Refusing to mount.\n");
304-
goto out_no_bitmap;
305-
}
306-
307-
block = minix_blocks_needed(
308-
(sbi->s_nzones - sbi->s_firstdatazone + 1),
309-
s->s_blocksize);
310-
if (sbi->s_zmap_blocks < block) {
311-
printk("MINIX-fs: file system does not have enough "
312-
"zmap blocks allocated. Refusing to mount.\n");
313-
goto out_no_bitmap;
314-
}
315-
316324
/* set up enough so that it can read an inode */
317325
s->s_op = &minix_sops;
318326
s->s_time_min = 0;

0 commit comments

Comments
 (0)