From b778f1e462f935ad6178a1a21f74bd5a96181e02 Mon Sep 17 00:00:00 2001 From: kuqin12 <42554914+kuqin12@users.noreply.github.com> Date: Wed, 28 Feb 2024 13:31:16 -0800 Subject: [PATCH] Fix section data length always 4 bytes larger than real data (#752) ## Description This change fixed an issue where the returned section data length is always 4 bytes larger than the real section. This would cause an issue where the caller could read into the final 4 bytes which is invalid data region. - [x] Impacts functionality? - **Functionality** - Does the change ultimately impact how firmware functions? - Examples: Add a new library, publish a new PPI, update an algorithm, ... - [ ] Impacts security? - **Security** - Does the change have a direct security impact on an application, flow, or firmware? - Examples: Crypto algorithm change, buffer overflow fix, parameter validation improvement, ... - [ ] Breaking change? - **Breaking change** - Will anyone consuming this change experience a break in build or boot behavior? - Examples: Add a new library class, move a module to a different repo, call a function in a new library class in a pre-existing module, ... - [ ] Includes tests? - **Tests** - Does the change include any explicit test code? - Examples: Unit tests, integration tests, robot tests, ... - [ ] Includes documentation? - **Documentation** - Does the change contain explicit documentation additions outside direct code modifications (and comments)? - Examples: Update readme file, add feature readme file, link to documentation on an a separate Web page, ... ## How This Was Tested This is verified on QEMU Q35 platform and booted to UEFI shell. ## Integration Instructions N/A --- StandaloneMmPkg/Include/Library/FvLib.h | 2 +- StandaloneMmPkg/Library/FvLib/FvLib.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/StandaloneMmPkg/Include/Library/FvLib.h b/StandaloneMmPkg/Include/Library/FvLib.h index 1eb9ea7e04..3b603e473d 100644 --- a/StandaloneMmPkg/Include/Library/FvLib.h +++ b/StandaloneMmPkg/Include/Library/FvLib.h @@ -87,7 +87,7 @@ FindFfsSectionInSections ( @param FfsFileHeader Pointer to the current file to search. @param SectionData Pointer to the Section matching SectionType in FfsFileHeader. NULL if section not found - @param SectionDataSize The size of SectionData + @param SectionDataSize The size of SectionData, excluding the section header. @retval EFI_NOT_FOUND No files matching the search criteria were found @retval EFI_SUCCESS diff --git a/StandaloneMmPkg/Library/FvLib/FvLib.c b/StandaloneMmPkg/Library/FvLib/FvLib.c index 71808b3e7a..8c875c922f 100644 --- a/StandaloneMmPkg/Library/FvLib/FvLib.c +++ b/StandaloneMmPkg/Library/FvLib/FvLib.c @@ -342,7 +342,7 @@ FfsFindSection ( @param FfsFileHeader Pointer to the current file to search. @param SectionData Pointer to the Section matching SectionType in FfsFileHeader. NULL if section not found - @param SectionDataSize The size of SectionData + @param SectionDataSize The size of SectionData, excluding the section header. @retval EFI_NOT_FOUND No files matching the search criteria were found @retval EFI_SUCCESS @@ -380,10 +380,10 @@ FfsFindSectionData ( if (Section->Type == SectionType) { if (IS_SECTION2 (Section)) { *SectionData = (VOID *)((EFI_COMMON_SECTION_HEADER2 *)Section + 1); - *SectionDataSize = SECTION2_SIZE (Section); + *SectionDataSize = SECTION2_SIZE (Section) - sizeof (EFI_COMMON_SECTION_HEADER2); } else { *SectionData = (VOID *)(Section + 1); - *SectionDataSize = SECTION_SIZE (Section); + *SectionDataSize = SECTION_SIZE (Section) - sizeof (EFI_COMMON_SECTION_HEADER); } return EFI_SUCCESS;