Verify embedded blkptr's in arc_read()

The block pointer verification check in arc_read() should also
cover embedded block pointers.  While highly unlikely, accessing
a damaged block pointer can result in panic.  To further harden
the code extend the existing check to include embedded block
pointers and add a comment explaining the rational for this
sanity check.  Lastly, correct a flaw in zfs_blkptr_verify()
so the error count is checked even when checking a untrusted
config to verify the non-pool-specific portions of a block
pointer.

Reviewed-by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Tony Nguyen <tony.nguyen@delphix.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #12535
This commit is contained in:
Brian Behlendorf 2021-09-09 18:02:07 -07:00 committed by Tony Hutter
parent 32512acbc0
commit 9183321501
2 changed files with 14 additions and 7 deletions

View File

@ -5917,17 +5917,24 @@ arc_read(zio_t *pio, spa_t *spa, const blkptr_t *bp,
*/ */
fstrans_cookie_t cookie = spl_fstrans_mark(); fstrans_cookie_t cookie = spl_fstrans_mark();
top: top:
/*
* Verify the block pointer contents are reasonable. This should
* always be the case since the blkptr is protected by a checksum.
* However, if there is damage it's desirable to detect this early
* and treat it as a checksum error. This allows an alternate blkptr
* to be tried when one is available (e.g. ditto blocks).
*/
if (!zfs_blkptr_verify(spa, bp, zio_flags & ZIO_FLAG_CONFIG_WRITER,
BLK_VERIFY_LOG)) {
rc = SET_ERROR(ECKSUM);
goto out;
}
if (!embedded_bp) { if (!embedded_bp) {
/* /*
* Embedded BP's have no DVA and require no I/O to "read". * Embedded BP's have no DVA and require no I/O to "read".
* Create an anonymous arc buf to back it. * Create an anonymous arc buf to back it.
*/ */
if (!zfs_blkptr_verify(spa, bp, zio_flags &
ZIO_FLAG_CONFIG_WRITER, BLK_VERIFY_LOG)) {
rc = SET_ERROR(ECKSUM);
goto out;
}
hdr = buf_hash_find(guid, bp, &hash_lock); hdr = buf_hash_find(guid, bp, &hash_lock);
} }

View File

@ -1006,7 +1006,7 @@ zfs_blkptr_verify(spa_t *spa, const blkptr_t *bp, boolean_t config_held,
* will be done once the zio is executed in vdev_mirror_map_alloc. * will be done once the zio is executed in vdev_mirror_map_alloc.
*/ */
if (!spa->spa_trust_config) if (!spa->spa_trust_config)
return (B_TRUE); return (errors == 0);
if (!config_held) if (!config_held)
spa_config_enter(spa, SCL_VDEV, bp, RW_READER); spa_config_enter(spa, SCL_VDEV, bp, RW_READER);