Files
system76-edk2/SecurityPkg/RandomNumberGenerator/RngDxe/Arm/ArmAlgo.c
Kun Qin b74f1f7ab5 SecurityPkg: RngDxe: Fixing mAvailableAlgoArray allocator
REF: https://bugzilla.tianocore.org/show_bug.cgi?idD91

mAvailableAlgoArray is currently allocated for "RNG_AVAILABLE_ALGO_MAX"
number of bytes, whereas it was dereferenced as "EFI_RNG_ALGORITHM".

This change fixed the buffer allocation logic by allocating a proper size
of buffer before referencing.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Sami Mujawar <Sami.Mujawar@arm.com>
Cc: Pierre Gondois <pierre.gondois@arm.com>

Signed-off-by: Kun Qin <kuqin@microsoft.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
2023-09-08 12:48:57 +00:00

52 lines
1.3 KiB
C

/** @file
Arm specific code.
Copyright (c) 2022, Arm Limited. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/ArmTrngLib.h>
#include "RngDxeInternals.h"
// Maximum number of Rng algorithms.
#define RNG_AVAILABLE_ALGO_MAX 1
/** Allocate and initialize mAvailableAlgoArray with the available
Rng algorithms. Also update mAvailableAlgoArrayCount.
@retval EFI_SUCCESS The function completed successfully.
@retval EFI_OUT_OF_RESOURCES Could not allocate memory.
**/
EFI_STATUS
EFIAPI
GetAvailableAlgorithms (
VOID
)
{
UINT16 MajorRevision;
UINT16 MinorRevision;
// Rng algorithms 2 times, one for the allocation, one to populate.
mAvailableAlgoArray = AllocateZeroPool (RNG_AVAILABLE_ALGO_MAX * sizeof (EFI_RNG_ALGORITHM));
if (mAvailableAlgoArray == NULL) {
return EFI_OUT_OF_RESOURCES;
}
// Raw algorithm (Trng)
if (!EFI_ERROR (GetArmTrngVersion (&MajorRevision, &MinorRevision))) {
CopyMem (
&mAvailableAlgoArray[mAvailableAlgoArrayCount],
&gEfiRngAlgorithmRaw,
sizeof (EFI_RNG_ALGORITHM)
);
mAvailableAlgoArrayCount++;
}
return EFI_SUCCESS;
}