Skip to content

Commit 9183321

Browse files
behlendorftonyhutter
authored andcommitted
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 <[email protected]> Reviewed-by: Tony Nguyen <[email protected]> Signed-off-by: Brian Behlendorf <[email protected]> Closes openzfs#12535
1 parent 32512ac commit 9183321

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

module/zfs/arc.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5917,17 +5917,24 @@ arc_read(zio_t *pio, spa_t *spa, const blkptr_t *bp,
59175917
*/
59185918
fstrans_cookie_t cookie = spl_fstrans_mark();
59195919
top:
5920+
/*
5921+
* Verify the block pointer contents are reasonable. This should
5922+
* always be the case since the blkptr is protected by a checksum.
5923+
* However, if there is damage it's desirable to detect this early
5924+
* and treat it as a checksum error. This allows an alternate blkptr
5925+
* to be tried when one is available (e.g. ditto blocks).
5926+
*/
5927+
if (!zfs_blkptr_verify(spa, bp, zio_flags & ZIO_FLAG_CONFIG_WRITER,
5928+
BLK_VERIFY_LOG)) {
5929+
rc = SET_ERROR(ECKSUM);
5930+
goto out;
5931+
}
5932+
59205933
if (!embedded_bp) {
59215934
/*
59225935
* Embedded BP's have no DVA and require no I/O to "read".
59235936
* Create an anonymous arc buf to back it.
59245937
*/
5925-
if (!zfs_blkptr_verify(spa, bp, zio_flags &
5926-
ZIO_FLAG_CONFIG_WRITER, BLK_VERIFY_LOG)) {
5927-
rc = SET_ERROR(ECKSUM);
5928-
goto out;
5929-
}
5930-
59315938
hdr = buf_hash_find(guid, bp, &hash_lock);
59325939
}
59335940

module/zfs/zio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ zfs_blkptr_verify(spa_t *spa, const blkptr_t *bp, boolean_t config_held,
10061006
* will be done once the zio is executed in vdev_mirror_map_alloc.
10071007
*/
10081008
if (!spa->spa_trust_config)
1009-
return (B_TRUE);
1009+
return (errors == 0);
10101010

10111011
if (!config_held)
10121012
spa_config_enter(spa, SCL_VDEV, bp, RW_READER);

0 commit comments

Comments
 (0)