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 <chfernal@microsoft.com>
This commit is contained in:
Chris Fernald
2025-06-11 21:21:34 +00:00
committed by mergify[bot]
parent 564b8e1825
commit 79eab6ffff
@@ -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,