When erasing a keyslot we deliberately ignore some errors and carry on trying to erase as much as possible. This results in overwriting Error objects and triggering an assertion. Don't pass in the &local_err, if errp is already set.
Fixes: https://gitlab.com/qemu-project/qemu/-/work_items/4697 Signed-off-by: Daniel P. Berrangé <[email protected]> --- crypto/block-luks.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/crypto/block-luks.c b/crypto/block-luks.c index 0926ad28f0c..8a1df846a14 100644 --- a/crypto/block-luks.c +++ b/crypto/block-luks.c @@ -1152,22 +1152,29 @@ qcrypto_block_luks_erase_key(QCryptoBlock *block, if (ret < 0) { error_propagate(errp, local_err); + local_err = NULL; } + /* * Now try to erase the key material, even if the header * update failed */ for (i = 0; i < QCRYPTO_BLOCK_LUKS_ERASE_ITERATIONS; i++) { if (qcrypto_random_bytes(garbagesplitkey, - splitkeylen, &local_err) < 0) { + splitkeylen, + errp && *errp ? NULL : &local_err) < 0) { /* * If we failed to get the random data, still write * at least zeros to the key slot at least once */ - error_propagate(errp, local_err); + if (local_err) { + error_propagate(errp, local_err); + } if (i > 0) { return -1; + } else { + local_err = NULL; } } if (writefunc(block, @@ -1175,8 +1182,10 @@ qcrypto_block_luks_erase_key(QCryptoBlock *block, garbagesplitkey, splitkeylen, opaque, - &local_err) < 0) { - error_propagate(errp, local_err); + errp && *errp ? NULL : &local_err) < 0) { + if (local_err) { + error_propagate(errp, local_err); + } return -1; } } -- 2.56.0
