Commit 2c33d690 authored by Darrick J. Wong's avatar Darrick J. Wong Committed by Long Li
Browse files

xfs: fix maxlevels comparisons in the btree staging code

mainline inclusion
from mainline-v5.15-rc4
commit 78e8ec83
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I76JSK
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=78e8ec83a404d63dcc86b251f42e4ee8aff27465



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

The btree geometry computation function has an off-by-one error in that
it does not allow maximally tall btrees (nlevels == XFS_BTREE_MAXLEVELS).
This can result in repairs failing unnecessarily on very fragmented
filesystems.  Subsequent patches to remove MAXLEVELS usage in favor of
the per-btree type computations will make this a much more likely
occurrence.

Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
Reviewed-by: default avatarChandan Babu R <chandan.babu@oracle.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarGuo Xuenan <guoxuenan@huawei.com>
Signed-off-by: default avatarLong Li <leo.lilong@huawei.com>
parent 8321d47f
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -663,7 +663,7 @@ xfs_btree_bload_compute_geometry(
	xfs_btree_bload_ensure_slack(cur, &bbl->node_slack, 1);

	bbl->nr_records = nr_this_level = nr_records;
	for (cur->bc_nlevels = 1; cur->bc_nlevels < XFS_BTREE_MAXLEVELS;) {
	for (cur->bc_nlevels = 1; cur->bc_nlevels <= XFS_BTREE_MAXLEVELS;) {
		uint64_t	level_blocks;
		uint64_t	dontcare64;
		unsigned int	level = cur->bc_nlevels - 1;
@@ -725,7 +725,7 @@ xfs_btree_bload_compute_geometry(
		nr_this_level = level_blocks;
	}

	if (cur->bc_nlevels == XFS_BTREE_MAXLEVELS)
	if (cur->bc_nlevels > XFS_BTREE_MAXLEVELS)
		return -EOVERFLOW;

	bbl->btree_height = cur->bc_nlevels;