Skip to content
/ linux Public

Commit 2bb588c

Browse files
LATENTBOUNCESasha Levin
authored andcommitted
minix: Add required sanity checking to minix_check_superblock()
[ Upstream commit 8c97a6d ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 43ccadb commit 2bb588c

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

fs/minix/inode.c

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,38 @@ static int minix_remount (struct super_block * sb, int * flags, char * data)
153153
static bool minix_check_superblock(struct super_block *sb)
154154
{
155155
struct minix_sb_info *sbi = minix_sb(sb);
156+
unsigned long block;
156157

157-
if (sbi->s_imap_blocks == 0 || sbi->s_zmap_blocks == 0)
158+
if (sbi->s_log_zone_size != 0) {
159+
printk("minix-fs error: zone size must equal block size. "
160+
"s_log_zone_size > 0 is not supported.\n");
161+
return false;
162+
}
163+
164+
if (sbi->s_ninodes < 1 || sbi->s_firstdatazone <= 4 ||
165+
sbi->s_firstdatazone >= sbi->s_nzones)
158166
return false;
159167

168+
/* Apparently minix can create filesystems that allocate more blocks for
169+
* the bitmaps than needed. We simply ignore that, but verify it didn't
170+
* create one with not enough blocks and bail out if so.
171+
*/
172+
block = minix_blocks_needed(sbi->s_ninodes, sb->s_blocksize);
173+
if (sbi->s_imap_blocks < block) {
174+
printk("MINIX-fs: file system does not have enough "
175+
"imap blocks allocated. Refusing to mount.\n");
176+
return false;
177+
}
178+
179+
block = minix_blocks_needed(
180+
(sbi->s_nzones - sbi->s_firstdatazone + 1),
181+
sb->s_blocksize);
182+
if (sbi->s_zmap_blocks < block) {
183+
printk("MINIX-fs: file system does not have enough "
184+
"zmap blocks allocated. Refusing to mount.\n");
185+
return false;
186+
}
187+
160188
/*
161189
* s_max_size must not exceed the block mapping limitation. This check
162190
* is only needed for V1 filesystems, since V2/V3 support an extra level
@@ -275,26 +303,6 @@ static int minix_fill_super(struct super_block *s, void *data, int silent)
275303
minix_set_bit(0,sbi->s_imap[0]->b_data);
276304
minix_set_bit(0,sbi->s_zmap[0]->b_data);
277305

278-
/* Apparently minix can create filesystems that allocate more blocks for
279-
* the bitmaps than needed. We simply ignore that, but verify it didn't
280-
* create one with not enough blocks and bail out if so.
281-
*/
282-
block = minix_blocks_needed(sbi->s_ninodes, s->s_blocksize);
283-
if (sbi->s_imap_blocks < block) {
284-
printk("MINIX-fs: file system does not have enough "
285-
"imap blocks allocated. Refusing to mount.\n");
286-
goto out_no_bitmap;
287-
}
288-
289-
block = minix_blocks_needed(
290-
(sbi->s_nzones - sbi->s_firstdatazone + 1),
291-
s->s_blocksize);
292-
if (sbi->s_zmap_blocks < block) {
293-
printk("MINIX-fs: file system does not have enough "
294-
"zmap blocks allocated. Refusing to mount.\n");
295-
goto out_no_bitmap;
296-
}
297-
298306
/* set up enough so that it can read an inode */
299307
s->s_op = &minix_sops;
300308
s->s_time_min = 0;

0 commit comments

Comments
 (0)