SecurityPkg/RngDxe: Correctly update mAvailableAlgoArrayCount

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 <pierre.gondois@arm.com>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
This commit is contained in:
Pierre Gondois 2022-11-24 17:17:54 +01:00 committed by mergify[bot]
parent aa1cd447b3
commit bfb574db11
2 changed files with 9 additions and 1 deletions

View File

@ -40,6 +40,7 @@ FreeAvailableAlgorithms (
VOID VOID
) )
{ {
mAvailableAlgoArrayCount = 0;
FreePool (mAvailableAlgoArray); FreePool (mAvailableAlgoArray);
return; return;
} }

View File

@ -26,6 +26,11 @@
#include "RngDxeInternals.h" #include "RngDxeInternals.h"
//
// Count of Rng algorithms.
//
#define RNG_ALGORITHM_COUNT 2
/** Allocate and initialize mAvailableAlgoArray with the available /** Allocate and initialize mAvailableAlgoArray with the available
Rng algorithms. Also update mAvailableAlgoArrayCount. Rng algorithms. Also update mAvailableAlgoArrayCount.
@ -38,6 +43,7 @@ GetAvailableAlgorithms (
VOID VOID
) )
{ {
mAvailableAlgoArrayCount = RNG_ALGORITHM_COUNT;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -49,6 +55,7 @@ FreeAvailableAlgorithms (
VOID VOID
) )
{ {
mAvailableAlgoArrayCount = 0;
return; return;
} }
@ -164,7 +171,7 @@ RngGetInfo (
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
RequiredSize = 2 * sizeof (EFI_RNG_ALGORITHM); RequiredSize = RNG_ALGORITHM_COUNT * sizeof (EFI_RNG_ALGORITHM);
if (*RNGAlgorithmListSize < RequiredSize) { if (*RNGAlgorithmListSize < RequiredSize) {
*RNGAlgorithmListSize = RequiredSize; *RNGAlgorithmListSize = RequiredSize;