Skip to content

Commit 2207041

Browse files
djwonggregkh
authored andcommitted
xfs: make sure the rt allocator doesn't run off the end
[ Upstream commit 2a6ca4b ] There's an overflow bug in the realtime allocator. If the rt volume is large enough to handle a single allocation request that is larger than the maximum bmap extent length and the rt bitmap ends exactly on a bitmap block boundary, it's possible that the near allocator will try to check the freeness of a range that extends past the end of the bitmap. This fails with a corruption error and shuts down the fs. Therefore, constrain maxlen so that the range scan cannot run off the end of the rt bitmap. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 1024e69 commit 2207041

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

fs/xfs/xfs_rtalloc.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ xfs_rtallocate_extent_block(
247247
end = XFS_BLOCKTOBIT(mp, bbno + 1) - 1;
248248
i <= end;
249249
i++) {
250+
/* Make sure we don't scan off the end of the rt volume. */
251+
maxlen = min(mp->m_sb.sb_rextents, i + maxlen) - i;
252+
250253
/*
251254
* See if there's a free extent of maxlen starting at i.
252255
* If it's not so then next will contain the first non-free.
@@ -442,6 +445,14 @@ xfs_rtallocate_extent_near(
442445
*/
443446
if (bno >= mp->m_sb.sb_rextents)
444447
bno = mp->m_sb.sb_rextents - 1;
448+
449+
/* Make sure we don't run off the end of the rt volume. */
450+
maxlen = min(mp->m_sb.sb_rextents, bno + maxlen) - bno;
451+
if (maxlen < minlen) {
452+
*rtblock = NULLRTBLOCK;
453+
return 0;
454+
}
455+
445456
/*
446457
* Try the exact allocation first.
447458
*/

0 commit comments

Comments
 (0)