xfs: don't perform lookups on zero-height btrees
authorDarrick J. Wong <darrick.wong@oracle.com>
Fri, 26 Aug 2016 05:58:40 +0000 (15:58 +1000)
committerDave Chinner <david@fromorbit.com>
Fri, 26 Aug 2016 05:58:40 +0000 (15:58 +1000)
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>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
fs/xfs/libxfs/xfs_btree.c

index b5c213a051cde3f703227f10b73e367470a4df43..33f14067c3202b461c44ae523eeaa991990ace20 100644 (file)
@@ -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;