Skip to content

Commit da27e0a

Browse files
ebiggerstorvalds
authored andcommitted
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: 1da177e ("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>
1 parent 2fb3244 commit da27e0a

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎fs/minix/itree_common.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ static int alloc_branch(struct inode *inode,
7575
int n = 0;
7676
int i;
7777
int parent = minix_new_block(inode);
78+
int err = -ENOSPC;
7879

7980
branch[0].key = cpu_to_block(parent);
8081
if (parent) for (n = 1; n < num; n++) {
@@ -85,6 +86,11 @@ static int alloc_branch(struct inode *inode,
8586
break;
8687
branch[n].key = cpu_to_block(nr);
8788
bh = sb_getblk(inode->i_sb, parent);
89+
if (!bh) {
90+
minix_free_block(inode, nr);
91+
err = -ENOMEM;
92+
break;
93+
}
8894
lock_buffer(bh);
8995
memset(bh->b_data, 0, bh->b_size);
9096
branch[n].bh = bh;
@@ -103,7 +109,7 @@ static int alloc_branch(struct inode *inode,
103109
bforget(branch[i].bh);
104110
for (i = 0; i < n; i++)
105111
minix_free_block(inode, block_to_cpu(branch[i].key));
106-
return -ENOSPC;
112+
return err;
107113
}
108114

109115
static inline int splice_branch(struct inode *inode,

0 commit comments

Comments
 (0)