Make sure PE image is executable
All checks were successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
Rafal Kupiec 2022-11-12 19:16:00 +01:00
parent b03c9c2a25
commit 2dd7b09fbb
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4

View File

@ -178,6 +178,16 @@ PeLoadImage(IN PEFI_FILE_HANDLE FileHandle,
return Status;
}
/* Make sure image is executable */
if (!(ImageData->PeHeader->FileHeader.Characteristics & PECOFF_IMAGE_FILE_EXECUTABLE_IMAGE))
{
/* Loaded image is not executable */
XtLdrProtocol->DbgPrint(L"ERROR: Non-executable PE/COFF image loaded\n");
XtLdrProtocol->FreePages(Pages, (EFI_PHYSICAL_ADDRESS)(UINT_PTR)Data);
XtLdrProtocol->FreePool(ImageData);
return STATUS_EFI_LOAD_ERROR;
}
/* Store image size and calculate number of image pages */
ImageData->ImageSize = ImageData->PeHeader->OptionalHeader.SizeOfImage;
ImageData->ImagePages = EFI_SIZE_TO_PAGES(ImageData->ImageSize);