From nobody Thu Apr 25 19:30:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+96618+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+96618+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1669306712; cv=none; d=zohomail.com; s=zohoarc; b=c7ZncYd6Zuryoxi/uTq3NbjfhPbhN6/Zh4dV3+9KHd2UOuJKM86m1W5FCujswHqvTsQHua0+6yCQnH1hPaOJwpMjKWMrk37H0LL3+EPocnBF8RFzsgSyyo1LwIz2yMnLZKjT9Sx4rCI6Snae21LwjyW8+TNt3FGjT3dtXWEx+Uw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669306712; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=Uc3n//tLoRd7WNsey0wmlKHryZlX2lavhP6YVWftpQY=; b=GbwWYOz4pIbG2i7Q8py4elAJjKnN4gMHE9WP0L4MAl48VEwhujOEYH+pGJj57+Ym4qQ4K4TUZx/D0m4Wc6FBzRe8TwVTrMzZdj1nDirmGjyGIFQ3KX7wPyhoFzvWlhLN67GPoy6cbCqShnaMYyQIno6zzq1jfTSCRlnN5NrclJ0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+96618+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 16693067122061014.9781794603921; Thu, 24 Nov 2022 08:18:32 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id DC0FYY1788612xgeWKtBQ7FA; Thu, 24 Nov 2022 08:18:31 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.27829.1669306710399724122 for ; Thu, 24 Nov 2022 08:18:30 -0800 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 816C4106F; Thu, 24 Nov 2022 08:18:36 -0800 (PST) X-Received: from pierre123.nice.arm.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A49F73F587; Thu, 24 Nov 2022 08:18:28 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Sami Mujawar , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 1/4] ArmPkg/ArmTrngLib: Remove ASSERTs in ArmTrngLibConstructor() Date: Thu, 24 Nov 2022 17:17:53 +0100 Message-Id: <20221124161756.216996-2-Pierre.Gondois@arm.com> In-Reply-To: <20221124161756.216996-1-Pierre.Gondois@arm.com> References: <20221124161756.216996-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: k4Seky4Ig0YMVWp7Pb7BdzlZx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1669306711; bh=i7+5YEl9+5w0MLIzZGnYMgaa4FmGq3rdXIMz4bqPaKw=; h=Cc:Date:From:Reply-To:Subject:To; b=Xg9bC0mgHQcYF1Kx67EM07oeoXMPouG+Gaf+NmnwIdXfJP27ASBlRIN0Rv2WG/CY+uU mwBLicao+wI8Thgy2kh4sWaYra4zcWTsnoQPzswOL1DDB+MpVaOabURuoVvox1ppDnWq1 wDbgrUnNNN/V5cm+Jt5EEhxVjkg6w/AyHTI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1669306712999100006 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois Remove ASSERTs in ArmTrngLibConstructor() that prevent from booting on DEBUG builds. Signed-off-by: Pierre Gondois Reviewed-by: Ard Biesheuvel --- ArmPkg/Library/ArmTrngLib/ArmTrngLib.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ArmPkg/Library/ArmTrngLib/ArmTrngLib.c b/ArmPkg/Library/ArmTrn= gLib/ArmTrngLib.c index 3278722320c8..c2555f3ea6fe 100644 --- a/ArmPkg/Library/ArmTrngLib/ArmTrngLib.c +++ b/ArmPkg/Library/ArmTrngLib/ArmTrngLib.c @@ -331,14 +331,12 @@ ArmTrngLibConstructor ( ArmMonitorCall (&Parameters); Status =3D TrngStatusToReturnStatus ((INT32)Parameters.Arg0); if (RETURN_ERROR (Status)) { - ASSERT_RETURN_ERROR (Status); goto ErrorHandler; } =20 // Cf [1] s2.1.3 'Caller responsibilities', // SMCCC version must be greater or equal than 1.1 if ((INT32)Parameters.Arg0 < 0x10001) { - ASSERT_RETURN_ERROR (RETURN_UNSUPPORTED); goto ErrorHandler; } =20 @@ -350,14 +348,12 @@ ArmTrngLibConstructor ( // Check that the required features are present. Status =3D GetArmTrngFeatures (ARM_SMC_ID_TRNG_RND, NULL); if (RETURN_ERROR (Status)) { - ASSERT_RETURN_ERROR (Status); goto ErrorHandler; } =20 // Check if TRNG UUID is supported and if so trace the GUID. Status =3D GetArmTrngFeatures (ARM_SMC_ID_TRNG_GET_UUID, NULL); if (RETURN_ERROR (Status)) { - ASSERT_RETURN_ERROR (Status); goto ErrorHandler; } =20 @@ -365,7 +361,6 @@ ArmTrngLibConstructor ( =20 Status =3D GetArmTrngUuid (&Guid); if (RETURN_ERROR (Status)) { - ASSERT_RETURN_ERROR (Status); goto ErrorHandler; } =20 --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#96618): https://edk2.groups.io/g/devel/message/96618 Mute This Topic: https://groups.io/mt/95240504/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu Apr 25 19:30:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+96619+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+96619+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1669306713; cv=none; d=zohomail.com; s=zohoarc; b=eXfeKmhsrFAj1Vinz71tpFP9uHCQdHrOkhkopkyMgu2tY57rjqDekXzgsRo3pGWwIqCofniOXmbuqQn+LQjChWRbs+C9SSD5RYltoZABKp1RGqnAOwtMhhic5SZlhDZEjNKRlrIwpxbTcChekVIrcx8yfa4KA3chhlyhB9mIFfE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669306713; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=V3cTqfExC+snMLoZ2goXzn0tVYfZQZXKVo61vRWJlC4=; b=e/+zeiDkBXv8PDKOilq6xjS75RsJtERoD+aRPK6A37u0drbg6u/pkUe17NJ1kyBakNyEZNWFh5+fllesrWnYTqwrij2oIfT/ceMbygDTi07N5KGPcoITDFT9y26jEE5+9JCq1DbwxGSM+c93lGOYdqFHmbQ6BJV5peAucGDrVsI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+96619+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1669306713628598.1861083508165; Thu, 24 Nov 2022 08:18:33 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 5yC2YY1788612xz0iwB4Y7YK; Thu, 24 Nov 2022 08:18:32 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.27852.1669306712167278600 for ; Thu, 24 Nov 2022 08:18:32 -0800 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 549D523A; Thu, 24 Nov 2022 08:18:38 -0800 (PST) X-Received: from pierre123.nice.arm.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6129B3F587; Thu, 24 Nov 2022 08:18:30 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Sami Mujawar , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 2/4] SecurityPkg/RngDxe: Correctly update mAvailableAlgoArrayCount Date: Thu, 24 Nov 2022 17:17:54 +0100 Message-Id: <20221124161756.216996-3-Pierre.Gondois@arm.com> In-Reply-To: <20221124161756.216996-1-Pierre.Gondois@arm.com> References: <20221124161756.216996-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: i4WgAacWHoA2jVgXNytaI5HVx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1669306712; bh=yHOy7ccEFrCw6AxiY02FRVk4HDf6Of7E8ZNI873LCio=; h=Cc:Date:From:Reply-To:Subject:To; b=m0VP6ANRIwPmJgWp9EAlVwvmEbhBWcRSLLwFiNcHeDhHOpbNwxeRo1uMLTPVi7DaXOV cGnyDzLXyoGHNs5U9T4W8xVmJM5xXNUNN074xI3U5iSfIX4XLoSBlLBZI+Lq2gVr/o2TW o+Rg3Uc4rFJyEsOprBccdDJb7HDAzWjncH8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1669306715191100003 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois mAvailableAlgoArrayCount holds the count of available RNG algorithms. In a following patch, its value will be used to prevent the EFI_RNG_PROTOCOL to be installed if no RNG algorithm is available. Correctly set/reset the value for all implementations. Signed-off-by: Pierre Gondois Reviewed-by: Ard Biesheuvel --- SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c | 1 + SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c b/Securit= yPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c index 5ba319899ce9..ce49ff7ae661 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c @@ -40,6 +40,7 @@ FreeAvailableAlgorithms ( VOID ) { + mAvailableAlgoArrayCount =3D 0; FreePool (mAvailableAlgoArray); return; } diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c b/Secur= ityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c index 677600bed7ab..7e06e16e4be5 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c @@ -26,6 +26,11 @@ =20 #include "RngDxeInternals.h" =20 +// +// Count of Rng algorithms. +// +#define RNG_ALGORITHM_COUNT 2 + /** Allocate and initialize mAvailableAlgoArray with the available Rng algorithms. Also update mAvailableAlgoArrayCount. =20 @@ -38,6 +43,7 @@ GetAvailableAlgorithms ( VOID ) { + mAvailableAlgoArrayCount =3D RNG_ALGORITHM_COUNT; return EFI_SUCCESS; } =20 @@ -49,6 +55,7 @@ FreeAvailableAlgorithms ( VOID ) { + mAvailableAlgoArrayCount =3D 0; return; } =20 @@ -164,7 +171,7 @@ RngGetInfo ( return EFI_INVALID_PARAMETER; } =20 - RequiredSize =3D 2 * sizeof (EFI_RNG_ALGORITHM); + RequiredSize =3D RNG_ALGORITHM_COUNT * sizeof (EFI_RNG_ALGORITHM); =20 if (*RNGAlgorithmListSize < RequiredSize) { *RNGAlgorithmListSize =3D RequiredSize; --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#96619): https://edk2.groups.io/g/devel/message/96619 Mute This Topic: https://groups.io/mt/95240505/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu Apr 25 19:30:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+96620+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+96620+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1669306714; cv=none; d=zohomail.com; s=zohoarc; b=B3lwqkhV39TkwF5PBTmTOekipejD7g5iHw7jFEW7rzzt+/WGRfbA2MgvvJ7J6f0yNwv1OzZ73nbk3AgB+zOzFsbkywmUayV1ip4vAe3hVfOywIYKEHEGzQySwsunShjPNFkRepTTkoyM9KVSAJJb8stxqkOdbM/cdG9bvN9/x6U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669306714; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=wl0HfHGUSlZbxJ0Md0spM9kOTJJAfFzyGazG764WPUc=; b=J1LJw8uk2oqk57X1Tk6oP2L9FE0E0hPJGjSm35VB6GogPwDZmVJzkhxaGFRIu0hsib9px5z/0Gg05WKdG+7BZSTHJosy2DdB7ucHK44+aEKVPDCVIiQitOAbb6uznIFXPaViLED+0zLQsqYlhuOEtnm/GiauvPS/4ooWb40iLv4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+96620+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1669306714635212.71356240483703; Thu, 24 Nov 2022 08:18:34 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id r5naYY1788612xD44292CoJC; Thu, 24 Nov 2022 08:18:34 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.27831.1669306713929222120 for ; Thu, 24 Nov 2022 08:18:34 -0800 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1C6DE106F; Thu, 24 Nov 2022 08:18:40 -0800 (PST) X-Received: from pierre123.nice.arm.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3FE0D3F587; Thu, 24 Nov 2022 08:18:32 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Sami Mujawar , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 3/4] SecurityPkg/RngDxe: Conditionally install EFI_RNG_PROTOCOL Date: Thu, 24 Nov 2022 17:17:55 +0100 Message-Id: <20221124161756.216996-4-Pierre.Gondois@arm.com> In-Reply-To: <20221124161756.216996-1-Pierre.Gondois@arm.com> References: <20221124161756.216996-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: JljeExPXHoaWceDl49Tzu38nx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1669306714; bh=nS8Znc4V74jS0k5jWryykasE9Ceap0njc9+fkqPp5pU=; h=Cc:Date:From:Reply-To:Subject:To; b=Y7W5dmKkRQhbeGOsowML3rTVUdXZ7wUQVP5nKSWmWZ+1cKsuXOGaT9/NkcYPVs+CCv7 ux7zjVwDzT4zBr5pIDfB6dxpydIsqiOnlnqmAzOY1DhYPu8/Ykmi+0KCYgPtQPzKKiXcs sbCTdNGPE4h6RtcsrI4v3Fi0TM6Ichgfm6o= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1669306715191100002 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois On Arm platforms, the number of available RNG algorithms is dynamically detected and can be 0 in the absence of FEAT_RNG and firmware TRNG. In this case, the EFI_RNG_PROTOCOL should not be installed to prevent from installing an empty protocol. Signed-off-by: Pierre Gondois Reviewed-by: Ard Biesheuvel --- .../RandomNumberGenerator/RngDxe/RngDxe.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c b/SecurityPk= g/RandomNumberGenerator/RngDxe/RngDxe.c index 421abb52b8bf..d30cb7f47696 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c @@ -63,6 +63,18 @@ RngDriverEntry ( EFI_STATUS Status; EFI_HANDLE Handle; =20 + // + // Get the list of available algorithm. + // + Status =3D GetAvailableAlgorithms (); + if (EFI_ERROR (Status)) { + return Status; + } + + if (mAvailableAlgoArrayCount =3D=3D 0) { + return EFI_UNSUPPORTED; + } + // // Install UEFI RNG (Random Number Generator) Protocol // @@ -74,13 +86,10 @@ RngDriverEntry ( NULL ); if (EFI_ERROR (Status)) { - return Status; + FreeAvailableAlgorithms (); } =20 - // - // Get the list of available algorithm. - // - return GetAvailableAlgorithms (); + return Status; } =20 /** --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#96620): https://edk2.groups.io/g/devel/message/96620 Mute This Topic: https://groups.io/mt/95240507/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu Apr 25 19:30:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+96621+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+96621+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1669306716; cv=none; d=zohomail.com; s=zohoarc; b=XaPWrav1dvpb5EqZiyZ8xhi6GOJwXMd7xUA6w1Ym44ehMib5NKXU/TTj3KsVmbS+x2z0v22/ke5QNAuxPrhiWNqHRGanrjQDgfYVLYIylQCna1fi3/knlbX36KlKmnW+EwL+TApOxEZenlW+yUIcUmT5o8G7Tmni4HxfgCYXHIM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669306716; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=2oN5WkaVQ0GzRzZoXpuec+JrZa0N9nPQTSUWymoEqrU=; b=J3WCoTpY0sk0EBtngkvuj+/E1FWzeguylMyEH9Nh3FSCOM4KzqblRBoci3KqawCWfqKZ+wdavSFH9vRzvoSiGS2AOtSAs9TluGct1blSA5oa5KE5SOoXRcXk6XDURj+cdeD/3+6Emv9Mf9BPX4tL1hNScCF0+vmG6H2hy5XcgTE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+96621+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1669306716856838.3387942670454; Thu, 24 Nov 2022 08:18:36 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 4x9ZYY1788612xQOQn0tpg5j; Thu, 24 Nov 2022 08:18:36 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.27857.1669306715861583480 for ; Thu, 24 Nov 2022 08:18:35 -0800 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F348823A; Thu, 24 Nov 2022 08:18:41 -0800 (PST) X-Received: from pierre123.nice.arm.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E9D043F587; Thu, 24 Nov 2022 08:18:33 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Sami Mujawar , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 4/4] SecurityPkg/RngDxe: Fix Rng algo selection for Arm Date: Thu, 24 Nov 2022 17:17:56 +0100 Message-Id: <20221124161756.216996-5-Pierre.Gondois@arm.com> In-Reply-To: <20221124161756.216996-1-Pierre.Gondois@arm.com> References: <20221124161756.216996-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: S3sT8LEZi4J1FBMdtAiDkuuxx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1669306716; bh=C2fpH1dV2V3vuuqxmcYfqU2/ZSmFCqbe/89KfuQOP8w=; h=Cc:Date:From:Reply-To:Subject:To; b=OQc+8FDY7trTHxc2kH4vUAOhsnW/uiGyQgXZfRSvs5Y1dAZF6dM3sLPGg5b8ORUcEvi TrtLaAjVJIsWGIojpg2Xs91c/3dl3h/60txit+oBDJYjpKztWRYYCHDxOx7AWB2nqbrbf 9gcj310oxDg/DpPrYl1KMrhO16EhlTxpXNc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1669306719026100002 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4151 The EFI_RNG_PROTOCOL can advertise multiple algorithms through Guids. The PcdCpuRngSupportedAlgorithm contains a Guid that can be configured. It represents the algorithm used in RngLib. PcdCpuRngSupportedAlgorithm is set to the Zero Guid for KvmTool. When running KvmTool on a platform platform only having the RngLib, the only Guid available for EFI_RNG_PROTOCOL will be the zero Guid. To select the default algorithm in EFI_RNG_PROTOCOL.GetRng(): a. Zero Guids are skipped b. If no algorithm is found, an ASSERT is triggered To allow using the RngLib to be used for the case above, Zero Guids should not be skipped (a.). If no algorithm is found, don't prevent from booting on DEBUG builds (b.). Allow Zero Guids to be selected and don't ASSERT if no algorithm is found. Also simplify the selection of the Rng algorithm when the default one is selected by just picking up the first element of mAvailableAlgoArray. Reported-by: Sami Mujawar Signed-off-by: Pierre Gondois Reviewed-by: Ard Biesheuvel --- .../RandomNumberGenerator/RngDxe/ArmRngDxe.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c b/Securit= yPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c index ce49ff7ae661..b8a343e3d397 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c @@ -77,7 +77,6 @@ RngGetRNG ( ) { EFI_STATUS Status; - UINTN Index; =20 if ((This =3D=3D NULL) || (RNGValueLength =3D=3D 0) || (RNGValue =3D=3D = NULL)) { return EFI_INVALID_PARAMETER; @@ -87,21 +86,13 @@ RngGetRNG ( // // Use the default RNG algorithm if RNGAlgorithm is NULL. // - for (Index =3D 0; Index < mAvailableAlgoArrayCount; Index++) { - if (!IsZeroGuid (&mAvailableAlgoArray[Index])) { - RNGAlgorithm =3D &mAvailableAlgoArray[Index]; - goto FoundAlgo; - } - } - - if (Index =3D=3D mAvailableAlgoArrayCount) { - // No algorithm available. - ASSERT (Index !=3D mAvailableAlgoArrayCount); - return EFI_DEVICE_ERROR; + if (mAvailableAlgoArrayCount !=3D 0) { + RNGAlgorithm =3D &mAvailableAlgoArray[0]; + } else { + return EFI_UNSUPPORTED; } } =20 -FoundAlgo: if (CompareGuid (RNGAlgorithm, PcdGetPtr (PcdCpuRngSupportedAlgorithm)))= { Status =3D RngGetBytes (RNGValueLength, RNGValue); return Status; --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#96621): https://edk2.groups.io/g/devel/message/96621 Mute This Topic: https://groups.io/mt/95240509/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-