> 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]>
> Message-ID: <[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 0926ad28f0cd..8a1df846a146 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) {

I think the current code was simpler. error_propagate() will simpliy discard 
local_err if errp is already set. It is just missing "local_err = NULL;"

>              /*
>               * 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);
> +            }

Same, I dont see why that's necessary

-- 
Marc-André Lureau <[email protected]>


Reply via email to