linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xfs: fix use after free in buf log item unlock assert
@ 2019-02-06 16:01 Brian Foster
  2019-02-06 16:10 ` Darrick J. Wong
  2019-03-29 14:03 ` Brian Foster
  0 siblings, 2 replies; 4+ messages in thread
From: Brian Foster @ 2019-02-06 16:01 UTC (permalink / raw)
  To: linux-xfs

The xfs_buf_log_item ->iop_unlock() callback asserts that the buffer
is unlocked when either non-stale or aborted. This assert occurs
after the bli refcount has been dropped and the log item potentially
freed. The aborted check is thus a potential use after free. This
problem has been reproduced with KASAN enabled via generic/475.

Fix up xfs_buf_item_unlock() to query aborted state before the bli
reference is dropped to prevent a potential use after free.

Signed-off-by: Brian Foster <bfoster@redhat.com>
---
 fs/xfs/xfs_buf_item.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/xfs/xfs_buf_item.c b/fs/xfs/xfs_buf_item.c
index 010db5f8fb00..65b32acfa0f6 100644
--- a/fs/xfs/xfs_buf_item.c
+++ b/fs/xfs/xfs_buf_item.c
@@ -605,6 +605,8 @@ xfs_buf_item_unlock(
 #if defined(DEBUG) || defined(XFS_WARN)
 	bool			ordered = bip->bli_flags & XFS_BLI_ORDERED;
 	bool			dirty = bip->bli_flags & XFS_BLI_DIRTY;
+	bool			aborted = test_bit(XFS_LI_ABORTED,
+						   &lip->li_flags);
 #endif
 
 	trace_xfs_buf_item_unlock(bip);
@@ -633,7 +635,7 @@ xfs_buf_item_unlock(
 	released = xfs_buf_item_put(bip);
 	if (hold || (stale && !released))
 		return;
-	ASSERT(!stale || test_bit(XFS_LI_ABORTED, &lip->li_flags));
+	ASSERT(!stale || aborted);
 	xfs_buf_relse(bp);
 }
 
-- 
2.17.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] xfs: fix use after free in buf log item unlock assert
  2019-02-06 16:01 [PATCH] xfs: fix use after free in buf log item unlock assert Brian Foster
@ 2019-02-06 16:10 ` Darrick J. Wong
  2019-03-29 14:03 ` Brian Foster
  1 sibling, 0 replies; 4+ messages in thread
From: Darrick J. Wong @ 2019-02-06 16:10 UTC (permalink / raw)
  To: Brian Foster; +Cc: linux-xfs

On Wed, Feb 06, 2019 at 11:01:07AM -0500, Brian Foster wrote:
> The xfs_buf_log_item ->iop_unlock() callback asserts that the buffer
> is unlocked when either non-stale or aborted. This assert occurs
> after the bli refcount has been dropped and the log item potentially
> freed. The aborted check is thus a potential use after free. This
> problem has been reproduced with KASAN enabled via generic/475.
> 
> Fix up xfs_buf_item_unlock() to query aborted state before the bli
> reference is dropped to prevent a potential use after free.
> 
> Signed-off-by: Brian Foster <bfoster@redhat.com>

Seems reasonable,
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

--D

> ---
>  fs/xfs/xfs_buf_item.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/xfs/xfs_buf_item.c b/fs/xfs/xfs_buf_item.c
> index 010db5f8fb00..65b32acfa0f6 100644
> --- a/fs/xfs/xfs_buf_item.c
> +++ b/fs/xfs/xfs_buf_item.c
> @@ -605,6 +605,8 @@ xfs_buf_item_unlock(
>  #if defined(DEBUG) || defined(XFS_WARN)
>  	bool			ordered = bip->bli_flags & XFS_BLI_ORDERED;
>  	bool			dirty = bip->bli_flags & XFS_BLI_DIRTY;
> +	bool			aborted = test_bit(XFS_LI_ABORTED,
> +						   &lip->li_flags);
>  #endif
>  
>  	trace_xfs_buf_item_unlock(bip);
> @@ -633,7 +635,7 @@ xfs_buf_item_unlock(
>  	released = xfs_buf_item_put(bip);
>  	if (hold || (stale && !released))
>  		return;
> -	ASSERT(!stale || test_bit(XFS_LI_ABORTED, &lip->li_flags));
> +	ASSERT(!stale || aborted);
>  	xfs_buf_relse(bp);
>  }
>  
> -- 
> 2.17.2
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] xfs: fix use after free in buf log item unlock assert
  2019-02-06 16:01 [PATCH] xfs: fix use after free in buf log item unlock assert Brian Foster
  2019-02-06 16:10 ` Darrick J. Wong
@ 2019-03-29 14:03 ` Brian Foster
  2019-03-29 14:13   ` Darrick J. Wong
  1 sibling, 1 reply; 4+ messages in thread
From: Brian Foster @ 2019-03-29 14:03 UTC (permalink / raw)
  To: linux-xfs

On Wed, Feb 06, 2019 at 11:01:07AM -0500, Brian Foster wrote:
> The xfs_buf_log_item ->iop_unlock() callback asserts that the buffer
> is unlocked when either non-stale or aborted. This assert occurs
> after the bli refcount has been dropped and the log item potentially
> freed. The aborted check is thus a potential use after free. This
> problem has been reproduced with KASAN enabled via generic/475.
> 
> Fix up xfs_buf_item_unlock() to query aborted state before the bli
> reference is dropped to prevent a potential use after free.
> 
> Signed-off-by: Brian Foster <bfoster@redhat.com>
> ---

Ping on this one.. looks like it was reviewed and maybe fell through the
cracks?

Brian

>  fs/xfs/xfs_buf_item.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/xfs/xfs_buf_item.c b/fs/xfs/xfs_buf_item.c
> index 010db5f8fb00..65b32acfa0f6 100644
> --- a/fs/xfs/xfs_buf_item.c
> +++ b/fs/xfs/xfs_buf_item.c
> @@ -605,6 +605,8 @@ xfs_buf_item_unlock(
>  #if defined(DEBUG) || defined(XFS_WARN)
>  	bool			ordered = bip->bli_flags & XFS_BLI_ORDERED;
>  	bool			dirty = bip->bli_flags & XFS_BLI_DIRTY;
> +	bool			aborted = test_bit(XFS_LI_ABORTED,
> +						   &lip->li_flags);
>  #endif
>  
>  	trace_xfs_buf_item_unlock(bip);
> @@ -633,7 +635,7 @@ xfs_buf_item_unlock(
>  	released = xfs_buf_item_put(bip);
>  	if (hold || (stale && !released))
>  		return;
> -	ASSERT(!stale || test_bit(XFS_LI_ABORTED, &lip->li_flags));
> +	ASSERT(!stale || aborted);
>  	xfs_buf_relse(bp);
>  }
>  
> -- 
> 2.17.2
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] xfs: fix use after free in buf log item unlock assert
  2019-03-29 14:03 ` Brian Foster
@ 2019-03-29 14:13   ` Darrick J. Wong
  0 siblings, 0 replies; 4+ messages in thread
From: Darrick J. Wong @ 2019-03-29 14:13 UTC (permalink / raw)
  To: Brian Foster; +Cc: linux-xfs

On Fri, Mar 29, 2019 at 10:03:28AM -0400, Brian Foster wrote:
> On Wed, Feb 06, 2019 at 11:01:07AM -0500, Brian Foster wrote:
> > The xfs_buf_log_item ->iop_unlock() callback asserts that the buffer
> > is unlocked when either non-stale or aborted. This assert occurs
> > after the bli refcount has been dropped and the log item potentially
> > freed. The aborted check is thus a potential use after free. This
> > problem has been reproduced with KASAN enabled via generic/475.
> > 
> > Fix up xfs_buf_item_unlock() to query aborted state before the bli
> > reference is dropped to prevent a potential use after free.
> > 
> > Signed-off-by: Brian Foster <bfoster@redhat.com>
> > ---
> 
> Ping on this one.. looks like it was reviewed and maybe fell through the
> cracks?

Yep.  Spreadsheet says it's in 5.0-rc6, and ... totally not upstream. :(
Sorry about that.

--D

> Brian
> 
> >  fs/xfs/xfs_buf_item.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/fs/xfs/xfs_buf_item.c b/fs/xfs/xfs_buf_item.c
> > index 010db5f8fb00..65b32acfa0f6 100644
> > --- a/fs/xfs/xfs_buf_item.c
> > +++ b/fs/xfs/xfs_buf_item.c
> > @@ -605,6 +605,8 @@ xfs_buf_item_unlock(
> >  #if defined(DEBUG) || defined(XFS_WARN)
> >  	bool			ordered = bip->bli_flags & XFS_BLI_ORDERED;
> >  	bool			dirty = bip->bli_flags & XFS_BLI_DIRTY;
> > +	bool			aborted = test_bit(XFS_LI_ABORTED,
> > +						   &lip->li_flags);
> >  #endif
> >  
> >  	trace_xfs_buf_item_unlock(bip);
> > @@ -633,7 +635,7 @@ xfs_buf_item_unlock(
> >  	released = xfs_buf_item_put(bip);
> >  	if (hold || (stale && !released))
> >  		return;
> > -	ASSERT(!stale || test_bit(XFS_LI_ABORTED, &lip->li_flags));
> > +	ASSERT(!stale || aborted);
> >  	xfs_buf_relse(bp);
> >  }
> >  
> > -- 
> > 2.17.2
> > 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-03-29 14:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-06 16:01 [PATCH] xfs: fix use after free in buf log item unlock assert Brian Foster
2019-02-06 16:10 ` Darrick J. Wong
2019-03-29 14:03 ` Brian Foster
2019-03-29 14:13   ` Darrick J. Wong

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).