From df42e20ac68ed642c42d1b131391bf46452dadb0 Mon Sep 17 00:00:00 2001 From: Rich Ercolani <214141+rincebrain@users.noreply.github.com> Date: Fri, 3 Dec 2021 16:13:21 -0500 Subject: [PATCH] Corrected a case where we could read uninited ABD memory For my sins, I started running valgrind over ztest to try and fix that pesky intermittent "zloop dies with malloc errors" problem. This one seemed exciting enough to merit cutting a PR for before the rest get polished. Suggested-by: Paul Dagnelie Reviewed-by: Brian Behlendorf Signed-off-by: Rich Ercolani Closes #12214 --- module/zfs/arc.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/module/zfs/arc.c b/module/zfs/arc.c index 79e2d43818..5f086ea9f1 100644 --- a/module/zfs/arc.c +++ b/module/zfs/arc.c @@ -5682,17 +5682,20 @@ arc_read_done(zio_t *zio) zio_crypt_decode_params_bp(bp, hdr->b_crypt_hdr.b_salt, hdr->b_crypt_hdr.b_iv); - if (BP_GET_TYPE(bp) == DMU_OT_INTENT_LOG) { - void *tmpbuf; + if (zio->io_error == 0) { + if (BP_GET_TYPE(bp) == DMU_OT_INTENT_LOG) { + void *tmpbuf; - tmpbuf = abd_borrow_buf_copy(zio->io_abd, - sizeof (zil_chain_t)); - zio_crypt_decode_mac_zil(tmpbuf, - hdr->b_crypt_hdr.b_mac); - abd_return_buf(zio->io_abd, tmpbuf, - sizeof (zil_chain_t)); - } else { - zio_crypt_decode_mac_bp(bp, hdr->b_crypt_hdr.b_mac); + tmpbuf = abd_borrow_buf_copy(zio->io_abd, + sizeof (zil_chain_t)); + zio_crypt_decode_mac_zil(tmpbuf, + hdr->b_crypt_hdr.b_mac); + abd_return_buf(zio->io_abd, tmpbuf, + sizeof (zil_chain_t)); + } else { + zio_crypt_decode_mac_bp(bp, + hdr->b_crypt_hdr.b_mac); + } } }