Re: KASAN: null-ptr-deref Write in get_block

Dan Carpenter
2020-03-23T11:43:04Z

Fix the subject to [PATCH] minix: Fix NULL dereference in alloc_branch()

On Sun, Mar 22, 2020 at 08:06:48PM +0800, Qiujun Huang wrote:
> Need to check the return value of sb_getblk.
>

Add a Reported-by tag.

Reported-by: syzbot+4a88b2b9dc280f47baf4@syzkaller.appspotmail.com

> Signed-off-by: Qiujun Huang <hqjagain@gmail.com>
> ---
> fs/minix/itree_common.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/fs/minix/itree_common.c b/fs/minix/itree_common.c
> index 043c3fd..eedd79f 100644
> --- a/fs/minix/itree_common.c
> +++ b/fs/minix/itree_common.c
> @@ -85,6 +85,8 @@ static int alloc_branch(struct inode *inode,
> break;
> branch[n].key = cpu_to_block(nr);
> bh = sb_getblk(inode->i_sb, parent);
> + if (!bh)
> + break;

The patch is white space damaged and we need to do a bit of error
handling before the break as well.

bh = sb_getblk(inode->i_sb, parent);
+ if (!bh) {
+ minix_free_block(inode, block_to_cpu(branch[n].key));
+ break;
+ }
lock_buffer(bh);

Please fix those few things and resend.

regards,
dan carpenter