Skip to content

Commit 0a2426a

Browse files
committed
Verify BPs as part of spa_load_verify_cb()
We want `zpool import` to be highly robust and never panic, even when encountering corrupt metadata. This is already handled in the arc_read() code path, which covers most cases, but spa_load_verify_cb() relies on zio_read() and is responsible for verifying the block pointer. Furthermore, during import it's possible to encounter blocks pointers which contain ZIO_COMPRESS_INHERIT and ZIO_CHECKSUM_INHERIT. The verification function has been updated to allow these values. Signed-off-by: Brian Behlendorf <[email protected]>
1 parent 276b08c commit 0a2426a

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

module/zfs/spa.c

+16-3
Original file line numberDiff line numberDiff line change
@@ -2310,16 +2310,29 @@ spa_load_verify_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
23102310

23112311
(void) zilog, (void) dnp;
23122312

2313-
if (zb->zb_level == ZB_DNODE_LEVEL || BP_IS_HOLE(bp) ||
2314-
BP_IS_EMBEDDED(bp) || BP_IS_REDACTED(bp))
2315-
return (0);
23162313
/*
23172314
* Note: normally this routine will not be called if
23182315
* spa_load_verify_metadata is not set. However, it may be useful
23192316
* to manually set the flag after the traversal has begun.
23202317
*/
23212318
if (!spa_load_verify_metadata)
23222319
return (0);
2320+
2321+
/*
2322+
* Sanity check the block pointer in order to detect obvious damage
2323+
* before using the contents in subsequent checks or in zio_read().
2324+
* When damaged consider it to be a metadata error since we cannot
2325+
* trust the BP_GET_TYPE and BP_GET_LEVEL values.
2326+
*/
2327+
if (!zfs_blkptr_verify(spa, bp, B_FALSE, BLK_VERIFY_LOG)) {
2328+
atomic_inc_64(&sle->sle_meta_count);
2329+
return (0);
2330+
}
2331+
2332+
if (zb->zb_level == ZB_DNODE_LEVEL || BP_IS_HOLE(bp) ||
2333+
BP_IS_EMBEDDED(bp) || BP_IS_REDACTED(bp))
2334+
return (0);
2335+
23232336
if (!BP_IS_METADATA(bp) &&
23242337
(!spa_load_verify_data || !sle->sle_verify_data))
23252338
return (0);

module/zfs/zio.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -962,14 +962,12 @@ zfs_blkptr_verify(spa_t *spa, const blkptr_t *bp, boolean_t config_held,
962962
"blkptr at %p has invalid TYPE %llu",
963963
bp, (longlong_t)BP_GET_TYPE(bp));
964964
}
965-
if (BP_GET_CHECKSUM(bp) >= ZIO_CHECKSUM_FUNCTIONS ||
966-
BP_GET_CHECKSUM(bp) <= ZIO_CHECKSUM_ON) {
965+
if (BP_GET_CHECKSUM(bp) >= ZIO_CHECKSUM_FUNCTIONS) {
967966
errors += zfs_blkptr_verify_log(spa, bp, blk_verify,
968967
"blkptr at %p has invalid CHECKSUM %llu",
969968
bp, (longlong_t)BP_GET_CHECKSUM(bp));
970969
}
971-
if (BP_GET_COMPRESS(bp) >= ZIO_COMPRESS_FUNCTIONS ||
972-
BP_GET_COMPRESS(bp) <= ZIO_COMPRESS_ON) {
970+
if (BP_GET_COMPRESS(bp) >= ZIO_COMPRESS_FUNCTIONS) {
973971
errors += zfs_blkptr_verify_log(spa, bp, blk_verify,
974972
"blkptr at %p has invalid COMPRESS %llu",
975973
bp, (longlong_t)BP_GET_COMPRESS(bp));

0 commit comments

Comments
 (0)