From: "Daniel P. Berrange" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Dr . David Alan Gilbert" <dgilbert@redhat.com>,
"Daniel P. Berrange" <berrange@redhat.com>
Subject: [Qemu-devel] [PATCH] crypto: fix initialization of gcrypt threading
Date: Mon, 10 Oct 2016 12:41:47 +0100 [thread overview]
Message-ID: <1476099707-526-1-git-send-email-berrange@redhat.com> (raw)
The gcrypt threads implementation must be set before calling
gcry_check_version, since that triggers initialization of
the random pool. After that is initialized, changes to the
threads impl won't be honoured by the random pool code. This
means that gcrypt will thing thread locking is needed and
so try to acquire the random pool mutex, but this is NULL
as no threads impl was set originally. This results in a
crash in the random pool code.
For the same reasons, gnutls_init must be done after QEMU
initializes gcrypt, since gnutls will itself calling the
gcry_check_version function.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
In combination with my previous test case fix, this should
make unit tests pass again on RHEL6 platforms with gcrypt
instead of nettle
crypto/init.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/crypto/init.c b/crypto/init.c
index 16e099b..403f3a9 100644
--- a/crypto/init.c
+++ b/crypto/init.c
@@ -119,6 +119,17 @@ static struct gcry_thread_cbs qcrypto_gcrypt_thread_impl = {
int qcrypto_init(Error **errp)
{
+#ifdef CONFIG_GCRYPT
+#ifdef QCRYPTO_INIT_GCRYPT_THREADS
+ gcry_control(GCRYCTL_SET_THREAD_CBS, &qcrypto_gcrypt_thread_impl);
+#endif /* QCRYPTO_INIT_GCRYPT_THREADS */
+ if (!gcry_check_version(GCRYPT_VERSION)) {
+ error_setg(errp, "Unable to initialize gcrypt");
+ return -1;
+ }
+ gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
+#endif
+
#ifdef CONFIG_GNUTLS
int ret;
ret = gnutls_global_init();
@@ -134,16 +145,5 @@ int qcrypto_init(Error **errp)
#endif
#endif
-#ifdef CONFIG_GCRYPT
- if (!gcry_check_version(GCRYPT_VERSION)) {
- error_setg(errp, "Unable to initialize gcrypt");
- return -1;
- }
-#ifdef QCRYPTO_INIT_GCRYPT_THREADS
- gcry_control(GCRYCTL_SET_THREAD_CBS, &qcrypto_gcrypt_thread_impl);
-#endif /* QCRYPTO_INIT_GCRYPT_THREADS */
- gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
-#endif
-
return 0;
}
--
2.7.4
next reply other threads:[~2016-10-10 11:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-10 11:41 Daniel P. Berrange [this message]
2016-10-10 13:35 ` [Qemu-devel] [PATCH] crypto: fix initialization of gcrypt threading Eric Blake
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=1476099707-526-1-git-send-email-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=dgilbert@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 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).