[edk2-devel] [PATCH] UefiCpuPkg: Fix CPU stack guard support by aligning GDT buffer
Vitaly Cheptsov
cheptsov at ispras.ru
Fri Nov 5 19:37:23 UTC 2021
Hi Leif,
I assume you mean the commit description, because the commit message is in the topic. I believe something like that would do:
CpuExceptionHandlerLib supplies misaligned GDT to the outer world
(e.g. ArchSetupExceptionStack) when PcdCpuStackGuard is enabled.
This happens because it uses an array of UINT8 for the mNewGdt
variable, which alignment is 1 byte versus required 8 bytes. As a result
ArchSetupExceptionStack always returns EFI_INVALID_PARAMETER in OVMF Ia32
with XCODE5 and CLANGPDB at least.
Fix this by allocating extra space in mNewGdt and then aligning the pointer
upwards.
Best wishes,
Vitaly
> On 5 Nov 2021, at 22:28, Leif Lindholm <leif at nuviainc.com> wrote:
>
> UefiCpuPkg maintainers - please respond.
>
> Meanwhile, Vitaly, could you please provide a commit message?
> The BZ link is needed, but it's not a substitute.
>
> /
> Leif
>
> On Mon, Sep 20, 2021 at 17:13:47 +0300, Vitaly Cheptsov wrote:
>> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3639
>>
>>
>>
>> Cc: Jiewen Yao <jiewen.yao at intel.com>
>>
>> Cc: Eric Dong <eric.dong at intel.com>
>>
>> Cc: Michael Kinney <michael.d.kinney at intel.com>
>>
>> Cc: Jian J Wang <jian.j.wang at intel.com>
>>
>> Cc: Jeff Fan <vanjeff_919 at hotmail.com>
>>
>> Cc: Mikhail Krichanov <krichanov at ispras.ru>
>>
>> Cc: Marvin Häuser <mhaeuser at posteo.de>
>>
>> Signed-off-by: Vitaly Cheptsov <cheptsov at ispras.ru>
>>
>> ---
>>
>> .../Library/CpuExceptionHandlerLib/DxeException.c | 12 +++++++-----
>>
>> 1 file changed, 7 insertions(+), 5 deletions(-)
>>
>>
>>
>> diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
>>
>> index fd59f09ecd..12874811e1 100644
>>
>> --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
>>
>> +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
>>
>> @@ -22,7 +22,7 @@ EXCEPTION_HANDLER_DATA mExceptionHandlerData;
>>
>>
>>
>> UINT8 mNewStack[CPU_STACK_SWITCH_EXCEPTION_NUMBER *
>>
>> CPU_KNOWN_GOOD_STACK_SIZE];
>>
>> -UINT8 mNewGdt[CPU_TSS_GDT_SIZE];
>>
>> +UINT8 mNewGdt[CPU_TSS_GDT_SIZE + IA32_GDT_ALIGNMENT];
>>
>>
>>
>> /**
>>
>> Common exception handler.
>>
>> @@ -238,6 +238,7 @@ InitializeCpuExceptionHandlersEx (
>>
>> CPU_EXCEPTION_INIT_DATA EssData;
>>
>> IA32_DESCRIPTOR Idtr;
>>
>> IA32_DESCRIPTOR Gdtr;
>>
>> + UINT8 *Gdt;
>>
>>
>>
>> //
>>
>> // To avoid repeat initialization of default handlers, the caller should pass
>>
>> @@ -259,6 +260,7 @@ InitializeCpuExceptionHandlersEx (
>>
>> if (PcdGetBool (PcdCpuStackGuard)) {
>>
>> if (InitData == NULL) {
>>
>> SetMem (mNewGdt, sizeof (mNewGdt), 0);
>>
>> + Gdt = ALIGN_POINTER (mNewGdt, IA32_GDT_ALIGNMENT);
>>
>>
>>
>> AsmReadIdtr (&Idtr);
>>
>> AsmReadGdtr (&Gdtr);
>>
>> @@ -270,11 +272,11 @@ InitializeCpuExceptionHandlersEx (
>>
>> EssData.X64.StackSwitchExceptionNumber = CPU_STACK_SWITCH_EXCEPTION_NUMBER;
>>
>> EssData.X64.IdtTable = (VOID *)Idtr.Base;
>>
>> EssData.X64.IdtTableSize = Idtr.Limit + 1;
>>
>> - EssData.X64.GdtTable = mNewGdt;
>>
>> - EssData.X64.GdtTableSize = sizeof (mNewGdt);
>>
>> - EssData.X64.ExceptionTssDesc = mNewGdt + Gdtr.Limit + 1;
>>
>> + EssData.X64.GdtTable = Gdt;
>>
>> + EssData.X64.GdtTableSize = CPU_TSS_GDT_SIZE;
>>
>> + EssData.X64.ExceptionTssDesc = Gdt + Gdtr.Limit + 1;
>>
>> EssData.X64.ExceptionTssDescSize = CPU_TSS_DESC_SIZE;
>>
>> - EssData.X64.ExceptionTss = mNewGdt + Gdtr.Limit + 1 + CPU_TSS_DESC_SIZE;
>>
>> + EssData.X64.ExceptionTss = Gdt + Gdtr.Limit + 1 + CPU_TSS_DESC_SIZE;
>>
>> EssData.X64.ExceptionTssSize = CPU_TSS_SIZE;
>>
>>
>>
>> InitData = &EssData;
>>
>> --
>>
>> 2.30.1 (Apple Git-130)
>>
>>
>>
>>
>>
>>
>>
>>
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#83406): https://edk2.groups.io/g/devel/message/83406
Mute This Topic: https://groups.io/mt/85741694/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Message signed with OpenPGP
URL: <http://listman.redhat.com/archives/edk2-devel-archive/attachments/20211105/4b2e2f28/attachment.sig>
More information about the edk2-devel-archive
mailing list