[edk2-devel] [Patch V2 1/1] UefiPayloadPkg/PayloadLoaderPeim: Force UINTN before save Ptr

Ni, Ray ray.ni at intel.com
Thu Feb 10 05:34:09 UTC 2022


Reviewed-by: Ray Ni <ray.ni at intel.com>

-----Original Message-----
From: Jiang, Guomin <guomin.jiang at intel.com> 
Sent: Thursday, February 10, 2022 11:03 AM
To: devel at edk2.groups.io
Cc: Dong, Guo <guo.dong at intel.com>; Ni, Ray <ray.ni at intel.com>; Ma, Maurice <maurice.ma at intel.com>; You, Benjamin <benjamin.you at intel.com>
Subject: [Patch V2 1/1] UefiPayloadPkg/PayloadLoaderPeim: Force UINTN before save Ptr

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3818

It will have some potential issue when memory larger than 2G because the high memory address will be fill with 0xFFFFFFFF when do the operation of UINT64 + INTN.

V2:
1. Force the data type to UINTN to avoid high dword be filled with 0xFFFFFFFF 2. Keep INTN because the offset may postive or negative.

Cc: Guo Dong <guo.dong at intel.com>
Cc: Ray Ni <ray.ni at intel.com>
Cc: Maurice Ma <maurice.ma at intel.com>
Cc: Benjamin You <benjamin.you at intel.com>
Signed-off-by: Guomin Jiang <guomin.jiang at intel.com>
---
 UefiPayloadPkg/PayloadLoaderPeim/ElfLib/Elf64Lib.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/UefiPayloadPkg/PayloadLoaderPeim/ElfLib/Elf64Lib.c b/UefiPayloadPkg/PayloadLoaderPeim/ElfLib/Elf64Lib.c
index dc47a05c6e4a..68200fcadd3f 100644
--- a/UefiPayloadPkg/PayloadLoaderPeim/ElfLib/Elf64Lib.c
+++ b/UefiPayloadPkg/PayloadLoaderPeim/ElfLib/Elf64Lib.c
@@ -143,7 +143,7 @@ ProcessRelocation64 (
           DEBUG ((DEBUG_INFO, "Unsupported relocation type %02X\n", Type));
           ASSERT (FALSE);
         } else {
-          *Ptr += Delta;
+          *Ptr = *(UINTN *)Ptr + Delta;
         }
 
         break;
@@ -177,12 +177,12 @@ ProcessRelocation64 (
           // Calculation: B + A
           //
           if (RelaType == SHT_RELA) {
-            *Ptr = Delta + Rela->r_addend;
+            *Ptr = Delta + (UINTN)Rela->r_addend;
           } else {
             //
             // A is stored in the field of relocation for REL type.
             //
-            *Ptr = Delta + *Ptr;
+            *Ptr = Delta + *(UINTN *)Ptr;
           }
         } else {
           //
--
2.30.0.windows.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#86543): https://edk2.groups.io/g/devel/message/86543
Mute This Topic: https://groups.io/mt/89038278/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