From 79eab6ffff07deb80c698453bb67d348d81ab975 Mon Sep 17 00:00:00 2001 From: Chris Fernald Date: Wed, 11 Jun 2025 21:21:34 +0000 Subject: [PATCH] StandaloneMmPkg: Avoid updating attributes on 0 length sections PE images can have a zero virtual length section for placeholders, unused relocation, or other artifacts. At best, updated attributes on such sections is a no-op, but at worst is can cause spurious errors and asserts. Specifically asserts have been observed in Hafnium when attempting to update attributes on a zero length section. It is best to just skip such sections entirely. This commit simply logs and skips these sections explicitly. Signed-off-by: Chris Fernald --- .../AArch64/StandaloneMmPeCoffExtraActionLib.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/AArch64/StandaloneMmPeCoffExtraActionLib.c b/StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/AArch64/StandaloneMmPeCoffExtraActionLib.c index 7a5bb412d0..2fa95341e0 100644 --- a/StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/AArch64/StandaloneMmPeCoffExtraActionLib.c +++ b/StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/AArch64/StandaloneMmPeCoffExtraActionLib.c @@ -164,7 +164,15 @@ UpdatePeCoffPermissions ( Base = TmpContext.ImageAddress + SectionHeader.VirtualAddress; - if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_MEM_EXECUTE) == 0) { + if (SectionHeader.Misc.VirtualSize == 0) { + DEBUG (( + DEBUG_INFO, + "%a: Skipping section %d of image at 0x%lx with size 0\n", + __func__, + Index, + Base + )); + } else if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_MEM_EXECUTE) == 0) { if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_MEM_WRITE) == 0) { DEBUG (( DEBUG_INFO,