Skip to content

Commit d477f17

Browse files
Christoph HellwigDarrick J. Wong
authored andcommitted
xfs: tighten up validation of root block in inode forks
Check that root blocks that sit in the inode fork and thus have a NULL bp don't have siblings. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
1 parent bd45019 commit d477f17

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

fs/xfs/libxfs/xfs_btree.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ __xfs_btree_check_lblock(
107107
{
108108
struct xfs_mount *mp = cur->bc_mp;
109109
xfs_failaddr_t fa;
110-
xfs_fsblock_t fsb = NULLFSBLOCK;
110+
xfs_fsblock_t fsb;
111111

112112
if (xfs_has_crc(mp)) {
113113
if (!uuid_equal(&block->bb_u.l.bb_uuid, &mp->m_sb.sb_meta_uuid))
@@ -127,9 +127,19 @@ __xfs_btree_check_lblock(
127127
cur->bc_ops->get_maxrecs(cur, level))
128128
return __this_address;
129129

130-
if (bp)
131-
fsb = XFS_DADDR_TO_FSB(mp, xfs_buf_daddr(bp));
130+
/*
131+
* For inode-rooted btrees, the root block sits in the inode fork. In
132+
* that case bp is NULL, and the block must not have any siblings.
133+
*/
134+
if (!bp) {
135+
if (block->bb_u.l.bb_leftsib != cpu_to_be64(NULLFSBLOCK))
136+
return __this_address;
137+
if (block->bb_u.l.bb_rightsib != cpu_to_be64(NULLFSBLOCK))
138+
return __this_address;
139+
return NULL;
140+
}
132141

142+
fsb = XFS_DADDR_TO_FSB(mp, xfs_buf_daddr(bp));
133143
fa = xfs_btree_check_lblock_siblings(mp, fsb, block->bb_u.l.bb_leftsib);
134144
if (!fa)
135145
fa = xfs_btree_check_lblock_siblings(mp, fsb,

0 commit comments

Comments
 (0)