public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch V2 1/1] UefiPayloadPkg/PayloadLoaderPeim: Force UINTN before save Ptr
@ 2022-02-10  3:03 Guomin Jiang
  2022-02-10  5:34 ` Ni, Ray
  2022-02-10 14:58 ` Ma, Maurice
  0 siblings, 2 replies; 3+ messages in thread
From: Guomin Jiang @ 2022-02-10  3:03 UTC (permalink / raw)
  To: devel; +Cc: Guo Dong, Ray Ni, Maurice Ma, Benjamin You

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@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Maurice Ma <maurice.ma@intel.com>
Cc: Benjamin You <benjamin.you@intel.com>
Signed-off-by: Guomin Jiang <guomin.jiang@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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-02-10 14:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-10  3:03 [Patch V2 1/1] UefiPayloadPkg/PayloadLoaderPeim: Force UINTN before save Ptr Guomin Jiang
2022-02-10  5:34 ` Ni, Ray
2022-02-10 14:58 ` Ma, Maurice

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox