Skip to content

Commit 9f2df09

Browse files
Tetsuo Handatorvalds
authored andcommitted
bfs: add sanity check at bfs_fill_super()
syzbot is reporting too large memory allocation at bfs_fill_super() [1]. Since file system image is corrupted such that bfs_sb->s_start == 0, bfs_fill_super() is trying to allocate 8MB of continuous memory. Fix this by adding a sanity check on bfs_sb->s_start, __GFP_NOWARN and printf(). [1] https://syzkaller.appspot.com/bug?id=16a87c236b951351374a84c8a32f40edbc034e96 Link: http://lkml.kernel.org/r/1525862104-3407-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Reported-by: syzbot <syzbot+71c6b5d68e91149fc8a4@syzkaller.appspotmail.com> Reviewed-by: Andrew Morton <akpm@linux-foundation.org> Cc: Tigran Aivazian <aivazian.tigran@gmail.com> Cc: Matthew Wilcox <willy@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 6f0483d commit 9f2df09

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

fs/bfs/inode.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
350350

351351
s->s_magic = BFS_MAGIC;
352352

353-
if (le32_to_cpu(bfs_sb->s_start) > le32_to_cpu(bfs_sb->s_end)) {
353+
if (le32_to_cpu(bfs_sb->s_start) > le32_to_cpu(bfs_sb->s_end) ||
354+
le32_to_cpu(bfs_sb->s_start) < BFS_BSIZE) {
354355
printf("Superblock is corrupted\n");
355356
goto out1;
356357
}
@@ -359,9 +360,11 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
359360
sizeof(struct bfs_inode)
360361
+ BFS_ROOT_INO - 1;
361362
imap_len = (info->si_lasti / 8) + 1;
362-
info->si_imap = kzalloc(imap_len, GFP_KERNEL);
363-
if (!info->si_imap)
363+
info->si_imap = kzalloc(imap_len, GFP_KERNEL | __GFP_NOWARN);
364+
if (!info->si_imap) {
365+
printf("Cannot allocate %u bytes\n", imap_len);
364366
goto out1;
367+
}
365368
for (i = 0; i < BFS_ROOT_INO; i++)
366369
set_bit(i, info->si_imap);
367370

0 commit comments

Comments
 (0)