linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Brian Foster <bfoster@redhat.com>
To: Dave Chinner <david@fromorbit.com>
Cc: "Darrick J. Wong" <darrick.wong@oracle.com>, linux-xfs@vger.kernel.org
Subject: Re: [PATCH] xfs: fix intent use-after-free on abort
Date: Tue, 3 Apr 2018 07:34:27 -0400	[thread overview]
Message-ID: <20180403113426.GB64324@bfoster.bfoster> (raw)
In-Reply-To: <20180403040358.GK1150@dastard>

On Tue, Apr 03, 2018 at 02:03:58PM +1000, Dave Chinner wrote:
> On Mon, Apr 02, 2018 at 08:06:47PM -0700, Darrick J. Wong wrote:
> > On Tue, Apr 03, 2018 at 11:44:58AM +1000, Dave Chinner wrote:
> > > From: Dave Chinner <dchinner@redhat.com>
> > > 
> > > When an intent is aborted during it's initial commit through
> > > xfs_defer_trans_abort(), there is a use after free. The current
> > > report is for a RUI  through this path in generic/388:
> > > 
> > >  Freed by task 6274:
> > >   __kasan_slab_free+0x136/0x180
> > >   kmem_cache_free+0xe7/0x4b0
> > >   xfs_trans_free_items+0x198/0x2e0
> > >   __xfs_trans_commit+0x27f/0xcc0
> > >   xfs_trans_roll+0x17b/0x2a0
> > >   xfs_defer_trans_roll+0x6ad/0xe60
> > >   xfs_defer_finish+0x2a6/0x2140
> > >   xfs_alloc_file_space+0x53a/0xf90
> > >   xfs_file_fallocate+0x5c6/0xac0
> > >   vfs_fallocate+0x2f5/0x930
> > >   ioctl_preallocate+0x1dc/0x320
> > >   do_vfs_ioctl+0xfe4/0x1690
> > > 
> > > The problem is that the RUI has two active references - one in the
> > > current transaction, and another held by the defer_ops structure
> > > that is passed to the RUD (intent done) so that both the intent and
> > > the intent done structures are freed on commit of the intent done.
> > > 
> > > Hence during abort, we need to release the intent item, because the
> > > defer_ops reference is released separately via ->abort_intent
> > > callback. Fix all the intent code to do this correctly.
> > > 
> > > Signed-Off-By: Dave Chinner <dchinner@redhat.com>
> .....
> > > @@ -142,7 +161,7 @@ xfs_bui_item_unlock(
> > >  	struct xfs_log_item	*lip)
> > >  {
> > >  	if (test_bit(XFS_LI_ABORTED, &lip->li_flags))
> > 
> > Hm, in my tree this is still "if (lip->li_flags & XFS_LI_ABORTED)" :)
> > /me wonders where the test_bit() came from?
> 
> Oh, sorry, I just dumped the patch on the end of my stack, which has
> this conversion in it (because we do a bunch of racy updates on the
> log item flags with any serialisation and that needs to be fixed to
> get rid of log item descriptors).
> 
> Change them all to
> 
> 	if (lip->li_flags & XFS_LI_ABORTED)
> 
> and it'll apply to the for-next tree.
> 

This also needs comment updates for all of the unlock handlers that
currently explain why we free the item directly (which should now
explain that the caller is responsible for the additional reference).

Brian

> > But this is the same change that I came up with to solve the problem, so
> > I guess I'll go feed it to the test machines and see how they fare
> > overnight, and mash on it harder with generic/388 tomorrow.
> 
> Been running generic/388 in a loop and nothing seems to have gone
> wrong yet.
> 
> Cheers,
> 
> Dave.
> -- 
> Dave Chinner
> david@fromorbit.com
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2018-04-03 11:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-03  1:44 [PATCH] xfs: fix intent use-after-free on abort Dave Chinner
2018-04-03  3:06 ` Darrick J. Wong
2018-04-03  4:03   ` Dave Chinner
2018-04-03 11:34     ` Brian Foster [this message]
2018-04-19 21:22     ` Luis R. Rodriguez
2018-04-19 22:58       ` Dave Chinner
2018-04-03  5:10 ` Allison Henderson

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=20180403113426.GB64324@bfoster.bfoster \
    --to=bfoster@redhat.com \
    --cc=darrick.wong@oracle.com \
    --cc=david@fromorbit.com \
    --cc=linux-xfs@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).