From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by mx.groups.io with SMTP id smtpd.web11.11268.1636144574462441578 for ; Fri, 05 Nov 2021 13:36:15 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: ispras.ru, ip: 83.149.199.84, mailfrom: cheptsov@ispras.ru) Received: from smtpclient.apple (unknown [77.232.9.83]) by mail.ispras.ru (Postfix) with ESMTPSA id D3B7F40D3BFF; Fri, 5 Nov 2021 20:36:10 +0000 (UTC) Mime-Version: 1.0 (Mac OS X Mail 15.0 \(3693.20.0.1.32\)) Subject: Re: [edk2-devel] [PATCH] UefiCpuPkg: Fix CPU stack guard support by aligning GDT buffer From: "Vitaly Cheptsov" In-Reply-To: Date: Fri, 5 Nov 2021 23:36:09 +0300 Cc: Leif Lindholm , "devel@edk2.groups.io" , "Yao, Jiewen" , "Dong, Eric" , "Wang, Jian J" , Jeff Fan , Mikhail Krichanov , =?utf-8?Q?Marvin_H=C3=A4user?= Message-Id: References: <20210920141347.25161-1-cheptsov@ispras.ru> <20211105192821.s2itdxh5t6azp4z6@leviathan> To: "Kinney, Michael D" X-Mailer: Apple Mail (2.3693.20.0.1.32) X-Groupsio-MsgNum: 83411 Content-Type: multipart/signed; boundary="Apple-Mail=_FCA37C8A-05F7-47EA-9430-81C294E12699"; protocol="application/pgp-signature"; micalg=pgp-sha256 Content-Transfer-Encoding: quoted-printable --Apple-Mail=_FCA37C8A-05F7-47EA-9430-81C294E12699 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hi Mike, The command is: build -a IA32 -p OvmfPkg/OvmfPkgIa32.dsc -t CLANGPDB -b NOOPT -D DEBUG_ON_S= ERIAL_PORT But I obviously needed to add gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard|TRUE to OvmfPkgIa32.dsc. The compiler is clang 12.0.1, because clang 13 is badly broken[1]. It would= then crash like this: HandOffToDxeCore() Stack Base: 0x7FE24000, Stack Size: 0x20000 ASSERT_EFI_ERROR (Status =3D Invalid Parameter) ASSERT [DxeCore] DxeMain.c(256): !EFI_ERROR (Status) As for aligning the array, I can submit a V2 which introduces the ALIGNAS m= acro. I also like this solution a lot more. Best wishes, Vitaly [1] https://bugzilla.tianocore.org/buglist.cgi?quicksearch=3Dclang%2013&lis= t_id=3D24276 > On 5 Nov 2021, at 22:42, Kinney, Michael D w= rote: >=20 > Hi Vitaly, >=20 > Can you please provide some details on the compiler/build command that di= d not align the array > correctly. >=20 > I agree that the GDT must have the correct alignment. >=20 > I do not like the idea of unused bytes at the beginning of the array. I w= ould prefer to see > an array that is aligned correctly by declaration. >=20 >=20 > Mike >=20 >> -----Original Message----- >> From: Leif Lindholm >> Sent: Friday, November 5, 2021 12:28 PM >> To: devel@edk2.groups.io; cheptsov@ispras.ru >> Cc: Yao, Jiewen ; Dong, Eric = ; Kinney, Michael D ; >> Wang, Jian J ; Jeff Fan = ; Mikhail Krichanov ; Marvin >> H=C3=A4user >> Subject: Re: [edk2-devel] [PATCH] UefiCpuPkg: Fix CPU stack guard suppor= t by aligning GDT buffer >>=20 >> UefiCpuPkg maintainers - please respond. >>=20 >> Meanwhile, Vitaly, could you please provide a commit message? >> The BZ link is needed, but it's not a substitute. >>=20 >> / >> Leif >>=20 >> On Mon, Sep 20, 2021 at 17:13:47 +0300, Vitaly Cheptsov wrote: >>> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3639 >>>=20 >>>=20 >>>=20 >>> Cc: Jiewen Yao >>>=20 >>> Cc: Eric Dong >>>=20 >>> Cc: Michael Kinney >>>=20 >>> Cc: Jian J Wang >>>=20 >>> Cc: Jeff Fan >>>=20 >>> Cc: Mikhail Krichanov >>>=20 >>> Cc: Marvin H=C3=A4user >>>=20 >>> Signed-off-by: Vitaly Cheptsov >>>=20 >>> --- >>>=20 >>> .../Library/CpuExceptionHandlerLib/DxeException.c | 12 +++++++----- >>>=20 >>> 1 file changed, 7 insertions(+), 5 deletions(-) >>>=20 >>>=20 >>>=20 >>> diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c >> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c >>>=20 >>> index fd59f09ecd..12874811e1 100644 >>>=20 >>> --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c >>>=20 >>> +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c >>>=20 >>> @@ -22,7 +22,7 @@ EXCEPTION_HANDLER_DATA mExceptionHandlerData; >>>=20 >>>=20 >>>=20 >>> UINT8 mNewStack[CPU_STACK_SWITCH_EXCEPTION_NUMBER= * >>>=20 >>> CPU_KNOWN_GOOD_STACK_SIZE]; >>>=20 >>> -UINT8 mNewGdt[CPU_TSS_GDT_SIZE]; >>>=20 >>> +UINT8 mNewGdt[CPU_TSS_GDT_SIZE + IA32_GDT_ALIGNM= ENT]; >>>=20 >>>=20 >>>=20 >>> /** >>>=20 >>> Common exception handler. >>>=20 >>> @@ -238,6 +238,7 @@ InitializeCpuExceptionHandlersEx ( >>>=20 >>> CPU_EXCEPTION_INIT_DATA EssData; >>>=20 >>> IA32_DESCRIPTOR Idtr; >>>=20 >>> IA32_DESCRIPTOR Gdtr; >>>=20 >>> + UINT8 *Gdt; >>>=20 >>>=20 >>>=20 >>> // >>>=20 >>> // To avoid repeat initialization of default handlers, the caller sho= uld pass >>>=20 >>> @@ -259,6 +260,7 @@ InitializeCpuExceptionHandlersEx ( >>>=20 >>> if (PcdGetBool (PcdCpuStackGuard)) { >>>=20 >>> if (InitData =3D=3D NULL) { >>>=20 >>> SetMem (mNewGdt, sizeof (mNewGdt), 0); >>>=20 >>> + Gdt =3D ALIGN_POINTER (mNewGdt, IA32_GDT_ALIGNMENT); >>>=20 >>>=20 >>>=20 >>> AsmReadIdtr (&Idtr); >>>=20 >>> AsmReadGdtr (&Gdtr); >>>=20 >>> @@ -270,11 +272,11 @@ InitializeCpuExceptionHandlersEx ( >>>=20 >>> EssData.X64.StackSwitchExceptionNumber =3D CPU_STACK_SWITCH_EXC= EPTION_NUMBER; >>>=20 >>> EssData.X64.IdtTable =3D (VOID *)Idtr.Base; >>>=20 >>> EssData.X64.IdtTableSize =3D Idtr.Limit + 1; >>>=20 >>> - EssData.X64.GdtTable =3D mNewGdt; >>>=20 >>> - EssData.X64.GdtTableSize =3D sizeof (mNewGdt); >>>=20 >>> - EssData.X64.ExceptionTssDesc =3D mNewGdt + Gdtr.Limit + 1; >>>=20 >>> + EssData.X64.GdtTable =3D Gdt; >>>=20 >>> + EssData.X64.GdtTableSize =3D CPU_TSS_GDT_SIZE; >>>=20 >>> + EssData.X64.ExceptionTssDesc =3D Gdt + Gdtr.Limit + 1; >>>=20 >>> EssData.X64.ExceptionTssDescSize =3D CPU_TSS_DESC_SIZE; >>>=20 >>> - EssData.X64.ExceptionTss =3D mNewGdt + Gdtr.Limit + 1 + CPU_TS= S_DESC_SIZE; >>>=20 >>> + EssData.X64.ExceptionTss =3D Gdt + Gdtr.Limit + 1 + CPU_TSS_DE= SC_SIZE; >>>=20 >>> EssData.X64.ExceptionTssSize =3D CPU_TSS_SIZE; >>>=20 >>>=20 >>>=20 >>> InitData =3D &EssData; >>>=20 >>> -- >>>=20 >>> 2.30.1 (Apple Git-130) >>>=20 >>>=20 >>>=20 >>>=20 >>>=20 >>>=20 >>>=20 >>>=20 --Apple-Mail=_FCA37C8A-05F7-47EA-9430-81C294E12699 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEsLABAI5Y5VbvBdmpL8K2O86Eyz4FAmGFlbkACgkQL8K2O86E yz4DHA//QL3estDJprx2O1lhy6/mUAKPKppmRSMLdxMjD/xy8Z4iqm0PNBIOjOXo brf7VcZbWIioEIl+z8o8nA8z7ns+N7+Fkc8ZQ5sMCvjwgwXLvV9gei39f4O02VsT 1fmIRrWdh/orQY7xIiywbqyudrz+G/0x4BZM4nJdEVzrw4Tl9Kiy6jRP5UzgnguO pKIGx42nc2MD7aa+WRnz9LFKAJVVF2hBNTGozZEBMehf+ZSF2fK+BWB0IIjWahid 9oENby2EXdoCeHWtd+HSICIso8CEOP6+mq9XYZmwbYnWdl/yTUwPMDCoLgIc4ujF t2AqSoUmTGc7stXboMo/JbmsbkmZqYWX89wTqKrhDlRnVitrOXRbo6O8/Bv0O8H6 wdOdngtX7LCJJpMSSy4ilHvwKSQvrS+FzMZuXzBQwM5T+sLC6qr3pzceN1Sm76pp iDyJYJ8/f7dVesnpd9BejFJj/tDPkq4M4A0NTLDPJUmqEiccwbZgyejQ31B3/Fqs SIsiFOvvMODvQDIls/K8/NgWe7wMfqM7RhGqeH/Kd9wxwIWW3awM4kv3OHy2rEhW m7oQlwcO3f71pni/ahr7fcBbeZ4I2/1AEB6z5RmVliCQ57yE638GPQfGy+saacVx LZjKEwy3stUHonbAVabP2/ssbAlXkdmfGoVBtiCnCcJStu9W3E0= =Pxrc -----END PGP SIGNATURE----- --Apple-Mail=_FCA37C8A-05F7-47EA-9430-81C294E12699--