Skip to content

Commit

Permalink
xfs: check for bogus values in btree block headers
Browse files Browse the repository at this point in the history
When we're reading a btree block, make sure that what we retrieved
matches the owner and level; and has a plausible number of records.

Signed-off-by: Darrick J. Wong <[email protected]>
Reviewed-by: Dave Chinner <[email protected]>
Signed-off-by: Dave Chinner <[email protected]>
  • Loading branch information
djwong authored and dchinner committed Dec 5, 2016
1 parent d2a047f commit bb3be7e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions fs/xfs/libxfs/xfs_btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1769,8 +1769,28 @@ xfs_btree_lookup_get_block(
if (error)
return error;

/* Check the inode owner since the verifiers don't. */
if (xfs_sb_version_hascrc(&cur->bc_mp->m_sb) &&
(cur->bc_flags & XFS_BTREE_LONG_PTRS) &&
be64_to_cpu((*blkp)->bb_u.l.bb_owner) !=
cur->bc_private.b.ip->i_ino)
goto out_bad;

/* Did we get the level we were looking for? */
if (be16_to_cpu((*blkp)->bb_level) != level)
goto out_bad;

/* Check that internal nodes have at least one record. */
if (level != 0 && be16_to_cpu((*blkp)->bb_numrecs) == 0)
goto out_bad;

xfs_btree_setbuf(cur, level, bp);
return 0;

out_bad:
*blkp = NULL;
xfs_trans_brelse(cur->bc_tp, bp);
return -EFSCORRUPTED;
}

/*
Expand Down

0 comments on commit bb3be7e

Please sign in to comment.