From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Eric Sandeen <sandeen@sandeen.net>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH 3/7] xfs: filter out obviously bad btree pointers
Date: Tue, 31 Jan 2017 12:09:18 -0800 [thread overview]
Message-ID: <20170131200918.GH9134@birch.djwong.org> (raw)
In-Reply-To: <eabf5bb2-124e-5af9-5dbb-380bc85d8b13@sandeen.net>
On Mon, Jan 30, 2017 at 10:39:05PM -0600, Eric Sandeen wrote:
> On 1/30/17 6:23 PM, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> >
> > Don't let anybody load an obviously bad btree pointer. Since the values
> > come from disk, we must return an error, not just ASSERT.
> >
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > ---
> > fs/xfs/libxfs/xfs_bmap.c | 4 +---
> > fs/xfs/libxfs/xfs_btree.c | 3 ++-
> > fs/xfs/libxfs/xfs_btree.h | 2 +-
> > 3 files changed, 4 insertions(+), 5 deletions(-)
> >
> >
> > diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
> > index bfc00de..443cb10 100644
> > --- a/fs/xfs/libxfs/xfs_bmap.c
> > +++ b/fs/xfs/libxfs/xfs_bmap.c
> > @@ -1291,9 +1291,7 @@ xfs_bmap_read_extents(
> > ASSERT(level > 0);
> > pp = XFS_BMAP_BROOT_PTR_ADDR(mp, block, 1, ifp->if_broot_bytes);
> > bno = be64_to_cpu(*pp);
> > - ASSERT(bno != NULLFSBLOCK);
> > - ASSERT(XFS_FSB_TO_AGNO(mp, bno) < mp->m_sb.sb_agcount);
> > - ASSERT(XFS_FSB_TO_AGBNO(mp, bno) < mp->m_sb.sb_agblocks);
> > +
>
> fwiw there's an assignment of bno = NULLFSBLOCK just before here,
> which is never used and overwritten in this hunk.
> Could probably clean that up here too.
Yes, that could go too.
> > /*
> > * Go down the tree until leaf level is reached, following the first
> > * pointer (leftmost) at each level.
> > diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c
> > index 21e6a6a..2849d3f 100644
> > --- a/fs/xfs/libxfs/xfs_btree.c
> > +++ b/fs/xfs/libxfs/xfs_btree.c
> > @@ -810,7 +810,8 @@ xfs_btree_read_bufl(
> > xfs_daddr_t d; /* real disk block address */
> > int error;
> >
> > - ASSERT(fsbno != NULLFSBLOCK);
> > + if (!XFS_FSB_SANITY_CHECK(mp, fsbno))
> > + return -EFSCORRUPTED;
>
> This does away with the NULLFSBLOCK checks though, right?
>
> #define NULLFSBLOCK ((xfs_fsblock_t)-1)
>
> which is also used as an in-memory condition, so I'm not sure
> it should be added to XFS_FSB_SANITY_CHECK.
[reiterating our irc conversation]
It shouldn't, since XFS_FSB_TO_AGNO(mp, NULLFSBLOCK) ought to produce
NULLAGNUMBER, which will still fail the check.
> IOWs some asserts about it are really code flow asserts, though
> it also shouldn't be read from disk.
xfs_btree_read_bufl is called by xfs_bmap_check_leaf_extents, which is
the verifier of the on-disk data.
--D
> > d = XFS_FSB_TO_DADDR(mp, fsbno);
> > error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp, d,
> > mp->m_bsize, lock, &bp, ops);
> > diff --git a/fs/xfs/libxfs/xfs_btree.h b/fs/xfs/libxfs/xfs_btree.h
> > index b69b947..33a8f86 100644
> > --- a/fs/xfs/libxfs/xfs_btree.h
> > +++ b/fs/xfs/libxfs/xfs_btree.h
> > @@ -456,7 +456,7 @@ static inline int xfs_btree_get_level(struct xfs_btree_block *block)
> > #define XFS_FILBLKS_MAX(a,b) max_t(xfs_filblks_t, (a), (b))
> >
> > #define XFS_FSB_SANITY_CHECK(mp,fsb) \
> > - (XFS_FSB_TO_AGNO(mp, fsb) < mp->m_sb.sb_agcount && \
> > + (fsb && XFS_FSB_TO_AGNO(mp, fsb) < mp->m_sb.sb_agcount && \
> > XFS_FSB_TO_AGBNO(mp, fsb) < mp->m_sb.sb_agblocks)
> >
> > /*
> >
> > --
> > 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
> >
> --
> 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
next prev parent reply other threads:[~2017-01-31 20:10 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-31 0:23 [PATCH 0/7] xfs: random fixes Darrick J. Wong
2017-01-31 0:23 ` [PATCH 1/7] xfs: fix toctou race when locking an inode to access the data map Darrick J. Wong
2017-01-31 3:01 ` Eric Sandeen
2017-01-31 13:26 ` Christoph Hellwig
2017-01-31 19:45 ` Darrick J. Wong
2017-01-31 21:40 ` Darrick J. Wong
2017-02-01 2:34 ` [PATCH v2 " Darrick J. Wong
2017-02-01 14:48 ` Christoph Hellwig
2017-01-31 0:23 ` [PATCH 2/7] xfs: fail _dir_open when readahead fails Darrick J. Wong
2017-01-31 4:12 ` Eric Sandeen
2017-01-31 13:29 ` Christoph Hellwig
2017-01-31 0:23 ` [PATCH 3/7] xfs: filter out obviously bad btree pointers Darrick J. Wong
2017-01-31 4:39 ` Eric Sandeen
2017-01-31 20:09 ` Darrick J. Wong [this message]
2017-01-31 20:37 ` Eric Sandeen
2017-01-31 0:23 ` [PATCH 4/7] xfs: check for obviously bad level values in the bmbt root Darrick J. Wong
2017-01-31 13:31 ` Christoph Hellwig
2017-01-31 0:23 ` [PATCH 5/7] xfs: verify free block header fields Darrick J. Wong
2017-01-31 13:42 ` Christoph Hellwig
2017-01-31 0:23 ` [PATCH 6/7] xfs: allow unwritten extents in the CoW fork Darrick J. Wong
2017-02-01 2:35 ` [PATCH v2 " Darrick J. Wong
2017-02-01 18:06 ` Christoph Hellwig
2017-01-31 0:23 ` [PATCH 7/7] xfs: mark speculative prealloc CoW fork extents unwritten Darrick J. Wong
2017-01-31 13:41 ` Christoph Hellwig
2017-01-31 19:11 ` Darrick J. Wong
2017-02-01 1:28 ` Darrick J. Wong
2017-02-01 2:36 ` [PATCH v2 " Darrick J. Wong
2017-02-01 18:36 ` Christoph Hellwig
2017-02-02 15:04 ` Brian Foster
2017-02-02 17:04 ` Darrick J. Wong
2017-02-02 19:42 ` Brian Foster
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=20170131200918.GH9134@birch.djwong.org \
--to=darrick.wong@oracle.com \
--cc=linux-xfs@vger.kernel.org \
--cc=sandeen@sandeen.net \
/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).