summaryrefslogtreecommitdiffstats
path: root/StandaloneMmPkg/Core/FwVol.c
diff options
context:
space:
mode:
authorWei6 Xu <wei6.xu@intel.com>2023-10-30 10:20:48 +0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2023-12-19 09:29:07 +0000
commitc0122840489194215a9209bb37f406f44c416953 (patch)
treeca6c3f69506d0e214804d1a2cdd04ac676617019 /StandaloneMmPkg/Core/FwVol.c
parent74daeded0cabe87d26546f07f9a3911cb60ec0e1 (diff)
downloadedk2-c0122840489194215a9209bb37f406f44c416953.tar.gz
edk2-c0122840489194215a9209bb37f406f44c416953.tar.bz2
edk2-c0122840489194215a9209bb37f406f44c416953.zip
StandaloneMmPkg/Core: Limit FwVol encapsulation section recursion
MmCoreFfsFindMmDriver() is called recursively for encapsulation sections. Currently this recursion is not limited. Introduce a new PCD (fixed-at-build, or patchable-in-module), and make MmCoreFfsFindMmDriver() track the section nesting depth against that PCD. Cc: Laszlo Ersek <lersek@redhat.com> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Cc: Ray Ni <ray.ni@intel.com> Signed-off-by: Wei6 Xu <wei6.xu@intel.com> Reviewed-by: Ray Ni <ray.ni@intel.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Diffstat (limited to 'StandaloneMmPkg/Core/FwVol.c')
-rw-r--r--StandaloneMmPkg/Core/FwVol.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/StandaloneMmPkg/Core/FwVol.c b/StandaloneMmPkg/Core/FwVol.c
index 1f6d7714ba..e1e20ffd14 100644
--- a/StandaloneMmPkg/Core/FwVol.c
+++ b/StandaloneMmPkg/Core/FwVol.c
@@ -48,6 +48,9 @@ FvIsBeingProcessed (
MM driver and return its PE32 image.
@param [in] FwVolHeader Pointer to memory mapped FV
+ @param [in] Depth Nesting depth of encapsulation sections. Callers
+ different from MmCoreFfsFindMmDriver() are
+ responsible for passing in a zero Depth.
@retval EFI_SUCCESS Success.
@retval EFI_INVALID_PARAMETER Invalid parameter.
@@ -55,11 +58,15 @@ FvIsBeingProcessed (
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_VOLUME_CORRUPTED Firmware volume is corrupted.
@retval EFI_UNSUPPORTED Operation not supported.
+ @retval EFI_ABORTED Recursion aborted because Depth has been
+ greater than or equal to
+ PcdFwVolMmMaxEncapsulationDepth.
**/
EFI_STATUS
MmCoreFfsFindMmDriver (
- IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader
+ IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,
+ IN UINT32 Depth
)
{
EFI_STATUS Status;
@@ -84,6 +91,11 @@ MmCoreFfsFindMmDriver (
DEBUG ((DEBUG_INFO, "MmCoreFfsFindMmDriver - 0x%x\n", FwVolHeader));
+ if (Depth >= PcdGet32 (PcdFwVolMmMaxEncapsulationDepth)) {
+ DEBUG ((DEBUG_ERROR, "%a: recursion aborted due to nesting depth\n", __func__));
+ return EFI_ABORTED;
+ }
+
if (FvHasBeenProcessed (FwVolHeader)) {
return EFI_SUCCESS;
}
@@ -172,7 +184,7 @@ MmCoreFfsFindMmDriver (
}
InnerFvHeader = (VOID *)(Section + 1);
- Status = MmCoreFfsFindMmDriver (InnerFvHeader);
+ Status = MmCoreFfsFindMmDriver (InnerFvHeader, Depth + 1);
if (EFI_ERROR (Status)) {
goto FreeDstBuffer;
}