From nobody Sat Nov 23 17:36:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730283169; cv=none; d=zohomail.com; s=zohoarc; b=CR8bam0MzxZDzeAhDZmVRDqZdMXg98Lk/iHTfylDBN42prHT0dhAcKkPIr7h10xTDB7fam92E1+51BASb4WO80mwb0icwqBtqt3RkUyOrlUfTAfdMbw7q4nzfF/ftyrpjEuV4Uj5IAlPCkopNIhbouEFsSo5h5nhbQ2aDWNMNVo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730283169; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=K5TCNaEd+j7wAtXxqyMyUlUmafiCl4lFp6wdNk9FZx4=; b=KWjENsSOHpP5fieXvmUomQ7qylwmvZ+sw+eWYRmf1CvMrAwKze5WBkhdqWRvUSIZQku1fsW39F/DDKKfcuRmXZ9WM2lhTt+6Lwd5yYr4wgd+P3GwL2032YhgWrO8hftYrCYqHMXwk5PdNDgMicRaP8Vr4rEKpLJS3VllMDHsRzE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730283169064795.2244244872627; Wed, 30 Oct 2024 03:12:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t65gU-0004Fj-3Z; Wed, 30 Oct 2024 06:12:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t65gP-0004Ex-NG for qemu-devel@nongnu.org; Wed, 30 Oct 2024 06:12:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t65gM-0004C6-Cc for qemu-devel@nongnu.org; Wed, 30 Oct 2024 06:12:08 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-160-O-mQItuIMaiRM1sfUcs5sg-1; Wed, 30 Oct 2024 06:12:01 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BB2C919560A3 for ; Wed, 30 Oct 2024 10:11:59 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.92]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7911119560A2; Wed, 30 Oct 2024 10:11:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730283125; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K5TCNaEd+j7wAtXxqyMyUlUmafiCl4lFp6wdNk9FZx4=; b=SScBAe4aIsKWJ7GaVfqtkgB+ZOpceJj337qvSjYIMi6Kukm/RoE+RGPgXGXr1B2XMGRZ1/ 8CYx+haGSeW7gILK5rQVF2R9/N7znQG1/kofWTLxaiPhHgM+Y6wKeMLFEnOGktV9dIx9Um wRq/AtC2JHWEVQAl0tcFC/hVMFHovNI= X-MC-Unique: O-mQItuIMaiRM1sfUcs5sg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH 1/2] crypto: fix error check on gcry_md_open Date: Wed, 30 Oct 2024 10:11:49 +0000 Message-ID: <20241030101150.3023300-2-berrange@redhat.com> In-Reply-To: <20241030101150.3023300-1-berrange@redhat.com> References: <20241030101150.3023300-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.302, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730283170019116600 Gcrypt does not return negative values on error, it returns non-zero values. This caused QEMU not to detect failure to open an unsupported hash, resulting in a later crash trying to use a NULL context. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- crypto/hash-gcrypt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto/hash-gcrypt.c b/crypto/hash-gcrypt.c index 73533a4949..22ddf394ec 100644 --- a/crypto/hash-gcrypt.c +++ b/crypto/hash-gcrypt.c @@ -49,7 +49,7 @@ static QCryptoHash *qcrypto_gcrypt_hash_new(QCryptoHashAlgo alg, Error **errp) { QCryptoHash *hash; - int ret; + gcry_error_t ret; =20 hash =3D g_new(QCryptoHash, 1); hash->alg =3D alg; @@ -57,7 +57,7 @@ QCryptoHash *qcrypto_gcrypt_hash_new(QCryptoHashAlgo alg,= Error **errp) =20 ret =3D gcry_md_open((gcry_md_hd_t *) hash->opaque, qcrypto_hash_alg_map[alg], 0); - if (ret < 0) { + if (ret !=3D 0) { error_setg(errp, "Unable to initialize hash algorithm: %s", gcry_strerror(ret)); --=20 2.46.0 From nobody Sat Nov 23 17:36:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730283168; cv=none; d=zohomail.com; s=zohoarc; b=BcOaLjTQVhRBxzrF/BHoeu/9mgwKBad4ErCPIPKqC4zxWx/3beK739k0HJhEpnPpM/dqE2xbkd6SEUCaBi5qc7k89V6bleFN6Ju4Cp4UgZVEAPuQId4FFsp46JtffxWGoBEOFwG22Yo8NeYY2sKs9iuYbZV9MzLOmMTz6orz1fU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730283168; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tTtkACQcE6aGkMXLA65joLcqEGmhrrJxLsb8iryBfB0=; b=LmpUJ/512cSjUvk4bx8702ug0FDz+eVgNxVSTKQn1s2bN/D3hawPtXvy9rvmD++SB9MT5yeiV6No9sCM/m0BwAIfz5HpBAhdlam8PsD1dZvjqo3lUwJZ7KMVC4pJHb/0eJoCqjzpHL9qKTLmWoT/3GrDrrXNAVZ8p0/zYk5jDzo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730283168693707.8402853145968; Wed, 30 Oct 2024 03:12:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t65gR-0004F4-Db; Wed, 30 Oct 2024 06:12:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t65gN-0004En-QZ for qemu-devel@nongnu.org; Wed, 30 Oct 2024 06:12:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t65gK-0004Bu-JN for qemu-devel@nongnu.org; Wed, 30 Oct 2024 06:12:06 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-170-qptckGkaM6e17JXWqASntw-1; Wed, 30 Oct 2024 06:12:02 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 50EA619560A5 for ; Wed, 30 Oct 2024 10:12:01 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.92]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5B28F19560A7; Wed, 30 Oct 2024 10:11:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730283123; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tTtkACQcE6aGkMXLA65joLcqEGmhrrJxLsb8iryBfB0=; b=Dnq+v9djF8Zrl58ZiZ+L+7TiDqTVaDBKxESYK+7Jr90EUGDHeL0Xs7FQ8ZQmj6RXEo7MSg l6p+VSsMZy+0kvxEpP3nnwBKdYU646TnsXAgQJb0QY9zcFA8g7X60TNTh3Dnx2dZ4l3oG3 LzC/6xLM7qpTO3qkfpZnHawpIbcTuqs= X-MC-Unique: qptckGkaM6e17JXWqASntw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH 2/2] crypto: perform runtime check for hash/hmac support in gcrypt Date: Wed, 30 Oct 2024 10:11:50 +0000 Message-ID: <20241030101150.3023300-3-berrange@redhat.com> In-Reply-To: <20241030101150.3023300-1-berrange@redhat.com> References: <20241030101150.3023300-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.302, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730283170023116600 gcrypto has the ability to dynamically disable hash/hmac algorithms at runtime, so QEMU must perform a runtime check. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- crypto/hash-gcrypt.c | 2 +- crypto/hmac-gcrypt.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto/hash-gcrypt.c b/crypto/hash-gcrypt.c index 22ddf394ec..2c8325869a 100644 --- a/crypto/hash-gcrypt.c +++ b/crypto/hash-gcrypt.c @@ -40,7 +40,7 @@ gboolean qcrypto_hash_supports(QCryptoHashAlgo alg) { if (alg < G_N_ELEMENTS(qcrypto_hash_alg_map) && qcrypto_hash_alg_map[alg] !=3D GCRY_MD_NONE) { - return true; + return gcry_md_test_algo(qcrypto_hash_alg_map[alg]) =3D=3D 0; } return false; } diff --git a/crypto/hmac-gcrypt.c b/crypto/hmac-gcrypt.c index 19990cb6ed..181b376572 100644 --- a/crypto/hmac-gcrypt.c +++ b/crypto/hmac-gcrypt.c @@ -37,7 +37,7 @@ bool qcrypto_hmac_supports(QCryptoHashAlgo alg) { if (alg < G_N_ELEMENTS(qcrypto_hmac_alg_map) && qcrypto_hmac_alg_map[alg] !=3D GCRY_MAC_NONE) { - return true; + return gcry_mac_test_algo(qcrypto_hmac_alg_map[alg]) =3D=3D 0; } =20 return false; --=20 2.46.0