X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FCore%2FDxe%2FSectionExtraction%2FCoreSectionExtraction.c;fp=MdeModulePkg%2FCore%2FDxe%2FSectionExtraction%2FCoreSectionExtraction.c;h=908617d1ca5c37e0caf7fb59eb05534f32191fed;hp=d7f7ef427422cb7044fc775dac4eec5bd7341e1a;hb=47343af30435302c087027177613412a1a83e919;hpb=b9bdfc72853fe97bd24401f8873ca61524dd2dc6 diff --git a/MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c b/MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c index d7f7ef4274..908617d1ca 100644 --- a/MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c +++ b/MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c @@ -955,6 +955,9 @@ CreateChildNode ( This is an in/out parameter and it is 1-based, to deal with recursions. @param SectionDefinitionGuid Guid of section definition + @param Depth Nesting depth of encapsulation sections. + Callers different from FindChildNode() are + responsible for passing in a zero Depth. @param FoundChild Output indicating the child node that is found. @param FoundStream Output indicating which section stream the child was found in. If this stream was generated as a @@ -968,6 +971,9 @@ CreateChildNode ( @retval EFI_NOT_FOUND Requested child node does not exist. @retval EFI_PROTOCOL_ERROR a required GUIDED section extraction protocol does not exist + @retval EFI_ABORTED Recursion aborted because Depth has been + greater than or equal to + PcdFwVolDxeMaxEncapsulationDepth. **/ EFI_STATUS @@ -976,6 +982,7 @@ FindChildNode ( IN EFI_SECTION_TYPE SearchType, IN OUT UINTN *SectionInstance, IN EFI_GUID *SectionDefinitionGuid, + IN UINT32 Depth, OUT CORE_SECTION_CHILD_NODE **FoundChild, OUT CORE_SECTION_STREAM_NODE **FoundStream, OUT UINT32 *AuthenticationStatus @@ -990,6 +997,10 @@ FindChildNode ( ASSERT (*SectionInstance > 0); + if (Depth >= PcdGet32 (PcdFwVolDxeMaxEncapsulationDepth)) { + return EFI_ABORTED; + } + CurrentChildNode = NULL; ErrorStatus = EFI_NOT_FOUND; @@ -1053,6 +1064,7 @@ FindChildNode ( SearchType, SectionInstance, SectionDefinitionGuid, + Depth + 1, &RecursedChildNode, &RecursedFoundStream, AuthenticationStatus @@ -1067,9 +1079,17 @@ FindChildNode ( *FoundStream = RecursedFoundStream; return EFI_SUCCESS; } else { + if (Status == EFI_ABORTED) { + // + // If the recursive call was aborted due to nesting depth, stop + // looking for the requested child node. The skipped subtree could + // throw off the instance counting. + // + return Status; + } // - // If the status is not EFI_SUCCESS, just save the error code and - // continue to find the request child node in the rest stream. + // Save the error code and continue to find the requested child node in + // the rest of the stream. // ErrorStatus = Status; } @@ -1272,11 +1292,20 @@ GetSection ( *SectionType, &Instance, SectionDefinitionGuid, + 0, // encapsulation depth &ChildNode, &ChildStreamNode, &ExtractedAuthenticationStatus ); if (EFI_ERROR (Status)) { + if (Status == EFI_ABORTED) { + DEBUG ((DEBUG_ERROR, "%a: recursion aborted due to nesting depth\n", + __FUNCTION__)); + // + // Map "aborted" to "not found". + // + Status = EFI_NOT_FOUND; + } goto GetSection_Done; }