From: "Daniel P. Berrangé" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>,
"Daniel P. Berrangé" <berrange@redhat.com>
Subject: [PATCH v2 1/4] crypto: set default initializer hmac/hash arrays to -1
Date: Mon, 2 Nov 2026 12:23:40 +0000 [thread overview]
Message-ID: <20261102122343.3348956-2-berrange@redhat.com> (raw)
In-Reply-To: <20261102122343.3348956-1-berrange@redhat.com>
The default static array initializer of 0 is not suitable for
the glib hash/hmac backends, as G_CHECKSUM_MD5 has a value of
0. Instead elements must be initialized to -1, but remembering
todo that as new algorithms are defined is errorprone. The
SM3 algorithm initializer is missing, leading to it being
mapped to MD5. This could potentially be a security flaw through
use of the wrong (much weaker) hashing algorithm, if a further
bug elsewhere didn't mask the issue.
Set a default array initializer so unlisted algorithms are
always set to -1 instead of 0.
Fixes: https://gitlab.com/qemu-project/qemu/-/work_items/4786
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
crypto/hash-glib.c | 3 +--
crypto/hmac-glib.c | 4 +---
2 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/crypto/hash-glib.c b/crypto/hash-glib.c
index 809cef98aee..d915430f459 100644
--- a/crypto/hash-glib.c
+++ b/crypto/hash-glib.c
@@ -26,13 +26,12 @@
static int qcrypto_hash_alg_map[QCRYPTO_HASH_ALGO__MAX] = {
+ [0 ... QCRYPTO_HASH_ALGO__MAX - 1] = -1,
[QCRYPTO_HASH_ALGO_MD5] = G_CHECKSUM_MD5,
[QCRYPTO_HASH_ALGO_SHA1] = G_CHECKSUM_SHA1,
- [QCRYPTO_HASH_ALGO_SHA224] = -1,
[QCRYPTO_HASH_ALGO_SHA256] = G_CHECKSUM_SHA256,
[QCRYPTO_HASH_ALGO_SHA384] = G_CHECKSUM_SHA384,
[QCRYPTO_HASH_ALGO_SHA512] = G_CHECKSUM_SHA512,
- [QCRYPTO_HASH_ALGO_RIPEMD160] = -1,
};
gboolean qcrypto_hash_supports(QCryptoHashAlgo alg)
diff --git a/crypto/hmac-glib.c b/crypto/hmac-glib.c
index 1f17769c1c7..4453e0d5f06 100644
--- a/crypto/hmac-glib.c
+++ b/crypto/hmac-glib.c
@@ -18,13 +18,11 @@
#include "hmacpriv.h"
static int qcrypto_hmac_alg_map[QCRYPTO_HASH_ALGO__MAX] = {
+ [0 ... QCRYPTO_HASH_ALGO__MAX - 1] = -1,
[QCRYPTO_HASH_ALGO_MD5] = G_CHECKSUM_MD5,
[QCRYPTO_HASH_ALGO_SHA1] = G_CHECKSUM_SHA1,
[QCRYPTO_HASH_ALGO_SHA256] = G_CHECKSUM_SHA256,
[QCRYPTO_HASH_ALGO_SHA512] = G_CHECKSUM_SHA512,
- [QCRYPTO_HASH_ALGO_SHA224] = -1,
- [QCRYPTO_HASH_ALGO_SHA384] = -1,
- [QCRYPTO_HASH_ALGO_RIPEMD160] = -1,
};
typedef struct QCryptoHmacGlib QCryptoHmacGlib;
--
2.56.0
next prev parent reply other threads:[~2026-11-02 12:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 12:23 [PATCH v2 0/4] crypto: robustness fixes to handling of SM3 hash Daniel P. Berrangé
2026-11-02 12:23 ` Daniel P. Berrangé [this message]
2026-11-02 12:23 ` [PATCH v2 2/4] crypto: unconditionally report SM3 hash length Daniel P. Berrangé
2026-11-02 12:23 ` [PATCH v2 3/4] tests/unit: drop conditionals for SM3 Daniel P. Berrangé
2026-11-02 12:23 ` [PATCH v2 4/4] tests/unit: register one test per hash/hmac algorithm Daniel P. Berrangé
2026-11-12 18:00 ` [PATCH v2 0/4] crypto: robustness fixes to handling of SM3 hash Daniel P. Berrangé
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=20261102122343.3348956-2-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=philmd@oss.qualcomm.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.