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.web10.53.1678209397175697012 for ; Tue, 07 Mar 2023 09:16:37 -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 405A71CDD; Tue, 7 Mar 2023 09:17:20 -0800 (PST) Received: from cam-smtp0.cambridge.arm.com (pierre123.nice.arm.com [10.34.100.129]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C8E333F67D; Tue, 7 Mar 2023 09:16:35 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: ardb+tianocore@kernel.org, leif@nuviainc.com, sami.mujawar@arm.com, Jiewen Yao , Jian J Wang Subject: [PATCH v4 2/2] SecurityPkg/RngDxe: Check for NULL PcdCpuRngSupportedAlgorithm Date: Tue, 7 Mar 2023 18:15:50 +0100 Message-Id: <20230307171550.555541-3-pierre.gondois@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230307171550.555541-1-pierre.gondois@arm.com> References: <20230307171550.555541-1-pierre.gondois@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 and using CPU instructions. When adding support for the Firmware Trng interface, it was made available through in the RngDxe module. In RngDxe, the algorithm associated with PcdCpuRngSupportedAlgorithm (implemented by the RngLib) was always advertised by default. It was assumed that support for RngLib and RNDR instructions should be kept in ArmVirtPkg. However this support did not exist as all ArmVirtPkg use the BaseRngLibTimerLib.inf implementation of the RngLib. Do not advertise the RngLib and PcdCpuRngSupportedAlgorithm if PcdCpuRngSupportedAlgorithm is NULL. Reported-by: Sami Mujawar Signed-off-by: Pierre Gondois --- .../RngDxe/AArch64/AArch64Algo.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo= .c b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c index e8be217f8a8c..c98e09363e25 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c @@ -39,23 +39,15 @@ GetAvailableAlgorithms ( } =20 // Check RngGetBytes() before advertising PcdCpuRngSupportedAlgorithm. - if (!EFI_ERROR (RngGetBytes (sizeof (DummyRand), (UINT8 *)&DummyRand))= ) { + if (!IsZeroGuid (PcdGetPtr (PcdCpuRngSupportedAlgorithm)) && + !EFI_ERROR (RngGetBytes (sizeof (DummyRand), (UINT8 *)&DummyRand))= ) + { CopyMem ( &mAvailableAlgoArray[mAvailableAlgoArrayCount], PcdGetPtr (PcdCpuRngSupportedAlgorithm), sizeof (EFI_RNG_ALGORITHM) ); mAvailableAlgoArrayCount++; - - DEBUG_CODE_BEGIN (); - if (IsZeroGuid (PcdGetPtr (PcdCpuRngSupportedAlgorithm))) { - DEBUG (( - DEBUG_WARN, - "PcdCpuRngSupportedAlgorithm should be a non-zero GUID\n" - )); - } - - DEBUG_CODE_END (); } =20 // Raw algorithm (Trng) --=20 2.25.1