All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	"Daniel P. Berrange" <berrange@redhat.com>
Subject: [Qemu-devel] [PULL v1 6/6] crypto: fix initialization of gcrypt threading
Date: Wed, 19 Oct 2016 11:02:48 +0100	[thread overview]
Message-ID: <1476871368-9120-7-git-send-email-berrange@redhat.com> (raw)
In-Reply-To: <1476871368-9120-1-git-send-email-berrange@redhat.com>

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 think 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.

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 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

  parent reply	other threads:[~2016-10-19 10:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-19 10:02 [Qemu-devel] [PULL v1 0/6] Merge qcrypto 2016/10/19 Daniel P. Berrange
2016-10-19 10:02 ` [Qemu-devel] [PULL v1 1/6] crypto: extend mode as a parameter in qcrypto_cipher_supports() Daniel P. Berrange
2016-10-19 10:02 ` [Qemu-devel] [PULL v1 2/6] crypto: add CTR mode support Daniel P. Berrange
2016-10-19 10:02 ` [Qemu-devel] [PULL v1 3/6] crypto: add mode check in qcrypto_cipher_new() for cipher-builtin Daniel P. Berrange
2016-10-19 10:02 ` [Qemu-devel] [PULL v1 4/6] qtest: fix make check complaint in crypto module Daniel P. Berrange
2016-10-19 10:02 ` [Qemu-devel] [PULL v1 5/6] crypto: fix initialization of crypto in tests Daniel P. Berrange
2016-10-19 10:02 ` Daniel P. Berrange [this message]
2016-10-20  9:28 ` [Qemu-devel] [PULL v1 0/6] Merge qcrypto 2016/10/19 Daniel P. Berrange
  -- strict thread matches above, loose matches on Subject: below --
2016-10-20 13:45 [Qemu-devel] [PULL v1 0/6] Merge qcrypto 2016/10/20 Daniel P. Berrange
2016-10-20 13:45 ` [Qemu-devel] [PULL v1 6/6] crypto: fix initialization of gcrypt threading Daniel P. Berrange

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=1476871368-9120-7-git-send-email-berrange@redhat.com \
    --to=berrange@redhat.com \
    --cc=peter.maydell@linaro.org \
    --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.