public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Long Li <leo.lilong@huawei.com>
To: "Darrick J. Wong" <djwong@kernel.org>
Cc: <cem@kernel.org>, <linux-xfs@vger.kernel.org>,
	<david@fromorbit.com>, <yi.zhang@huawei.com>,
	<houtao1@huawei.com>, <yangerkun@huawei.com>,
	<lonuxli.64@gmail.com>
Subject: Re: [PATCH v2 1/3] xfs: fix possible null pointer dereference in xfs_attri_recover_work
Date: Fri, 20 Mar 2026 09:44:15 +0800	[thread overview]
Message-ID: <abymb78z5v61vARS@localhost.localdomain> (raw)
In-Reply-To: <20260319165200.GP1770774@frogsfrogsfrogs>

On Thu, Mar 19, 2026 at 09:52:00AM -0700, Darrick J. Wong wrote:
> On Thu, Mar 19, 2026 at 09:06:16AM +0800, Long Li wrote:
> > When xlog_recover_iget() or xlog_recover_iget_handle() fails, ip is
> > not guaranteed to be initialized. Calling xfs_irele(ip) unconditionally
> > in the error path may dereference a null pointer.
> > 
> > Cc: <stable@vger.kernel.org> # v6.9
> > Fixes: ae673f534a30 ("xfs: record inode generation in xattr update log intent items")
> > Signed-off-by: Long Li <leo.lilong@huawei.com>
> > ---
> >  fs/xfs/xfs_attr_item.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/fs/xfs/xfs_attr_item.c b/fs/xfs/xfs_attr_item.c
> > index 354472bf45f1..8ebdd0926b89 100644
> > --- a/fs/xfs/xfs_attr_item.c
> > +++ b/fs/xfs/xfs_attr_item.c
> > @@ -633,7 +633,7 @@ xfs_attri_recover_work(
> >  {
> >  	struct xfs_attr_intent		*attr;
> >  	struct xfs_da_args		*args;
> > -	struct xfs_inode		*ip;
> > +	struct xfs_inode		*ip = NULL;
> >  	int				local;
> >  	int				error;
> >  
> > @@ -653,7 +653,8 @@ xfs_attri_recover_work(
> >  		break;
> >  	}
> >  	if (error) {
> > -		xfs_irele(ip);
> > +		if (ip)
> > +			xfs_irele(ip);
> 
> Hrmm.  On second thought, there's a much more severe UAF bug here:
> 
> int
> xlog_recover_iget(
> 	struct xfs_mount	*mp,
> 	xfs_ino_t		ino,
> 	struct xfs_inode	**ipp)
> {
> 	int			error;
> 
> 	error = xfs_iget(mp, NULL, ino, 0, 0, ipp);
> 	if (error)
> 		return error;
> 
> 	error = xfs_qm_dqattach(*ipp);
> 	if (error) {
> 		xfs_irele(*ipp);
> 		return error;
> 
> ^^^^^ here we return a nonzero error, having previously set @ipp.
> The xfs_irele in xfs_attri_recover_work is, in this case, the wrong
> thing to do.
> 
> 	}
> 
> 	if (VFS_I(*ipp)->i_nlink == 0)
> 		xfs_iflags_set(*ipp, XFS_IRECOVERY);
> 
> 	return 0;
> }
> 
> With that fixed, the xfs_irele call in xfs_attri_recover_work becomes
> incorrect because the xlog*iget functions never return nonzero *and* set
> *ipp.  If you found this via static checker, I wonder if that's what is
> tripping it up?
> 

Yes, we found this through static analysis. Obviously, I didn't look
at this code carefully enough. Thank you for pointing it out and fixing
it.

Thanks,
Long Li

  reply	other threads:[~2026-03-20  1:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-19  1:06 [PATCH v2 0/3] xfs: fixes and clean up for attr item Long Li
2026-03-19  1:06 ` [PATCH v2 1/3] xfs: fix possible null pointer dereference in xfs_attri_recover_work Long Li
2026-03-19 16:52   ` Darrick J. Wong
2026-03-20  1:44     ` Long Li [this message]
2026-03-19  1:06 ` [PATCH v2 2/3] xfs: fix ri_total validation in xlog_recover_attri_commit_pass2 Long Li
2026-03-19 16:54   ` Darrick J. Wong
2026-03-19  1:06 ` [PATCH v2 3/3] xfs: remove redundant " Long Li
2026-03-19 16:54   ` Darrick J. Wong

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=abymb78z5v61vARS@localhost.localdomain \
    --to=leo.lilong@huawei.com \
    --cc=cem@kernel.org \
    --cc=david@fromorbit.com \
    --cc=djwong@kernel.org \
    --cc=houtao1@huawei.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=lonuxli.64@gmail.com \
    --cc=yangerkun@huawei.com \
    --cc=yi.zhang@huawei.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