xfs: don't crash when read verifier reports errors with null b_ops
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
@@ -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" );
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 NULLb_opswhile ->verify_read validates the block, which means that if the verifier callsxfs_buf_verifier_errorit'll crash on the nullb_ops. Fix it to avoid this crash.Signed-off-by Darrick J. Wong <[email protected]>---
FWIW I also thought about stuffing in a fakeb_opswhilexrep_findrootis 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
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]
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 NULLb_opswhile ->verify_read validates the block, which means that if the verifier callsxfs_buf_verifier_errorit'll crash on the nullb_ops. Fix it to avoid this crash.Signed-off-by Darrick J. Wong <[email protected]>---
FWIW I also thought about stuffing in a fakeb_opswhilexrep_findrootis 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@@ -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
-1xfs_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 theb_opsstructure and so it may be null...
Will do.
--D
Quoted 6 lines
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
PATCH v2 1/1 xfs: don't crash when read verifier reports errors with null b_ops
In reply to Darrick J. WongFrom: 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
@@ -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" );
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 NULLb_opswhile ->verify_read validates the block, which means that if the verifier callsxfs_buf_verifier_errorit'll crash on the nullb_ops. Fix it to avoid this crash.
Quoted 4 lines
Signed-off-by Darrick J. Wong <[email protected]>---
v2: leave a comment about what we're doing above the function
---
Looks good now.
Signature · 2 lines
Dave Chinner [email protected]