[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v1 6/6] crypto: fix initialization of gcrypt threadin
From: |
Daniel P. Berrange |
Subject: |
[Qemu-devel] [PULL v1 6/6] crypto: fix initialization of gcrypt threading |
Date: |
Thu, 20 Oct 2016 14:45:10 +0100 |
The gcrypt threads implementation must be set before calling
any other gcrypt APIs, especially 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, we must set the gcrypt threads impl
before calling gnutls_init, since that will also trigger
gcry_check_version
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Daniel P. Berrange <address@hidden>
---
crypto/init.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/crypto/init.c b/crypto/init.c
index 16e099b..f65207e 100644
--- a/crypto/init.c
+++ b/crypto/init.c
@@ -119,6 +119,10 @@ static struct gcry_thread_cbs qcrypto_gcrypt_thread_impl =
{
int qcrypto_init(Error **errp)
{
+#ifdef QCRYPTO_INIT_GCRYPT_THREADS
+ gcry_control(GCRYCTL_SET_THREAD_CBS, &qcrypto_gcrypt_thread_impl);
+#endif /* QCRYPTO_INIT_GCRYPT_THREADS */
+
#ifdef CONFIG_GNUTLS
int ret;
ret = gnutls_global_init();
@@ -139,9 +143,6 @@ int qcrypto_init(Error **errp)
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
--
2.7.4
- [Qemu-devel] [PULL v1 0/6] Merge qcrypto 2016/10/20, Daniel P. Berrange, 2016/10/20
- [Qemu-devel] [PULL v1 2/6] crypto: add CTR mode support, Daniel P. Berrange, 2016/10/20
- [Qemu-devel] [PULL v1 3/6] crypto: add mode check in qcrypto_cipher_new() for cipher-builtin, Daniel P. Berrange, 2016/10/20
- [Qemu-devel] [PULL v1 5/6] crypto: fix initialization of crypto in tests, Daniel P. Berrange, 2016/10/20
- [Qemu-devel] [PULL v1 6/6] crypto: fix initialization of gcrypt threading,
Daniel P. Berrange <=
- [Qemu-devel] [PULL v1 1/6] crypto: extend mode as a parameter in qcrypto_cipher_supports(), Daniel P. Berrange, 2016/10/20
- [Qemu-devel] [PULL v1 4/6] qtest: fix make check complaint in crypto module, Daniel P. Berrange, 2016/10/20
- Re: [Qemu-devel] [PULL v1 0/6] Merge qcrypto 2016/10/20, Peter Maydell, 2016/10/20