[PATCH v3 4/4] SecurityPkg/RngDxe: Fix Rng algo selection for Arm


From: Pierre Gondois <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

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

Reported-by: Sami Mujawar <sami.mujawar@...>
Signed-off-by: Pierre Gondois <Pierre.Gondois@...>
.../RandomNumberGenerator/RngDxe/ArmRngDxe.c | 17 ++++-------------
1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c b/Secur=
index ce49ff7ae661..b8a343e3d397 100644
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c
+++ b/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c
@@ -77,7 +77,6 @@ RngGetRNG (
- UINTN Index;
if ((This =3D=3D NULL) || (RNGValueLength =3D=3D 0) || (RNGValue =3D=3D=
NULL)) {
@@ -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);
+ if (mAvailableAlgoArrayCount !=3D 0) {
+ RNGAlgorithm =3D &mAvailableAlgoArray[0];
+ } else {
if (CompareGuid (RNGAlgorithm, PcdGetPtr (PcdCpuRngSupportedAlgorithm)=
)) {
Status =3D RngGetBytes (RNGValueLength, RNGValue);
return Status;

Join devel@edk2.groups.io to automatically receive all group messages.