Blame SOURCES/xfsprogs-5.7.0-xfs_repair-complain-about-bad-interior-btree-pointer.patch

48cf7c
From 320cc3b263542e692c4978fb327efa591892ab37 Mon Sep 17 00:00:00 2001
48cf7c
From: "Darrick J. Wong" <darrick.wong@oracle.com>
48cf7c
Date: Fri, 10 Jul 2020 15:35:45 -0400
48cf7c
Subject: [PATCH] xfs_repair: complain about bad interior btree pointers
48cf7c
48cf7c
Actually complain about garbage btree node pointers, don't just silently
48cf7c
ignore them.
48cf7c
48cf7c
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
48cf7c
Reviewed-by: Christoph Hellwig <hch@lst.de>
48cf7c
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
48cf7c
---
48cf7c
 libxfs/libxfs_api_defs.h |  1 +
48cf7c
 repair/scan.c            | 55 +++++++++++++++++++++++++++++-----------
48cf7c
 2 files changed, 41 insertions(+), 15 deletions(-)
48cf7c
48cf7c
Index: xfsprogs-5.0.0/libxfs/libxfs_api_defs.h
48cf7c
===================================================================
48cf7c
--- xfsprogs-5.0.0.orig/libxfs/libxfs_api_defs.h
48cf7c
+++ xfsprogs-5.0.0/libxfs/libxfs_api_defs.h
48cf7c
@@ -118,6 +118,7 @@
48cf7c
 #define xfs_symlink_blocks		libxfs_symlink_blocks
48cf7c
 #define xfs_symlink_hdr_ok		libxfs_symlink_hdr_ok
48cf7c
 
48cf7c
+#define xfs_verify_agbno		libxfs_verify_agbno
48cf7c
 #define xfs_verify_cksum		libxfs_verify_cksum
48cf7c
 #define xfs_dinode_verify		libxfs_dinode_verify
48cf7c
 
48cf7c
Index: xfsprogs-5.0.0/repair/scan.c
48cf7c
===================================================================
48cf7c
--- xfsprogs-5.0.0.orig/repair/scan.c
48cf7c
+++ xfsprogs-5.0.0/repair/scan.c
48cf7c
@@ -743,6 +743,14 @@ _("%s freespace btree block claimed (sta
48cf7c
 	for (i = 0; i < numrecs; i++)  {
48cf7c
 		xfs_agblock_t		agbno = be32_to_cpu(pp[i]);
48cf7c
 
48cf7c
+		if (!libxfs_verify_agbno(mp, agno, agbno)) {
48cf7c
+			do_warn(
48cf7c
+	_("bad btree pointer (%u) in %sbt block %u/%u\n"),
48cf7c
+				agbno, name, agno, bno);
48cf7c
+			suspect++;
48cf7c
+			return;
48cf7c
+		}
48cf7c
+
48cf7c
 		/*
48cf7c
 		 * XXX - put sibling detection right here.
48cf7c
 		 * we know our sibling chain is good.  So as we go,
48cf7c
@@ -752,10 +760,8 @@ _("%s freespace btree block claimed (sta
48cf7c
 		 * pointer mismatch, try and extract as much data
48cf7c
 		 * as possible.
48cf7c
 		 */
48cf7c
-		if (agbno != 0 && verify_agbno(mp, agno, agbno)) {
48cf7c
-			scan_sbtree(agbno, level, agno, suspect, scan_allocbt,
48cf7c
-				    0, magic, priv, ops);
48cf7c
-		}
48cf7c
+		scan_sbtree(agbno, level, agno, suspect, scan_allocbt, 0,
48cf7c
+				magic, priv, ops);
48cf7c
 	}
48cf7c
 }
48cf7c
 
48cf7c
@@ -1196,10 +1202,16 @@ advance:
48cf7c
 			continue;
48cf7c
 		}
48cf7c
 
48cf7c
-		if (agbno != 0 && verify_agbno(mp, agno, agbno)) {
48cf7c
-			scan_sbtree(agbno, level, agno, suspect, scan_rmapbt, 0,
48cf7c
-				    magic, priv, ops);
48cf7c
+		if (!libxfs_verify_agbno(mp, agno, agbno)) {
48cf7c
+			do_warn(
48cf7c
+	_("bad btree pointer (%u) in %sbt block %u/%u\n"),
48cf7c
+				agbno, name, agno, bno);
48cf7c
+			suspect++;
48cf7c
+			return;
48cf7c
 		}
48cf7c
+
48cf7c
+		scan_sbtree(agbno, level, agno, suspect, scan_rmapbt, 0, magic,
48cf7c
+				priv, ops);
48cf7c
 	}
48cf7c
 
48cf7c
 out:
48cf7c
@@ -1416,10 +1428,16 @@ _("extent (%u/%u) len %u claimed, state
48cf7c
 	for (i = 0; i < numrecs; i++)  {
48cf7c
 		xfs_agblock_t		agbno = be32_to_cpu(pp[i]);
48cf7c
 
48cf7c
-		if (agbno != 0 && verify_agbno(mp, agno, agbno)) {
48cf7c
-			scan_sbtree(agbno, level, agno, suspect, scan_refcbt, 0,
48cf7c
-				    magic, priv, ops);
48cf7c
+		if (!libxfs_verify_agbno(mp, agno, agbno)) {
48cf7c
+			do_warn(
48cf7c
+	_("bad btree pointer (%u) in %sbt block %u/%u\n"),
48cf7c
+				agbno, name, agno, bno);
48cf7c
+			suspect++;
48cf7c
+			return;
48cf7c
 		}
48cf7c
+
48cf7c
+		scan_sbtree(agbno, level, agno, suspect, scan_refcbt, 0, magic,
48cf7c
+				priv, ops);
48cf7c
 	}
48cf7c
 out:
48cf7c
 	if (suspect)
48cf7c
@@ -2083,11 +2101,18 @@ _("inode btree block claimed (state %d),
48cf7c
 	}
48cf7c
 
48cf7c
 	for (i = 0; i < numrecs; i++)  {
48cf7c
-		if (be32_to_cpu(pp[i]) != 0 && verify_agbno(mp, agno,
48cf7c
-							be32_to_cpu(pp[i])))
48cf7c
-			scan_sbtree(be32_to_cpu(pp[i]), level, agno,
48cf7c
-					suspect, scan_inobt, 0, magic, priv,
48cf7c
-					ops);
48cf7c
+		xfs_agblock_t	agbno = be32_to_cpu(pp[i]);
48cf7c
+
48cf7c
+		if (!libxfs_verify_agbno(mp, agno, agbno)) {
48cf7c
+			do_warn(
48cf7c
+	_("bad btree pointer (%u) in %sbt block %u/%u\n"),
48cf7c
+				agbno, name, agno, bno);
48cf7c
+			suspect++;
48cf7c
+			return;
48cf7c
+		}
48cf7c
+
48cf7c
+		scan_sbtree(be32_to_cpu(pp[i]), level, agno, suspect,
48cf7c
+				scan_inobt, 0, magic, priv, ops);
48cf7c
 	}
48cf7c
 }
48cf7c