edk2/StandaloneMmPkg/Core
Oliver Smith-Denny 21cbba1bb3 StandaloneMmPkg: Call PeCoffLoaderUnloadImage When Unloading Image
Today, StandaloneMmCore calls PeCoffLoaderRelocateImage() when loading
images, which calls PeCoffLoaderRelocateImageExtraAction(). On AARCH64,
this sets the image memory protections accordingly, RO + E on code
sections, RW + NX on data sections.

However, if an image fails to start (i.e. its entry point returns a
failure) StandaloneMmCore does not call the corresponding
PeCoffLoaderUnloadImage, which calls PeCoffLoaderUnloadImageExtraAction,
which on AARCH64 undoes the memory protections on the image, setting the
whole memory region back to RW + NX. The core then frees this memory
and the next allocation attempts to use it, which results in a data
abort if a read only memory region is attempted to be written to.
Theoretically, other instances of the PeCoffExtraActionLib could take
other actions and so regardless of architecture, the contract with the
PeCoffLoader should be maintained.

This patch calls PeCoffLoaderUnloadImage when an image's entry point
returns a failure, before freeing the image memory. This meets the
contract and follows the DXE core behavior.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
2025-01-09 12:44:46 +00:00
..
Dependency.c StandaloneMmPkg/Core: Remove traditional MM driver support 2024-08-28 15:25:27 +00:00
Dispatcher.c StandaloneMmPkg: Call PeCoffLoaderUnloadImage When Unloading Image 2025-01-09 12:44:46 +00:00
FwVol.c StandaloneMmPkg/Core: Support to dispatch multiple standalone MM FVs 2024-12-20 10:16:16 +00:00
Handle.c StandaloneMmPkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
InstallConfigurationTable.c StandaloneMmPkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
Locate.c StandaloneMmPkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
MemoryAttributesTable.c StandaloneMmPkg/Core: Add MemoryAttributes support 2024-08-28 15:25:27 +00:00
Mmi.c StandaloneMmPkg: Initialize 'WillReturn' variable 2024-05-30 01:57:35 +00:00
Notify.c StandaloneMmPkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
Page.c StandaloneMmPkg/Core: Add MemoryAttributes support 2024-08-28 15:25:27 +00:00
Pool.c StandaloneMmPkg/Core: Add MemoryAttributes support 2024-08-28 15:25:27 +00:00
StandaloneMmCore.c StandaloneMmPkg/Core: Support to dispatch multiple standalone MM FVs 2024-12-20 10:16:16 +00:00
StandaloneMmCore.h StandaloneMmPkg/Core: Support to dispatch multiple standalone MM FVs 2024-12-20 10:16:16 +00:00
StandaloneMmCore.inf StandaloneMmPkg/Core: Add MemoryAttributes support 2024-08-28 15:25:27 +00:00
StandaloneMmCorePrivateData.h StandaloneMmPkg/Core: Drop MM_CORE_PRIVATE_DATA 2024-08-28 15:25:27 +00:00