Locate, get and update PE/COFF permissions during Standalone MM\r
Foundation Entry point on ARM platforms.\r
\r
-Copyright (c) 2017 - 2018, ARM Ltd. All rights reserved.<BR>\r
+Copyright (c) 2017 - 2021, Arm Ltd. All rights reserved.<BR>\r
SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
#include <IndustryStandard/ArmStdSmc.h>\r
\r
+/**\r
+ Privileged firmware assigns RO & Executable attributes to all memory occupied\r
+ by the Boot Firmware Volume. This function sets the correct permissions of\r
+ sections in the Standalone MM Core module to be able to access RO and RW data\r
+ and make further progress in the boot process.\r
+\r
+ @param [in] ImageContext Pointer to PE/COFF image context\r
+ @param [in] ImageBase Base of image in memory\r
+ @param [in] SectionHeaderOffset Offset of PE/COFF image section header\r
+ @param [in] NumberOfSections Number of Sections\r
+ @param [in] TextUpdater Function to change code permissions\r
+ @param [in] ReadOnlyUpdater Function to change RO permissions\r
+ @param [in] ReadWriteUpdater Function to change RW permissions\r
+\r
+**/\r
EFI_STATUS\r
EFIAPI\r
UpdateMmFoundationPeCoffPermissions (\r
IN CONST PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,\r
+ IN EFI_PHYSICAL_ADDRESS ImageBase,\r
IN UINT32 SectionHeaderOffset,\r
IN CONST UINT16 NumberOfSections,\r
IN REGION_PERMISSION_UPDATE_FUNC TextUpdater,\r
// if it is a writeable section then mark it appropriately as well.\r
//\r
if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_MEM_EXECUTE) == 0) {\r
- Base = ImageContext->ImageAddress + SectionHeader.VirtualAddress;\r
+ Base = ImageBase + SectionHeader.VirtualAddress;\r
\r
TextUpdater (Base, SectionHeader.Misc.VirtualSize);\r
\r
return RETURN_SUCCESS;\r
}\r
\r
+/**\r
+ Privileged firmware assigns RO & Executable attributes to all memory occupied\r
+ by the Boot Firmware Volume. This function locates the Standalone MM Core\r
+ module PE/COFF image in the BFV and returns this information.\r
+\r
+ @param [in] BfvAddress Base Address of Boot Firmware Volume\r
+ @param [in, out] TeData Pointer to address for allocating memory\r
+ for PE/COFF image data\r
+ @param [in, out] TeDataSize Pointer to size of PE/COFF image data\r
+\r
+**/\r
EFI_STATUS\r
EFIAPI\r
LocateStandaloneMmCorePeCoffData (\r
IN OUT UINTN *TeDataSize\r
)\r
{\r
- EFI_FFS_FILE_HEADER *FileHeader = NULL;\r
+ EFI_FFS_FILE_HEADER *FileHeader;\r
EFI_STATUS Status;\r
\r
+ FileHeader = NULL;\r
Status = FfsFindNextFile (\r
EFI_FV_FILETYPE_SECURITY_CORE,\r
BfvAddress,\r
return Status;\r
}\r
\r
+/**\r
+ Returns the PC COFF section information.\r
+\r
+ @param [in, out] ImageContext Pointer to PE/COFF image context\r
+ @param [out] ImageBase Base of image in memory\r
+ @param [out] SectionHeaderOffset Offset of PE/COFF image section header\r
+ @param [out] NumberOfSections Number of Sections\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
GetPeCoffSectionInformation (\r
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,\r
+ OUT EFI_PHYSICAL_ADDRESS *ImageBase,\r
OUT UINT32 *SectionHeaderOffset,\r
OUT UINT16 *NumberOfSections\r
)\r
return Status;\r
}\r
\r
+ *ImageBase = ImageContext->ImageAddress;\r
if (!ImageContext->IsTeImage) {\r
ASSERT (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE);\r
\r
} else {\r
*SectionHeaderOffset = (UINTN)(sizeof (EFI_TE_IMAGE_HEADER));\r
*NumberOfSections = Hdr.Te->NumberOfSections;\r
- ImageContext->ImageAddress -= (UINT32)Hdr.Te->StrippedSize - sizeof (EFI_TE_IMAGE_HEADER);\r
+ *ImageBase -= (UINT32)Hdr.Te->StrippedSize - sizeof (EFI_TE_IMAGE_HEADER);\r
}\r
return RETURN_SUCCESS;\r
}\r
\r
+/**\r
+ Privileged firmware assigns RO & Executable attributes to all memory occupied\r
+ by the Boot Firmware Volume. This function locates the section information of\r
+ the Standalone MM Core module to be able to change permissions of the\r
+ individual sections later in the boot process.\r
+\r
+ @param [in] TeData Pointer to PE/COFF image data\r
+ @param [in, out] ImageContext Pointer to PE/COFF image context\r
+ @param [out] ImageBase Pointer to ImageBase variable\r
+ @param [in, out] SectionHeaderOffset Offset of PE/COFF image section header\r
+ @param [in, out] NumberOfSections Number of Sections\r
+\r
+**/\r
EFI_STATUS\r
EFIAPI\r
GetStandaloneMmCorePeCoffSections (\r
IN VOID *TeData,\r
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,\r
+ OUT EFI_PHYSICAL_ADDRESS *ImageBase,\r
IN OUT UINT32 *SectionHeaderOffset,\r
IN OUT UINT16 *NumberOfSections\r
)\r
\r
DEBUG ((DEBUG_INFO, "Found Standalone MM PE data - 0x%x\n", TeData));\r
\r
- Status = GetPeCoffSectionInformation (ImageContext, SectionHeaderOffset, NumberOfSections);\r
+ Status = GetPeCoffSectionInformation (ImageContext, ImageBase,\r
+ SectionHeaderOffset, NumberOfSections);\r
if (EFI_ERROR (Status)) {\r
DEBUG ((DEBUG_ERROR, "Unable to locate Standalone MM Core PE-COFF Section information - %r\n", Status));\r
return Status;\r