[edk2-devel][PATCH 1/2] MdeModulePkg: StackOffset must be aligned to a 16-byte boundary in X64
Kuo, Ted
ted.kuo at intel.com
Mon Mar 21 12:43:27 UTC 2022
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3865
For X64, StackOffset must be aligned to a 16-byte boundary as well as
old stack and new stack. Otherwise, it'll get wrong data from Private
pointer after switching from old stack to new stack.
Cc: Michael D Kinney <michael.d.kinney at intel.com>
Cc: Dandan Bi <dandan.bi at intel.com>
Cc: Liming Gao <gaoliming at byosoft.com.cn>
Cc: Debkumar De <debkumar.de at intel.com>
Cc: Harry Han <harry.han at intel.com>
Cc: Catharine West <catharine.west at intel.com>
Cc: Jian J Wang <jian.j.wang at intel.com>
Cc: Marvin Häuser <mhaeuser at posteo.de>
Signed-off-by: Ted Kuo <ted.kuo at intel.com>
---
MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
index 3552feda8f..8a2c1ec779 100644
--- a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
+++ b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
@@ -823,6 +823,19 @@ PeiCheckAndSwitchStack (
(VOID **)&TemporaryRamSupportPpi
);
if (!EFI_ERROR (Status)) {
+ //
+ // For X64, StackOffset must be aligned to a 16-byte boundary. Otherwise, it'll get wrong data
+ // from Private pointer after switching to new stack.
+ //
+ if ((sizeof (UINTN) == sizeof (UINT64)) && ((StackOffset & 0x0F) == 8)) {
+ if (StackOffsetPositive == TRUE) {
+ StackOffset -= 8;
+ } else {
+ StackOffset += 8;
+ }
+ Private->StackOffset = StackOffset;
+ }
+
//
// Heap Offset
//
@@ -852,7 +865,10 @@ PeiCheckAndSwitchStack (
// Temporary Ram Support PPI is provided by platform, it will copy
// temporary memory to permanent memory and do stack switching.
// After invoking Temporary Ram Support PPI, the following code's
- // stack is in permanent memory.
+ // stack is in permanent memory. For X64, the bit3:0 of the new stack
+ // produced by TemporaryRamMigration must be aligned with the bit3:0 of
+ // the old stack. Otherwise, it'll break the original stack alignment
+ // after switching to new stack.
//
TemporaryRamSupportPpi->TemporaryRamMigration (
PeiServices,
--
2.16.2.windows.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#87792): https://edk2.groups.io/g/devel/message/87792
Mute This Topic: https://groups.io/mt/89926603/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