From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59271) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btYxz-0008GJ-4Y for qemu-devel@nongnu.org; Mon, 10 Oct 2016 07:42:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1btYxu-0000aP-0I for qemu-devel@nongnu.org; Mon, 10 Oct 2016 07:41:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59204) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btYxt-0000ZV-QD for qemu-devel@nongnu.org; Mon, 10 Oct 2016 07:41:53 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9431B31B309 for ; Mon, 10 Oct 2016 11:41:52 +0000 (UTC) From: "Daniel P. Berrange" Date: Mon, 10 Oct 2016 12:41:47 +0100 Message-Id: <1476099707-526-1-git-send-email-berrange@redhat.com> Subject: [Qemu-devel] [PATCH] crypto: fix initialization of gcrypt threading List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: "Dr . David Alan Gilbert" , "Daniel P. Berrange" 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 --- 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