[edk2-devel] [PATCH 3/5] MdeModulePkg/DxeCore: Check for fixed-address Image relocations

Marvin Häuser mhaeuser at posteo.de
Sat Aug 21 19:55:51 UTC 2021


Especially in the relative mode, fixed-address loading may not target
the preferred Image base address. In this case, Image relocations are
required to load the Image. Add the necessary check for this.

Cc: Jian J Wang <jian.j.wang at intel.com>
Cc: Hao A Wu <hao.a.wu at intel.com>
Cc: Dandan Bi <dandan.bi at intel.com>
Cc: Liming Gao <gaoliming at byosoft.com.cn>
Cc: Vitaly Cheptsov <vit9696 at protonmail.com>
Signed-off-by: Marvin Häuser <mhaeuser at posteo.de>
---
 MdeModulePkg/Core/Dxe/Image/Image.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c
index 0a1def0572bc..a19be4c2a4a9 100644
--- a/MdeModulePkg/Core/Dxe/Image/Image.c
+++ b/MdeModulePkg/Core/Dxe/Image/Image.c
@@ -647,7 +647,13 @@ CoreLoadPeImage (
 

       Status = GetPeCoffImageFixLoadingAssignedAddress (&(Image->ImageContext));

 

-      if (EFI_ERROR (Status))  {

+      if (!EFI_ERROR (Status))  {

+          if (PreferredAddress != Image->ImageContext.ImageAddress && Image->ImageContext.RelocationsStripped) {

+            Status = EFI_UNSUPPORTED;

+            DEBUG ((EFI_D_INFO|EFI_D_LOAD, "LOADING MODULE FIXED ERROR: Loading module at fixed address failed since relocations have been stripped.\n"));

+            Image->ImageContext.ImageAddress = PreferredAddress;

+          }

+      } else {

           //

           // If the code memory is not ready, invoke CoreAllocatePage with AllocateAnyPages to load the driver.

           //

-- 
2.31.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#79673): https://edk2.groups.io/g/devel/message/79673
Mute This Topic: https://groups.io/mt/85048611/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-






More information about the edk2-devel-archive mailing list