Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Commit

Permalink
UefiCpuPkg/CpuExceptionHandlerLib: always clear descriptor data in ad…
Browse files Browse the repository at this point in the history
…vance

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1237

Sometimes the memory will be contaminated by random data left in last
boot (warm reset). The code should not assume the allocated memory is
always filled with zero. This patch add code to clear data structure
used for stack switch to prevent such problem from happening.

Cc: Eric Dong <[email protected]>
Cc: Laszlo Ersek <[email protected]>
Cc: Ruiyu Ni <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <[email protected]>
Reviewed-by: Eric Dong <[email protected]>
Reviewed-by: Laszlo Ersek <[email protected]>
Reviewed-by: Ruiyu Ni <[email protected]>
  • Loading branch information
Jian J Wang committed Oct 18, 2018
1 parent fea5e28 commit eae7b47
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ ArchSetupExcpetionStack (
//
TssBase = (UINTN)Tss;

TssDesc->Uint64 = 0;
TssDesc->Bits.LimitLow = sizeof(IA32_TASK_STATE_SEGMENT) - 1;
TssDesc->Bits.BaseLow = (UINT16)TssBase;
TssDesc->Bits.BaseMid = (UINT8)(TssBase >> 16);
Expand All @@ -238,6 +239,7 @@ ArchSetupExcpetionStack (
//
TssBase = (UINTN)Tss;

TssDesc->Uint64 = 0;
TssDesc->Bits.LimitLow = sizeof(IA32_TASK_STATE_SEGMENT) - 1;
TssDesc->Bits.BaseLow = (UINT16)TssBase;
TssDesc->Bits.BaseMid = (UINT8)(TssBase >> 16);
Expand All @@ -255,6 +257,7 @@ ArchSetupExcpetionStack (
continue;
}

ZeroMem (Tss, sizeof (*Tss));
Tss->EIP = (UINT32)(TemplateMap.ExceptionStart
+ Vector * TemplateMap.ExceptionStubHeaderSize);
Tss->EFLAGS = 0x2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ ArchSetupExcpetionStack (
//
TssBase = (UINTN)Tss;

TssDesc->Uint128.Uint64 = 0;
TssDesc->Uint128.Uint64_1= 0;
TssDesc->Bits.LimitLow = sizeof(IA32_TASK_STATE_SEGMENT) - 1;
TssDesc->Bits.BaseLow = (UINT16)TssBase;
TssDesc->Bits.BaseMidl = (UINT8)(TssBase >> 16);
Expand All @@ -231,6 +233,7 @@ ArchSetupExcpetionStack (
//
// Fixup exception task descriptor and task-state segment
//
ZeroMem (Tss, sizeof (*Tss));
StackTop = StackSwitchData->X64.KnownGoodStackTop - CPU_STACK_ALIGNMENT;
StackTop = (UINTN)ALIGN_POINTER (StackTop, CPU_STACK_ALIGNMENT);
IdtTable = StackSwitchData->X64.IdtTable;
Expand Down

0 comments on commit eae7b47

Please sign in to comment.