]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/RiscVVirt: Add Stack HOB edk2-stable202302
authorSunil V L <sunilvl@ventanamicro.com>
Sat, 25 Feb 2023 05:32:00 +0000 (13:32 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 1 Mar 2023 15:08:07 +0000 (15:08 +0000)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4350

Currently, stack HOB is not created for the stack memory. This causes
stack memory to be treated as free memory and any memory allocation which
happens at this address causes random memory corruption. Fix this by
creating the stack HOB which marks the memory as BS data.

Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Andrei Warkentin <andrei.warkentin@intel.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
Reported-by: Andrei Warkentin <andrei.warkentin@intel.com>
Tested-by: Andrei Warkentin <andrei.warkentin@intel.com>
Reviewed-by: Andrei Warkentin <andrei.warkentin@intel.com>
OvmfPkg/RiscVVirt/Sec/SecMain.c

index 73b9b21a67baf53d1e1096c7c03d79e3bcb88e23..adf73f2eb66c7d6d8da5ac88192ec972b52ce338 100644 (file)
@@ -55,6 +55,7 @@ SecStartup (
   EFI_STATUS                  Status;\r
   UINT64                      UefiMemoryBase;\r
   UINT64                      StackBase;\r
+  UINT32                      StackSize;\r
 \r
   //\r
   // Report Status Code to indicate entering SEC core\r
@@ -71,9 +72,9 @@ SecStartup (
   FirmwareContext.FlattenedDeviceTree = (UINT64)DeviceTreeAddress;\r
   SetFirmwareContextPointer (&FirmwareContext);\r
 \r
-  StackBase = (UINT64)FixedPcdGet32 (PcdOvmfSecPeiTempRamBase) +\r
-              FixedPcdGet32 (PcdOvmfSecPeiTempRamSize);\r
-  UefiMemoryBase = StackBase - SIZE_32MB;\r
+  StackBase      = (UINT64)FixedPcdGet32 (PcdOvmfSecPeiTempRamBase);\r
+  StackSize      = FixedPcdGet32 (PcdOvmfSecPeiTempRamSize);\r
+  UefiMemoryBase = StackBase + StackSize - SIZE_32MB;\r
 \r
   // Declare the PI/UEFI memory region\r
   HobList = HobConstructor (\r
@@ -86,6 +87,8 @@ SecStartup (
 \r
   SecInitializePlatform ();\r
 \r
+  BuildStackHob (StackBase, StackSize);\r
+\r
   //\r
   // Process all libraries constructor function linked to SecMain.\r
   //\r