Skip to contentSkip to conversation

xfs: don't crash when read verifier reports errors with null b_ops

PATCH Superseded Darrick J. Wong 2 participants 5 messages Jan 15, 2019 – Jan 18, 2019 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: don't crash when read verifier reports errors with null b_ops

From: Darrick J. Wong <[email protected]>

In xrep_findroot_block, we work out the btree type and correctness of a given block by calling different btree verifiers on root block candidates. However, we leave the NULL b_ops while ->verify_read validates the block, which means that if the verifier calls xfs_buf_verifier_error it'll crash on the null b_ops. Fix it to avoid this crash.

---
FWIW I also thought about stuffing in a fake b_ops while xrep_findroot is calling a candidate read verifier, but thought that might just confuse things more?

---
 fs/xfs/xfs_error.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_error.c +1 -1
index 9866f542e77b..2a02be280769 100644
@@ -359,7 +359,7 @@ xfs_buf_verifier_error(
 
 	xfs_alert(mp, "Metadata %s detected at %pS, %s block 0x%llx %s",
 		  bp->b_error == -EFSBADCRC ? "CRC error" : "corruption",
-		  fa, bp->b_ops->name, bp->b_bn, name);
+		  fa, bp->b_ops ? bp->b_ops->name : "unknown", bp->b_bn, name);
 
 	xfs_alert(mp, "Unmount and run xfs_repair");
 
#1 lore raw
Quoted 23 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

In xrep_findroot_block, we work out the btree type and correctness of a given block by calling different btree verifiers on root block candidates. However, we leave the NULL b_ops while ->verify_read validates the block, which means that if the verifier calls xfs_buf_verifier_error it'll crash on the null b_ops. Fix it to avoid this crash.

---
FWIW I also thought about stuffing in a fake b_ops while xrep_findroot is calling a candidate read verifier, but thought that might just confuse things more?

---
 fs/xfs/xfs_error.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_error.c +0 -0
index 9866f542e77b..2a02be280769 100644

fs/xfs/xfs_error.c xfs_buf_verifier_error( · line 362

Quoted 5 lines
fs/xfs/xfs_error.c +1 -1
@@ -359,7 +359,7 @@ xfs_buf_verifier_error(
 
 	xfs_alert(mp, "Metadata %s detected at %pS, %s block 0x%llx %s",
 		  bp->b_error == -EFSBADCRC ? "CRC error" : "corruption",
-		  fa, bp->b_ops->name, bp->b_bn, name);
+		  fa, bp->b_ops ? bp->b_ops->name : "unknown", bp->b_bn, name);

Looks fine, but can you add a comment to xfs_buf_verifier_error() that says that some callers might be running the verifiers themselves rather than through the b_ops structure and so it may be null...

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#2 lore raw
Quoted 25 lines · Dave Chinner
Quoted 24 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

In xrep_findroot_block, we work out the btree type and correctness of a given block by calling different btree verifiers on root block candidates. However, we leave the NULL b_ops while ->verify_read validates the block, which means that if the verifier calls xfs_buf_verifier_error it'll crash on the null b_ops. Fix it to avoid this crash.

---
FWIW I also thought about stuffing in a fake b_ops while xrep_findroot is calling a candidate read verifier, but thought that might just confuse things more?

---
 fs/xfs/xfs_error.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_error.c +0 -0
index 9866f542e77b..2a02be280769 100644
@@ -359,7 +359,7 @@ xfs_buf_verifier_error(
 
Quoted 9 lines

fs/xfs/xfs_error.c xfs_buf_verifier_error( · line 362

Quoted 4 lines
fs/xfs/xfs_error.c +1 -1
 	xfs_alert(mp, "Metadata %s detected at %pS, %s block 0x%llx %s",
 		  bp->b_error == -EFSBADCRC ? "CRC error" : "corruption",
-		  fa, bp->b_ops->name, bp->b_bn, name);
+		  fa, bp->b_ops ? bp->b_ops->name : "unknown", bp->b_bn, name);

Looks fine, but can you add a comment to xfs_buf_verifier_error() that says that some callers might be running the verifiers themselves rather than through the b_ops structure and so it may be null...

Will do.

--D

Quoted 6 lines

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#3 lore raw

PATCH v2 1/1 xfs: don't crash when read verifier reports errors with null b_ops

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

In xrep_findroot_block, we work out the btree type and correctness of a given block by calling different btree verifiers on root block candidates. However, we leave the NULL b_ops while ->verify_read validates the block, which means that if the verifier calls xfs_buf_verifier_error it'll crash on the null b_ops. Fix it to avoid this crash.

---
v2: leave a comment about what we're doing above the function

---
 fs/xfs/xfs_error.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/xfs/xfs_error.c +4 -1
index 9866f542e77b..6e80e438b27a 100644
@@ -340,6 +340,9 @@ xfs_corruption_error(
 /*
  * Warnings specifically for verifier errors.  Differentiate CRC vs. invalid
  * values, and omit the stack trace unless the error level is tuned high.
+ *
+ * NOTE: Some callers might be calling the verifiers directly (rather than
+ * through the b_ops structure) so bp->b_ops may be NULL.
  */
 void
 xfs_buf_verifier_error(
@@ -359,7 +362,7 @@ xfs_buf_verifier_error(
 
 	xfs_alert(mp, "Metadata %s detected at %pS, %s block 0x%llx %s",
 		  bp->b_error == -EFSBADCRC ? "CRC error" : "corruption",
-		  fa, bp->b_ops->name, bp->b_bn, name);
+		  fa, bp->b_ops ? bp->b_ops->name : "unknown", bp->b_bn, name);
 
 	xfs_alert(mp, "Unmount and run xfs_repair");
 
Reviewed-by on v2 1/1
#4 lore raw
Quoted 9 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

In xrep_findroot_block, we work out the btree type and correctness of a given block by calling different btree verifiers on root block candidates. However, we leave the NULL b_ops while ->verify_read validates the block, which means that if the verifier calls xfs_buf_verifier_error it'll crash on the null b_ops. Fix it to avoid this crash.

Quoted 4 lines

---
v2: leave a comment about what we're doing above the function
---

Looks good now.

Signature · 2 lines
Dave Chinner
[email protected]