[edk2-devel][PATCH 2/2] IntelFsp2Pkg: Ensure new stack is aligned to old stack for X64

Kuo, Ted ted.kuo at intel.com
Mon Mar 21 12:43:28 UTC 2022


REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3865
Ensure bit3:0 of NewStack is aligned with bit3:0 of OldStack for X64
before switching stack. Otherwise, RSP may not be aligned to a 16-byte
boundary after returning from SecTemporaryRamSupport.

Cc: Chasel Chiu <chasel.chiu at intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone at intel.com>
Cc: Star Zeng <star.zeng at intel.com>
Cc: Ashraf Ali S <ashraf.ali.s at intel.com>
Signed-off-by: Ted Kuo <ted.kuo at intel.com>
---
 IntelFsp2Pkg/FspSecCore/SecMain.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/IntelFsp2Pkg/FspSecCore/SecMain.c b/IntelFsp2Pkg/FspSecCore/SecMain.c
index d376fb8361..f93e2d2ff7 100644
--- a/IntelFsp2Pkg/FspSecCore/SecMain.c
+++ b/IntelFsp2Pkg/FspSecCore/SecMain.c
@@ -258,6 +258,14 @@ SecTemporaryRamSupport (
     NewStack = (VOID *)(UINTN)PermanentMemoryBase;
   }
 
+  //
+  // Ensure bit3:0 of NewStack is aligned with bit3:0 of OldStack for X64 before switching stack.
+  // Otherwise, RSP may not be aligned to a 16-byte boundary after returning from SecTemporaryRamSupport.
+  //
+  if ((sizeof (UINTN) == sizeof (UINT64)) && (((UINTN)NewStack & 0x0F) != ((UINTN)OldStack & 0x0F))) {
+    NewStack = (VOID *)((UINTN)NewStack - 8);
+  }
+
   //
   // Migrate Heap
   //
-- 
2.16.2.windows.1



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