diff mbox series

[25/48] xfs_db: warn about suspicious finobt trees when metadumping

Message ID 164263832979.865554.11791034100178491501.stgit@magnolia (mailing list archive)
State Accepted
Headers show
Series xfsprogs: sync libxfs with 5.16 | expand

Commit Message

Darrick J. Wong Jan. 20, 2022, 12:25 a.m. UTC
From: Darrick J. Wong <djwong@kernel.org>

We warn about suspicious roots and btree heights before metadumping the
inode btree, so do the same for the free inode btree.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 db/metadump.c |   15 +++++++++++++++
 1 file changed, 15 insertions(+)
diff mbox series

Patch

diff --git a/db/metadump.c b/db/metadump.c
index cc7a4a55..af8b67d5 100644
--- a/db/metadump.c
+++ b/db/metadump.c
@@ -2664,6 +2664,21 @@  copy_inodes(
 		root = be32_to_cpu(agi->agi_free_root);
 		levels = be32_to_cpu(agi->agi_free_level);
 
+		if (root == 0 || root > mp->m_sb.sb_agblocks) {
+			if (show_warnings)
+				print_warning("invalid block number (%u) in "
+						"finobt root in agi %u", root,
+						agno);
+			return 1;
+		}
+
+		if (levels > XFS_BTREE_MAXLEVELS) {
+			if (show_warnings)
+				print_warning("invalid level (%u) in finobt "
+						"root in agi %u", levels, agno);
+			return 1;
+		}
+
 		finobt = 1;
 		if (!scan_btree(agno, root, levels, TYP_FINOBT, &finobt,
 				scanfunc_ino))