Skip to content

Commit 7e01a69

Browse files
committed
Merge tag 'vfs-7.0-rc1.minix' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs
Pull minix update from Christian Brauner: "Consolidate and strengthen superblock validation in minix_check_superblock() The minix filesystem driver does not validate several superblock fields before using them during mount, allowing a crafted filesystem image to trigger out-of-bounds accesses (reported by syzbot)" * tag 'vfs-7.0-rc1.minix' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs: minix: Add required sanity checking to minix_check_superblock()
2 parents 6124fa4 + 8c97a6d commit 7e01a69

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)