From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.136.1668449659540579779 for ; Mon, 14 Nov 2022 10:14:19 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: pierre.gondois@arm.com) 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 0951411FB; Mon, 14 Nov 2022 10:14:25 -0800 (PST) Received: from pierre123.arm.com (unknown [10.57.8.51]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1AFE83F663; Mon, 14 Nov 2022 10:14:16 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Ard Biesheuvel , Liming Gao , Jiewen Yao , Jian J Wang Subject: [PATCH 1/1][edk2-stable202211] SecurityPkg/RngDxe: Fix Rng algo selection for Arm Date: Mon, 14 Nov 2022 19:13:51 +0100 Message-Id: <20221114181351.1813748-1-Pierre.Gondois@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Pierre Gondois BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4151 PcdCpuRngSupportedAlgorithm is set to the Zero Guid for KvmTool since it is not possible to predict which algorithm will be implemented for Arm's FEAT_RNG in the host. Current handling is: - skipping the Zero Guid, which should not happen to handle KvmTool's case, - triggering an ASSERT if no algorithm was found. However having no Rng algorithm is a valid case, Correctly handle the Zero Guid case and replace the ASSERT by a warning message when no Rng 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 --- .../RandomNumberGenerator/RngDxe/ArmRngDxe.c | 15 +++------------ SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c | 8 +++++++- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c b/Secur= ityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c index 5ba319899ce9..722d53386373 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c @@ -76,7 +76,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; @@ -86,21 +85,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); + if (mAvailableAlgoArrayCount !=3D 0) { + RNGAlgorithm =3D &mAvailableAlgoArray[0]; + } else { return EFI_DEVICE_ERROR; } } =20 -FoundAlgo: if (CompareGuid (RNGAlgorithm, PcdGetPtr (PcdCpuRngSupportedAlgorithm)= )) { Status =3D RngGetBytes (RNGValueLength, RNGValue); return Status; diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c b/Security= Pkg/RandomNumberGenerator/RngDxe/RngDxe.c index 421abb52b8bf..403b31b73609 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c @@ -21,6 +21,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include #include +#include #include #include #include @@ -80,7 +81,12 @@ RngDriverEntry ( // // Get the list of available algorithm. // - return GetAvailableAlgorithms (); + Status =3D GetAvailableAlgorithms (); + if (mAvailableAlgoArrayCount =3D=3D 0) { + DEBUG ((DEBUG_WARN, "No Rng algorithm found in RngDxe.\n")); + } + + return Status; } =20 /** --=20 2.25.1