Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fs/minix: check return value of sb_getblk()

Patch series "fs/minix: fix syzbot bugs and set s_maxbytes".

This series fixes all syzbot bugs in the minix filesystem:

KASAN: null-ptr-deref Write in get_block
KASAN: use-after-free Write in get_block
KASAN: use-after-free Read in get_block
WARNING in inc_nlink
KMSAN: uninit-value in get_block
WARNING in drop_nlink

It also fixes the minix filesystem to set s_maxbytes correctly, so that
userspace sees the correct behavior when exceeding the max file size.

This patch (of 6):

sb_getblk() can fail, so check its return value.

This fixes a NULL pointer dereference.

Originally from Qiujun Huang.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-by: syzbot+4a88b2b9dc280f47baf4@syzkaller.appspotmail.com
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Qiujun Huang <anenbupt@gmail.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: <stable@vger.kernel.org>
Link: http://lkml.kernel.org/r/20200628060846.682158-1-ebiggers@kernel.org
Link: http://lkml.kernel.org/r/20200628060846.682158-2-ebiggers@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Eric Biggers and committed by
Linus Torvalds
da27e0a0 2fb3244f

+7 -1
+7 -1
fs/minix/itree_common.c
··· 75 75 int n = 0; 76 76 int i; 77 77 int parent = minix_new_block(inode); 78 + int err = -ENOSPC; 78 79 79 80 branch[0].key = cpu_to_block(parent); 80 81 if (parent) for (n = 1; n < num; n++) { ··· 86 85 break; 87 86 branch[n].key = cpu_to_block(nr); 88 87 bh = sb_getblk(inode->i_sb, parent); 88 + if (!bh) { 89 + minix_free_block(inode, nr); 90 + err = -ENOMEM; 91 + break; 92 + } 89 93 lock_buffer(bh); 90 94 memset(bh->b_data, 0, bh->b_size); 91 95 branch[n].bh = bh; ··· 109 103 bforget(branch[i].bh); 110 104 for (i = 0; i < n; i++) 111 105 minix_free_block(inode, block_to_cpu(branch[i].key)); 112 - return -ENOSPC; 106 + return err; 113 107 } 114 108 115 109 static inline int splice_branch(struct inode *inode,