qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] crypto: misc gcrypt hash/hmac fixes
@ 2024-10-30 10:11 Daniel P. Berrangé
  2024-10-30 10:11 ` [PATCH 1/2] crypto: fix error check on gcry_md_open Daniel P. Berrangé
  2024-10-30 10:11 ` [PATCH 2/2] crypto: perform runtime check for hash/hmac support in gcrypt Daniel P. Berrangé
  0 siblings, 2 replies; 5+ messages in thread
From: Daniel P. Berrangé @ 2024-10-30 10:11 UTC (permalink / raw)
  To: qemu-devel; +Cc: Daniel P. Berrangé

This fixes the test suite when gcrypt disables some algorithms
at runtime.

Daniel P. Berrangé (2):
  crypto: fix error check on gcry_md_open
  crypto: perform runtime check for hash/hmac support in gcrypt

 crypto/hash-gcrypt.c | 6 +++---
 crypto/hmac-gcrypt.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

-- 
2.46.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] crypto: fix error check on gcry_md_open
  2024-10-30 10:11 [PATCH 0/2] crypto: misc gcrypt hash/hmac fixes Daniel P. Berrangé
@ 2024-10-30 10:11 ` Daniel P. Berrangé
  2024-10-30 18:56   ` Philippe Mathieu-Daudé
  2024-10-30 10:11 ` [PATCH 2/2] crypto: perform runtime check for hash/hmac support in gcrypt Daniel P. Berrangé
  1 sibling, 1 reply; 5+ messages in thread
From: Daniel P. Berrangé @ 2024-10-30 10:11 UTC (permalink / raw)
  To: qemu-devel; +Cc: Daniel P. Berrangé

Gcrypt does not return negative values on error, it returns non-zero
values. This caused QEMU not to detect failure to open an unsupported
hash, resulting in a later crash trying to use a NULL context.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 crypto/hash-gcrypt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/crypto/hash-gcrypt.c b/crypto/hash-gcrypt.c
index 73533a4949..22ddf394ec 100644
--- a/crypto/hash-gcrypt.c
+++ b/crypto/hash-gcrypt.c
@@ -49,7 +49,7 @@ static
 QCryptoHash *qcrypto_gcrypt_hash_new(QCryptoHashAlgo alg, Error **errp)
 {
     QCryptoHash *hash;
-    int ret;
+    gcry_error_t ret;
 
     hash = g_new(QCryptoHash, 1);
     hash->alg = alg;
@@ -57,7 +57,7 @@ QCryptoHash *qcrypto_gcrypt_hash_new(QCryptoHashAlgo alg, Error **errp)
 
     ret = gcry_md_open((gcry_md_hd_t *) hash->opaque,
                        qcrypto_hash_alg_map[alg], 0);
-    if (ret < 0) {
+    if (ret != 0) {
         error_setg(errp,
                    "Unable to initialize hash algorithm: %s",
                    gcry_strerror(ret));
-- 
2.46.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] crypto: perform runtime check for hash/hmac support in gcrypt
  2024-10-30 10:11 [PATCH 0/2] crypto: misc gcrypt hash/hmac fixes Daniel P. Berrangé
  2024-10-30 10:11 ` [PATCH 1/2] crypto: fix error check on gcry_md_open Daniel P. Berrangé
@ 2024-10-30 10:11 ` Daniel P. Berrangé
  2024-10-31  4:01   ` Philippe Mathieu-Daudé
  1 sibling, 1 reply; 5+ messages in thread
From: Daniel P. Berrangé @ 2024-10-30 10:11 UTC (permalink / raw)
  To: qemu-devel; +Cc: Daniel P. Berrangé

gcrypto has the ability to dynamically disable hash/hmac algorithms
at runtime, so QEMU must perform a runtime check.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 crypto/hash-gcrypt.c | 2 +-
 crypto/hmac-gcrypt.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/crypto/hash-gcrypt.c b/crypto/hash-gcrypt.c
index 22ddf394ec..2c8325869a 100644
--- a/crypto/hash-gcrypt.c
+++ b/crypto/hash-gcrypt.c
@@ -40,7 +40,7 @@ gboolean qcrypto_hash_supports(QCryptoHashAlgo alg)
 {
     if (alg < G_N_ELEMENTS(qcrypto_hash_alg_map) &&
         qcrypto_hash_alg_map[alg] != GCRY_MD_NONE) {
-        return true;
+        return gcry_md_test_algo(qcrypto_hash_alg_map[alg]) == 0;
     }
     return false;
 }
diff --git a/crypto/hmac-gcrypt.c b/crypto/hmac-gcrypt.c
index 19990cb6ed..181b376572 100644
--- a/crypto/hmac-gcrypt.c
+++ b/crypto/hmac-gcrypt.c
@@ -37,7 +37,7 @@ bool qcrypto_hmac_supports(QCryptoHashAlgo alg)
 {
     if (alg < G_N_ELEMENTS(qcrypto_hmac_alg_map) &&
         qcrypto_hmac_alg_map[alg] != GCRY_MAC_NONE) {
-        return true;
+        return gcry_mac_test_algo(qcrypto_hmac_alg_map[alg]) == 0;
     }
 
     return false;
-- 
2.46.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] crypto: fix error check on gcry_md_open
  2024-10-30 10:11 ` [PATCH 1/2] crypto: fix error check on gcry_md_open Daniel P. Berrangé
@ 2024-10-30 18:56   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-10-30 18:56 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel

On 30/10/24 07:11, Daniel P. Berrangé wrote:
> Gcrypt does not return negative values on error, it returns non-zero
> values. This caused QEMU not to detect failure to open an unsupported
> hash, resulting in a later crash trying to use a NULL context.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   crypto/hash-gcrypt.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] crypto: perform runtime check for hash/hmac support in gcrypt
  2024-10-30 10:11 ` [PATCH 2/2] crypto: perform runtime check for hash/hmac support in gcrypt Daniel P. Berrangé
@ 2024-10-31  4:01   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-10-31  4:01 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel

On 30/10/24 07:11, Daniel P. Berrangé wrote:
> gcrypto has the ability to dynamically disable hash/hmac algorithms
> at runtime, so QEMU must perform a runtime check.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   crypto/hash-gcrypt.c | 2 +-
>   crypto/hmac-gcrypt.c | 2 +-
>   2 files changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-10-31  4:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-30 10:11 [PATCH 0/2] crypto: misc gcrypt hash/hmac fixes Daniel P. Berrangé
2024-10-30 10:11 ` [PATCH 1/2] crypto: fix error check on gcry_md_open Daniel P. Berrangé
2024-10-30 18:56   ` Philippe Mathieu-Daudé
2024-10-30 10:11 ` [PATCH 2/2] crypto: perform runtime check for hash/hmac support in gcrypt Daniel P. Berrangé
2024-10-31  4:01   ` Philippe Mathieu-Daudé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).