Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1617797

[PATCH 4.9 10/72] xfs: filter out obviously bad btree pointers

From Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Newsgroups linux.kernel
Subject [PATCH 4.9 10/72] xfs: filter out obviously bad btree pointers
Date 2017-04-06 11:40 +0200
Message-ID <ttc3w-6L0-31@gated-at.bofh.it> (permalink)
References <ttbh7-6aP-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


4.9-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Darrick J. Wong <darrick.wong@oracle.com>

commit d5a91baeb6033c3392121e4d5c011cdc08dfa9f7 upstream.

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>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 fs/xfs/libxfs/xfs_bmap.c  |    5 +----
 fs/xfs/libxfs/xfs_btree.c |    3 ++-
 fs/xfs/libxfs/xfs_btree.h |    2 +-
 3 files changed, 4 insertions(+), 6 deletions(-)

--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -1278,7 +1278,6 @@ xfs_bmap_read_extents(
 	/* REFERENCED */
 	xfs_extnum_t		room;	/* number of entries there's room for */
 
-	bno = NULLFSBLOCK;
 	mp = ip->i_mount;
 	ifp = XFS_IFORK_PTR(ip, whichfork);
 	exntf = (whichfork != XFS_DATA_FORK) ? XFS_EXTFMT_NOSTATE :
@@ -1291,9 +1290,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);
+
 	/*
 	 * Go down the tree until leaf level is reached, following the first
 	 * pointer (leftmost) at each level.
--- 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;
 	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);
--- a/fs/xfs/libxfs/xfs_btree.h
+++ b/fs/xfs/libxfs/xfs_btree.h
@@ -491,7 +491,7 @@ static inline int xfs_btree_get_level(st
 #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)
 
 /*

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 4.9 00/72] 4.9.21-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-04-06 11:30 +0200
  [PATCH 4.9 24/72] xfs: tune down agno asserts in the bmap code Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-04-06 11:30 +0200
  [PATCH 4.9 07/72] xfs: fix eofblocks race with file extending async dio writes Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-04-06 11:40 +0200
  [PATCH 4.9 10/72] xfs: filter out obviously bad btree pointers Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-04-06 11:40 +0200
  [PATCH 4.9 01/72] libceph: force GFP_NOIO for socket allocations Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-04-06 11:40 +0200
  [PATCH 4.9 05/72] xfs: pull up iolock from xfs_free_eofblocks() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-04-06 11:40 +0200
  [PATCH 4.9 06/72] xfs: sync eofblocks scans under iolock are livelock prone Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-04-06 11:40 +0200
  Re: [PATCH 4.9 00/72] 4.9.21-stable review Shuah Khan <shuahkh@osg.samsung.com> - 2017-04-06 19:50 +0200
  Re: [PATCH 4.9 00/72] 4.9.21-stable review Guenter Roeck <linux@roeck-us.net> - 2017-04-07 00:00 +0200

csiph-web