public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Brian Foster <bfoster@redhat.com>
Cc: linux-xfs@vger.kernel.org, xfs@oss.sgi.com
Subject: Re: [PATCH] xfs: don't perform lookups on zero-height btrees
Date: Wed, 24 Aug 2016 13:39:33 -0700	[thread overview]
Message-ID: <20160824203933.GA20705@birch.djwong.org> (raw)
In-Reply-To: <20160824180154.GA8982@bfoster.bfoster>

On Wed, Aug 24, 2016 at 02:01:55PM -0400, Brian Foster wrote:
> On Fri, Aug 19, 2016 at 01:30:22PM -0700, Darrick J. Wong wrote:
> > If the caller passes in a cursor to a zero-height btree (which is
> > impossible), we never set block to anything but NULL, which causes the
> > later dereference of it to crash.  Instead, just return -EFSCORRUPTED.
> > 
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > ---
> 
> Did something actually cause this to happen?

Well, if you took a reflink xfs that was formatted before we added the
rmap/refcount btree block counters to the AGF and then tried to mount
it after will blow up like this, because the refcount_level field got
moved to somewhere that's zero in the old image.

Anyone being malicious with xfs_db can also do this to any other _level field.

(Yay automounting!)

--D

> 
> Brian
> 
> >  fs/xfs/libxfs/xfs_btree.c |    4 ++++
> >  1 file changed, 4 insertions(+)
> > 
> > diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c
> > index 64fd847..4bffea4 100644
> > --- a/fs/xfs/libxfs/xfs_btree.c
> > +++ b/fs/xfs/libxfs/xfs_btree.c
> > @@ -1814,6 +1814,10 @@ xfs_btree_lookup(
> >  
> >  	XFS_BTREE_STATS_INC(cur, lookup);
> >  
> > +	/* No such thing as a zero-level tree. */
> > +	if (cur->bc_nlevels == 0)
> > +		return -EFSCORRUPTED;
> > +
> >  	block = NULL;
> >  	keyno = 0;
> >  
> > 
> > _______________________________________________
> > xfs mailing list
> > xfs@oss.sgi.com
> > http://oss.sgi.com/mailman/listinfo/xfs

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

  reply	other threads:[~2016-08-24 20:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-19 20:30 [PATCH] xfs: don't perform lookups on zero-height btrees Darrick J. Wong
2016-08-24 18:01 ` Brian Foster
2016-08-24 20:39   ` Darrick J. Wong [this message]
2016-08-25  8:04 ` Christoph Hellwig

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=20160824203933.GA20705@birch.djwong.org \
    --to=darrick.wong@oracle.com \
    --cc=bfoster@redhat.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=xfs@oss.sgi.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