Skip to content

Commit

Permalink
OvmfPkg/RiscVVirt: Add Stack HOB
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
vlsunil authored and mergify[bot] committed Mar 1, 2023
1 parent 1eeca07 commit f80f052
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions OvmfPkg/RiscVVirt/Sec/SecMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ SecStartup (
EFI_STATUS Status;
UINT64 UefiMemoryBase;
UINT64 StackBase;
UINT32 StackSize;

//
// Report Status Code to indicate entering SEC core
Expand All @@ -71,9 +72,9 @@ SecStartup (
FirmwareContext.FlattenedDeviceTree = (UINT64)DeviceTreeAddress;
SetFirmwareContextPointer (&FirmwareContext);

StackBase = (UINT64)FixedPcdGet32 (PcdOvmfSecPeiTempRamBase) +
FixedPcdGet32 (PcdOvmfSecPeiTempRamSize);
UefiMemoryBase = StackBase - SIZE_32MB;
StackBase = (UINT64)FixedPcdGet32 (PcdOvmfSecPeiTempRamBase);
StackSize = FixedPcdGet32 (PcdOvmfSecPeiTempRamSize);
UefiMemoryBase = StackBase + StackSize - SIZE_32MB;

// Declare the PI/UEFI memory region
HobList = HobConstructor (
Expand All @@ -86,6 +87,8 @@ SecStartup (

SecInitializePlatform ();

BuildStackHob (StackBase, StackSize);

//
// Process all libraries constructor function linked to SecMain.
//
Expand Down

0 comments on commit f80f052

Please sign in to comment.