From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33372) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxDev-0006Zx-49 for qemu-devel@nongnu.org; Thu, 20 Oct 2016 09:45:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bxDeu-00042p-5M for qemu-devel@nongnu.org; Thu, 20 Oct 2016 09:45:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45284) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bxDeu-00042M-0V for qemu-devel@nongnu.org; Thu, 20 Oct 2016 09:45:24 -0400 From: "Daniel P. Berrange" Date: Thu, 20 Oct 2016 14:45:10 +0100 Message-Id: <1476971110-10403-7-git-send-email-berrange@redhat.com> In-Reply-To: <1476971110-10403-1-git-send-email-berrange@redhat.com> References: <1476971110-10403-1-git-send-email-berrange@redhat.com> Subject: [Qemu-devel] [PULL v1 6/6] crypto: fix initialization of gcrypt threading List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , "Daniel P. Berrange" 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 Signed-off-by: Daniel P. Berrange --- 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