Re: [PATCH] fs/bfs: Null check to prevent null-ptr-deref bug

From: Christian A. Ehrhardt
Date: Sat Jan 06 2024 - 13:54:45 EST



Hi,

On Sat, Jan 06, 2024 at 08:38:02AM +0000, Tigran Aivazian wrote:
> Hello,
>
> On Fri, 5 Jan 2024 at 19:33, Xiaochen Zou <xzou017@xxxxxxx> wrote:
> > Similar to ea2b62f3058 (fs/sysv: Null check to prevent
> > null-ptr-deref bug), bfs is lack of return value check for
> > sb_getblk(). Adding a null check to prevent null-ptr-defer bug
>
> > diff --git a/fs/bfs/file.c b/fs/bfs/file.c
> > index adc2230079c6..35688424bde3 100644
> > --- a/fs/bfs/file.c
> > +++ b/fs/bfs/file.c
> > @@ -39,6 +39,8 @@ static int bfs_move_block(unsigned long from, unsigned long to,
> > if (!bh)
> > return -EIO;
> > new = sb_getblk(sb, to);
> > + if (unlikely(!new))
> > + return -ENOMEM;
>
> Thank you, yes, that makes sense. Please apply the patch.

What's with the bh in this case? Wouldn't we need a brelse or something?

>
> Acknowledged-By; Tigran Aivazian <aivazian.tigran@xxxxxxxxx>
>
>

regards Christian