public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: Edward Adam Davis <eadavis@qq.com>
Cc: syzbot+4125a3c514e3436a02e6@syzkaller.appspotmail.com,
	cem@kernel.org, chandan.babu@oracle.com, djwong@kernel.org,
	linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org,
	syzkaller-bugs@googlegroups.com
Subject: Re: [PATCH] xfs: If unable to pick perag an error needs to be returned
Date: Tue, 22 Oct 2024 00:51:03 +1100	[thread overview]
Message-ID: <ZxZcR1v8OnYH/l+/@dread.disaster.area> (raw)
In-Reply-To: <tencent_1DD6B365236C297EA3A6A45DB768B76F2605@qq.com>

On Sun, Oct 20, 2024 at 01:30:05PM +0800, Edward Adam Davis wrote:
> Syzbot reported a null-ptr-deref Write in xfs_filestream_select_ag.
> When pag is not found, xfs_filestream_pick_ag() also returns 0, which leads
> to null pointer access in xfs_filestream_create_association().
> 
> At the end of xfs_filestream_pick_ag, we need to add a sanity check for pag,
> if we fail to grab any AG, we should return to -ENOSPC instead of 0.
> 
> Reported-and-tested-by: syzbot+4125a3c514e3436a02e6@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=4125a3c514e3436a02e6
> Signed-off-by: Edward Adam Davis <eadavis@qq.com>
> ---
>  fs/xfs/xfs_filestream.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/fs/xfs/xfs_filestream.c b/fs/xfs/xfs_filestream.c
> index e3aaa0555597..dd8f193a3957 100644
> --- a/fs/xfs/xfs_filestream.c
> +++ b/fs/xfs/xfs_filestream.c
> @@ -165,6 +165,10 @@ xfs_filestream_pick_ag(
>  
>  	trace_xfs_filestream_pick(pag, pino, free);
>  	args->pag = pag;
> +
> +	if (!args->pag)
> +		return -ENOSPC;
> +

If we get here with pag == NULL, then something else has gone
wrong before we got here.

i.e. there's an if (!pag) {} check directly above this, and it can
only fall through to this code if pag != NULL. Hence if pag is NULL
at this point, we should have already hit a null pointer deref
before we got to this point...

So, where's the null pag coming from?

-Dave.
-- 
Dave Chinner
david@fromorbit.com

  reply	other threads:[~2024-10-21 13:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-18 19:00 [syzbot] [xfs?] KASAN: null-ptr-deref Write in xfs_filestream_select_ag (2) syzbot
2024-10-20  5:30 ` [PATCH] xfs: If unable to pick perag an error needs to be returned Edward Adam Davis
2024-10-21 13:51   ` Dave Chinner [this message]
2024-10-22  9:41 ` [syzbot] [xfs?] KASAN: null-ptr-deref Write in xfs_filestream_select_ag (2) Christoph Hellwig
2024-10-22 10:11   ` syzbot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZxZcR1v8OnYH/l+/@dread.disaster.area \
    --to=david@fromorbit.com \
    --cc=cem@kernel.org \
    --cc=chandan.babu@oracle.com \
    --cc=djwong@kernel.org \
    --cc=eadavis@qq.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=syzbot+4125a3c514e3436a02e6@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox