All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: qemu-devel@nongnu.org,  marcandre.lureau@redhat.com
Subject: Re: [PATCH v2 1/2] crypto: avoid overwriting Error object erasing keyslot
Date: Mon, 26 Oct 2026 12:51:02 +0100	[thread overview]
Message-ID: <878q3k3ck9.fsf@pond.sub.org> (raw)
In-Reply-To: <20261026111237.660633-2-berrange@redhat.com> ("Daniel P. Berrangé"'s message of "Mon, 26 Oct 2026 11:12:36 +0000")

Daniel P. Berrangé <berrange@redhat.com> writes:

> 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é <berrange@redhat.com>
> ---
>  crypto/block-luks.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/crypto/block-luks.c b/crypto/block-luks.c
> index 0926ad28f0c..277a5110607 100644
> --- a/crypto/block-luks.c
> +++ b/crypto/block-luks.c
> @@ -1152,6 +1152,7 @@ qcrypto_block_luks_erase_key(QCryptoBlock *block,
   {
       QCryptoBlockLUKS *luks = block->opaque;
       QCryptoBlockLUKSKeySlot *slot;
       g_autofree uint8_t *garbagesplitkey = NULL;
       size_t splitkeylen;
       size_t i;
       Error *local_err = NULL;
       int ret;

       assert(slot_idx < QCRYPTO_BLOCK_LUKS_NUM_KEY_SLOTS);
       slot = &luks->header.key_slots[slot_idx];

       splitkeylen = luks->header.master_key_len * slot->stripes;
       assert(splitkeylen > 0);

       garbagesplitkey = g_new0(uint8_t, splitkeylen);

       /* Reset the key slot header */
       memset(slot->salt, 0, QCRYPTO_BLOCK_LUKS_SALT_LEN);
       slot->iterations = 0;
       slot->active = QCRYPTO_BLOCK_LUKS_KEY_SLOT_DISABLED;

       ret = qcrypto_block_luks_store_header(block, writefunc,
                                             opaque, &local_err);

Why not pass @errp here, and ...

>  
>      if (ret < 0) {
>          error_propagate(errp, local_err);

... drop this line?

> +        local_err = NULL;
>      }

Suggest a blank line here.


Note for later: @errp may be non-null now.

>      /*
>       * Now try to erase the key material, even if the header
> @@ -1169,6 +1170,7 @@ qcrypto_block_luks_erase_key(QCryptoBlock *block,
        * update failed
        */
       for (i = 0; i < QCRYPTO_BLOCK_LUKS_ERASE_ITERATIONS; i++) {
           if (qcrypto_random_bytes(garbagesplitkey,
                                    splitkeylen, &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 @errp is still null, store this error, else ignore it.

>              if (i > 0) {
>                  return -1;

Stop when erasing non-first key slot failed.

>              }
> +            local_err = NULL;
>          }
>          if (writefunc(block,
>                        slot->key_offset_sector * QCRYPTO_BLOCK_LUKS_SECTOR_SIZE,
                         garbagesplitkey,
                         splitkeylen,
                         opaque,
                         &local_err) < 0) {
               error_propagate(errp, local_err);

We do need error_propagate() here, because @errp can be non-null.

               return -1;
           }
       }
       return ret;
   }

Nothing is wrong, so
Reviewed-by: Markus Armbruster <armbru@redhat.com>



  reply	other threads:[~2026-10-26 11:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-26 11:12 [PATCH v2 0/2] crypto: fix handling & reporting of errors when erasing keyslots Daniel P. Berrangé
2026-10-26 11:12 ` [PATCH v2 1/2] crypto: avoid overwriting Error object erasing keyslot Daniel P. Berrangé
2026-10-26 11:51   ` Markus Armbruster [this message]
2026-10-27 14:27   ` marcandre.lureau
2026-10-26 11:12 ` [PATCH v2 2/2] crypto: add newline in error hint messages Daniel P. Berrangé
2026-10-26 11:51   ` Markus Armbruster
2026-10-27 14:27   ` marcandre.lureau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878q3k3ck9.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.