Re: [PATCH] MdeModulePkg/DxeCore: Consistent DebugImageInfoTable updates
Wu, Hao A
toggle quoted messageShow quoted text
-----Original Message----- I would suggest to send a V2 series for all the patches (not only limited to MdeModulePkg) you sent. Please ensure that patches belong to one series are generated by a single 'git format-patch' command. I think doing so will add information like '1/n', '2/n', ..., 'n/n' for the patches in one series. And you may need to create a cover-letter for one patch series to give a brief summary on the purpose of the series as a whole. Also, if you are implementing a new feature or a fix that touches many modules, I suggest to file a Bugzilla tracker for it: Feature request: https://bugzilla.tianocore.org/enter_bug.cgi?product=Tianocore%20Feature%20Requests Bugfix: https://bugzilla.tianocore.org/enter_bug.cgi?product=EDK2 Lastly, you may keep the 'Reviewed-by' tags already received by other reviewers. Best Regards, Hao Wu
|
|
Re: [PATCH] MdeModulePkg/DxeCore: Consistent DebugImageInfoTable updates
Marvin Häuser <mhaeuser@...>
Good day Hao,
toggle quoted messageShow quoted text
Sorry for the confusion, and you are (rightfully!) not alone. :( I'll quote myself from a different patch: [...] for some reason, none of the other patch series had indices appended. I'm sure I can get that fixed shortly, but what to do then, re-send the entire bulk? I don't want to spam the list, maybe it is smarter to group them by some overview mail this one time? Sorry for the disruption! Best regards, Marvin
On 09/08/2021 08:10, Wu, Hao A wrote:
Sorry Marvin Häuser,
|
|
Re: [PATCH] MdeModulePkg/DxeCore: Consistent DebugImageInfoTable updates
Wu, Hao A
Sorry Marvin Häuser,
toggle quoted messageShow quoted text
Could you help to confirm that below 9 MdeModulePkg related patches are either: * All independent patches * Belong to a patch series that includes all these 9 MdeModulePkg related commits * Belong to several independent patch series MdePkg/Base.h: Introduce various alignment-related macros MdeModulePkg/CoreDxe: Mandatory LoadedImage for DebugImageInfoTable MdeModulePkg/DxeCore: Fix DebugImageInfoTable size report MdeModulePkg/DxeCore: Use the correct source for fixed load address MdeModulePkg/PiSmmCore: Drop deprecated image profiling commands MdeModulePkg/CoreDxe: Drop caller-allocated image buffers MdeModulePkg/DxeCore: Drop unnecessary pointer indirection MdeModulePkg/PiSmmIpl: Correct fixed load address bounds check MdeModulePkg/DxeCore: Consistent DebugImageInfoTable updates Best Regards, Hao Wu
-----Original Message-----
|
|
[PATCH v2 1/1] MdeModulePkg/PiSmmCore: Drop deprecated image profiling commands
Marvin Häuser <mhaeuser@...>
The legacy codebase allowed SMM images to be registered for profiling
from DXE. Support for this has been dropped entirely, so remove the remaining handlers. Cc: Jian J Wang <jian.j.wang@...> Cc: Hao A Wu <hao.a.wu@...> Cc: Eric Dong <eric.dong@...> Cc: Ray Ni <ray.ni@...> Cc: Vitaly Cheptsov <vit9696@...> Signed-off-by: Marvin Häuser <mhaeuser@...> --- MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c | 89 ++------------------ MdeModulePkg/Include/Guid/MemoryProfile.h | 6 +- 2 files changed, 12 insertions(+), 83 deletions(-) diff --git a/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c b/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c index 1b302c810cc9..9d6e3bf27aca 100644 --- a/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c +++ b/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c @@ -2232,64 +2232,6 @@ Done: mSmramProfileGettingStatus = SmramProfileGettingStatus; } -/** - SMRAM profile handler to register SMM image. - - @param SmramProfileParameterRegisterImage The parameter of SMM profile register image. - -**/ -VOID -SmramProfileHandlerRegisterImage ( - IN SMRAM_PROFILE_PARAMETER_REGISTER_IMAGE *SmramProfileParameterRegisterImage - ) -{ - EFI_STATUS Status; - EFI_SMM_DRIVER_ENTRY DriverEntry; - VOID *EntryPointInImage; - - ZeroMem (&DriverEntry, sizeof (DriverEntry)); - CopyMem (&DriverEntry.FileName, &SmramProfileParameterRegisterImage->FileName, sizeof(EFI_GUID)); - DriverEntry.ImageBuffer = SmramProfileParameterRegisterImage->ImageBuffer; - DriverEntry.NumberOfPage = (UINTN) SmramProfileParameterRegisterImage->NumberOfPage; - Status = InternalPeCoffGetEntryPoint ((VOID *) (UINTN) DriverEntry.ImageBuffer, &EntryPointInImage); - ASSERT_EFI_ERROR (Status); - DriverEntry.ImageEntryPoint = (PHYSICAL_ADDRESS) (UINTN) EntryPointInImage; - - Status = RegisterSmramProfileImage (&DriverEntry, FALSE); - if (!EFI_ERROR (Status)) { - SmramProfileParameterRegisterImage->Header.ReturnStatus = 0; - } -} - -/** - SMRAM profile handler to unregister SMM image. - - @param SmramProfileParameterUnregisterImage The parameter of SMM profile unregister image. - -**/ -VOID -SmramProfileHandlerUnregisterImage ( - IN SMRAM_PROFILE_PARAMETER_UNREGISTER_IMAGE *SmramProfileParameterUnregisterImage - ) -{ - EFI_STATUS Status; - EFI_SMM_DRIVER_ENTRY DriverEntry; - VOID *EntryPointInImage; - - ZeroMem (&DriverEntry, sizeof (DriverEntry)); - CopyMem (&DriverEntry.FileName, &SmramProfileParameterUnregisterImage->FileName, sizeof (EFI_GUID)); - DriverEntry.ImageBuffer = SmramProfileParameterUnregisterImage->ImageBuffer; - DriverEntry.NumberOfPage = (UINTN) SmramProfileParameterUnregisterImage->NumberOfPage; - Status = InternalPeCoffGetEntryPoint ((VOID *) (UINTN) DriverEntry.ImageBuffer, &EntryPointInImage); - ASSERT_EFI_ERROR (Status); - DriverEntry.ImageEntryPoint = (PHYSICAL_ADDRESS) (UINTN) EntryPointInImage; - - Status = UnregisterSmramProfileImage (&DriverEntry, FALSE); - if (!EFI_ERROR (Status)) { - SmramProfileParameterUnregisterImage->Header.ReturnStatus = 0; - } -} - /** Dispatch function for a Software SMI handler. @@ -2374,28 +2316,6 @@ SmramProfileHandler ( } SmramProfileHandlerGetDataByOffset ((SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA_BY_OFFSET *) (UINTN) CommBuffer); break; - case SMRAM_PROFILE_COMMAND_REGISTER_IMAGE: - DEBUG ((EFI_D_ERROR, "SmramProfileHandlerRegisterImage\n")); - if (TempCommBufferSize != sizeof (SMRAM_PROFILE_PARAMETER_REGISTER_IMAGE)) { - DEBUG ((EFI_D_ERROR, "SmramProfileHandler: SMM communication buffer size invalid!\n")); - return EFI_SUCCESS; - } - if (mSmramReadyToLock) { - return EFI_SUCCESS; - } - SmramProfileHandlerRegisterImage ((SMRAM_PROFILE_PARAMETER_REGISTER_IMAGE *) (UINTN) CommBuffer); - break; - case SMRAM_PROFILE_COMMAND_UNREGISTER_IMAGE: - DEBUG ((EFI_D_ERROR, "SmramProfileHandlerUnregisterImage\n")); - if (TempCommBufferSize != sizeof (SMRAM_PROFILE_PARAMETER_UNREGISTER_IMAGE)) { - DEBUG ((EFI_D_ERROR, "SmramProfileHandler: SMM communication buffer size invalid!\n")); - return EFI_SUCCESS; - } - if (mSmramReadyToLock) { - return EFI_SUCCESS; - } - SmramProfileHandlerUnregisterImage ((SMRAM_PROFILE_PARAMETER_UNREGISTER_IMAGE *) (UINTN) CommBuffer); - break; case SMRAM_PROFILE_COMMAND_GET_RECORDING_STATE: DEBUG ((EFI_D_ERROR, "SmramProfileHandlerGetRecordingState\n")); if (TempCommBufferSize != sizeof (SMRAM_PROFILE_PARAMETER_RECORDING_STATE)) { @@ -2417,6 +2337,15 @@ SmramProfileHandler ( ParameterRecordingState->Header.ReturnStatus = 0; break; + // + // Below 2 commands have been deprecated. They may not be (re-)used. + // + case SMRAM_PROFILE_COMMAND_DEPRECATED1: + case SMRAM_PROFILE_COMMAND_DEPRECATED2: + ASSERT (FALSE); + // + // Fall-through to the default (unrecognized command) case. + // default: break; } diff --git a/MdeModulePkg/Include/Guid/MemoryProfile.h b/MdeModulePkg/Include/Guid/MemoryProfile.h index eee3b9125240..7565e68b5c33 100644 --- a/MdeModulePkg/Include/Guid/MemoryProfile.h +++ b/MdeModulePkg/Include/Guid/MemoryProfile.h @@ -389,10 +389,10 @@ struct _EDKII_MEMORY_PROFILE_PROTOCOL { #define SMRAM_PROFILE_COMMAND_GET_PROFILE_INFO 0x1 #define SMRAM_PROFILE_COMMAND_GET_PROFILE_DATA 0x2 // -// Below 2 commands are now used by ECP only and only valid before SmmReadyToLock +// Below 2 commands have been deprecated. They may not be re-used. // -#define SMRAM_PROFILE_COMMAND_REGISTER_IMAGE 0x3 -#define SMRAM_PROFILE_COMMAND_UNREGISTER_IMAGE 0x4 +#define SMRAM_PROFILE_COMMAND_DEPRECATED1 0x3 +#define SMRAM_PROFILE_COMMAND_DEPRECATED2 0x4 #define SMRAM_PROFILE_COMMAND_GET_PROFILE_DATA_BY_OFFSET 0x5 #define SMRAM_PROFILE_COMMAND_GET_RECORDING_STATE 0x6 -- 2.31.1
|
|
[PATCH] UefiPayloadPkg: Fix the non-ascii character in UniversalPayloadEntry.c
duntan
Fix the non-ascii character in UniversalPayloadEntry.c
Cc: Guo Dong <guo.dong@...> Cc: Ray Ni <ray.ni@...> Cc: Maurice Ma <maurice.ma@...> Cc: Benjamin You <benjamin.you@...> Signed-off-by: DunTan <dun.tan@...> --- UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c b/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c index 09dd1e8378..03ad9c457b 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c +++ b/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c @@ -38,7 +38,7 @@ PrintHob ( /** Some bootloader may pass a pcd database, and UPL also contain a PCD database. Dxe PCD driver has the assumption that the two PCD database can be catenated and - the local token number should be successive。 + the local token number should be successive. This function will fix up the UPL PCD database to meet that assumption. @param[in] DxeFv The FV where to find the Universal PCD database. -- 2.31.1.windows.1
|
|
Re: [PATCH 1/1] MdeModulePkg/Console: Improve encoding of box drawing characters
Wu, Hao A
Sorry Zhichao and Ray, could you please help to check if you have comments for this patch. Thanks in advance.
toggle quoted messageShow quoted text
Hello Caden Kline, could you help to provide the information on what kind of unit test was done for this patch? Some inline comments for ONLY coding style issues:
-----Original Message----- Typo: lenth -> length, squences -> sequences Also, please help to update the comments to style: // // This the length the escape sequences for entering and exiting Dec Special // Graphics Mode Please help to fix the space indent (extra spaces) here to keep it aligned with the contexts.
Please help to add an extra space for the above 3 lines for space indent coding style.
For the below added codes (for case TerminalTypeXtermR6 & TerminalTypeSCO), please help to fix below coding style issues: a) Codes within a 'case' or 'if-else' statement is recommended to add 2 spaces for indent. (The space indent of the below chunk of codes are messy, which impacts the readability.) b) For multi-line function calls, the input parameters (including the closing bracket) are recommended to add 2 spaces from the function name in the 1st line. c) Please update multi-line comment to align with style: // // Comments... // + if (TerminalIsValidTextGraphics (*WString, NULL, NULL, &DecChar) For the below added codes (for case TerminalTypeVt100Plus & TerminalTypeVt400), please help to fix below coding style issues: a) Codes within a 'case' or 'if-else' statement is recommended to add 2 spaces for indent. (The space indent of the below chunk of codes are messy, which impacts the readability.) b) For multi-line function calls, the input parameters (including the closing bracket) are recommended to add 2 spaces from the function name in the 1st line. Best Regards, Hao Wu
|
|
Re: [PATCH] UefiPayloadPkg/UefiPayloadEntry: Fix memory corruption
Marvin Häuser <mhaeuser@...>
On 09/08/2021 06:20, Ni, Ray wrote:
It's so lucky that no code calls AllocatePool so the bug didn't cause real issues. (I tried to remove AllocatePool() and build still passed.)Hey Ray, clang-tidy gave me a hand. :) "Suspicious usage of 'sizeof(K)'; did you mean 'K'? clang-tidy(bugprone-sizeof-expression)" I set it up as follows (this is *not* sophisticated, just added things to quickly move on): https://github.com/tianocore/edk2-staging/blob/2021-gsoc-secure-loader/compile_flags.txt Best regards, Marvin
|
|
Re: [PATCH] MdeModulePkg/PiSmmCore: Drop deprecated image profiling commands
Marvin Häuser <mhaeuser@...>
Hey Jiewen,
toggle quoted messageShow quoted text
Good point, sure. Will probably add ASSERTs as well, if that is fine with you. Best regards, Marvin
On 09/08/2021 07:33, Yao, Jiewen wrote:
Can we define 3 and 4 to be "reserved and do not use", instead of removed ?
|
|
Re: [PATCH] SecurityPkg/DxeImageVerificationLib: Always lookup SHA-256 hash in dbx
Marvin Häuser <mhaeuser@...>
Hey Jiewen,
toggle quoted messageShow quoted text
Right, I meant to ask about this and forgot (sorry, I sent out a bit less than 30 patches yesterday :) ). Why do we record and potentially defer the loading of images that are distrusted by dbx? I would expect any image explicitly distrusted (not just untrusted) to be rejected and unloaded immediately. Sorry if I got wrong what is happening! Best regards, Marvin
On 09/08/2021 04:48, Yao, Jiewen wrote:
Hi Marvin
|
|
Re: [PATCH] MdeModulePkg/PiSmmCore: Drop deprecated image profiling commands
Yao, Jiewen
Can we define 3 and 4 to be "reserved and do not use", instead of removed ?
toggle quoted messageShow quoted text
-#define SMRAM_PROFILE_COMMAND_REGISTER_IMAGE 0x3 -#define SMRAM_PROFILE_COMMAND_UNREGISTER_IMAGE 0x4 For example: Command 0x3 and 0x4 are deprecated and reserved. They should not be used in the future. With that changed, reviewed-by: Jiewen Yao <Jiewen.yao@...>
-----Original Message-----
|
|
Re: [PATCH] SecurityPkg/DxeImageVerificationLib: Always lookup SHA-256 hash in dbx
Marvin Häuser <mhaeuser@...>
Good day,
toggle quoted messageShow quoted text
I just woke up to this mess, yes. I actually did follow that guide, just around 3 years ago I believe, so let me check where things went wrong since then... The patch you quoted was a standalone patch. However, for some reason, none of the other patch series had indices appended. I'm sure I can get that fixed shortly, but what to do then, re-send the entire bulk? I don't want to spam the list, maybe it is smarter to group them by some overview mail this one time? Sorry for the disruption! Best regards, Marvin
On 09/08/2021 02:02, Min Xu wrote:
On August 9, 2021 3:40 AM, Marvin Häuser wrote:Subject: [PATCH] SecurityPkg/DxeImageVerificationLib: Always lookup SHA-256It seems there are 3 patches sent from Marvin Häuser and I suppose they're in one patch-set, right? Please follow the link below to send out patch-set for review.
|
|
Re: [PATCH] MdeModulePkg/PiSmmCore: Drop deprecated image profiling commands
Ni, Ray
Reviewed-by: Ray Ni <ray.ni@...>
toggle quoted messageShow quoted text
+Star and Jiewen for confirmation.
-----Original Message-----
From: Marvin Häuser <mhaeuser@...> Sent: Monday, August 9, 2021 3:40 AM To: devel@edk2.groups.io Cc: Wang, Jian J <jian.j.wang@...>; Wu, Hao A <hao.a.wu@...>; Dong, Eric <eric.dong@...>; Ni, Ray <ray.ni@...>; Vitaly Cheptsov <vit9696@...> Subject: [PATCH] MdeModulePkg/PiSmmCore: Drop deprecated image profiling commands The legacy codebase allowed SMM images to be registered for profiling from DXE. Support for this has been dropped entirely, so remove the remaining handlers. Cc: Jian J Wang <jian.j.wang@...> Cc: Hao A Wu <hao.a.wu@...> Cc: Eric Dong <eric.dong@...> Cc: Ray Ni <ray.ni@...> Cc: Vitaly Cheptsov <vit9696@...> Signed-off-by: Marvin Häuser <mhaeuser@...> --- MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c | 80 -------------------- MdeModulePkg/Include/Guid/MemoryProfile.h | 5 -- 2 files changed, 85 deletions(-) diff --git a/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c b/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c index 1b302c810cc9..7316df7531fd 100644 --- a/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c +++ b/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c @@ -2232,64 +2232,6 @@ Done: mSmramProfileGettingStatus = SmramProfileGettingStatus; } -/** - SMRAM profile handler to register SMM image. - - @param SmramProfileParameterRegisterImage The parameter of SMM profile register image. - -**/ -VOID -SmramProfileHandlerRegisterImage ( - IN SMRAM_PROFILE_PARAMETER_REGISTER_IMAGE *SmramProfileParameterRegisterImage - ) -{ - EFI_STATUS Status; - EFI_SMM_DRIVER_ENTRY DriverEntry; - VOID *EntryPointInImage; - - ZeroMem (&DriverEntry, sizeof (DriverEntry)); - CopyMem (&DriverEntry.FileName, &SmramProfileParameterRegisterImage->FileName, sizeof(EFI_GUID)); - DriverEntry.ImageBuffer = SmramProfileParameterRegisterImage->ImageBuffer; - DriverEntry.NumberOfPage = (UINTN) SmramProfileParameterRegisterImage->NumberOfPage; - Status = InternalPeCoffGetEntryPoint ((VOID *) (UINTN) DriverEntry.ImageBuffer, &EntryPointInImage); - ASSERT_EFI_ERROR (Status); - DriverEntry.ImageEntryPoint = (PHYSICAL_ADDRESS) (UINTN) EntryPointInImage; - - Status = RegisterSmramProfileImage (&DriverEntry, FALSE); - if (!EFI_ERROR (Status)) { - SmramProfileParameterRegisterImage->Header.ReturnStatus = 0; - } -} - -/** - SMRAM profile handler to unregister SMM image. - - @param SmramProfileParameterUnregisterImage The parameter of SMM profile unregister image. - -**/ -VOID -SmramProfileHandlerUnregisterImage ( - IN SMRAM_PROFILE_PARAMETER_UNREGISTER_IMAGE *SmramProfileParameterUnregisterImage - ) -{ - EFI_STATUS Status; - EFI_SMM_DRIVER_ENTRY DriverEntry; - VOID *EntryPointInImage; - - ZeroMem (&DriverEntry, sizeof (DriverEntry)); - CopyMem (&DriverEntry.FileName, &SmramProfileParameterUnregisterImage->FileName, sizeof (EFI_GUID)); - DriverEntry.ImageBuffer = SmramProfileParameterUnregisterImage->ImageBuffer; - DriverEntry.NumberOfPage = (UINTN) SmramProfileParameterUnregisterImage->NumberOfPage; - Status = InternalPeCoffGetEntryPoint ((VOID *) (UINTN) DriverEntry.ImageBuffer, &EntryPointInImage); - ASSERT_EFI_ERROR (Status); - DriverEntry.ImageEntryPoint = (PHYSICAL_ADDRESS) (UINTN) EntryPointInImage; - - Status = UnregisterSmramProfileImage (&DriverEntry, FALSE); - if (!EFI_ERROR (Status)) { - SmramProfileParameterUnregisterImage->Header.ReturnStatus = 0; - } -} - /** Dispatch function for a Software SMI handler. @@ -2374,28 +2316,6 @@ SmramProfileHandler ( } SmramProfileHandlerGetDataByOffset ((SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA_BY_OFFSET *) (UINTN) CommBuffer); break; - case SMRAM_PROFILE_COMMAND_REGISTER_IMAGE: - DEBUG ((EFI_D_ERROR, "SmramProfileHandlerRegisterImage\n")); - if (TempCommBufferSize != sizeof (SMRAM_PROFILE_PARAMETER_REGISTER_IMAGE)) { - DEBUG ((EFI_D_ERROR, "SmramProfileHandler: SMM communication buffer size invalid!\n")); - return EFI_SUCCESS; - } - if (mSmramReadyToLock) { - return EFI_SUCCESS; - } - SmramProfileHandlerRegisterImage ((SMRAM_PROFILE_PARAMETER_REGISTER_IMAGE *) (UINTN) CommBuffer); - break; - case SMRAM_PROFILE_COMMAND_UNREGISTER_IMAGE: - DEBUG ((EFI_D_ERROR, "SmramProfileHandlerUnregisterImage\n")); - if (TempCommBufferSize != sizeof (SMRAM_PROFILE_PARAMETER_UNREGISTER_IMAGE)) { - DEBUG ((EFI_D_ERROR, "SmramProfileHandler: SMM communication buffer size invalid!\n")); - return EFI_SUCCESS; - } - if (mSmramReadyToLock) { - return EFI_SUCCESS; - } - SmramProfileHandlerUnregisterImage ((SMRAM_PROFILE_PARAMETER_UNREGISTER_IMAGE *) (UINTN) CommBuffer); - break; case SMRAM_PROFILE_COMMAND_GET_RECORDING_STATE: DEBUG ((EFI_D_ERROR, "SmramProfileHandlerGetRecordingState\n")); if (TempCommBufferSize != sizeof (SMRAM_PROFILE_PARAMETER_RECORDING_STATE)) { diff --git a/MdeModulePkg/Include/Guid/MemoryProfile.h b/MdeModulePkg/Include/Guid/MemoryProfile.h index eee3b9125240..92cd1e7cf493 100644 --- a/MdeModulePkg/Include/Guid/MemoryProfile.h +++ b/MdeModulePkg/Include/Guid/MemoryProfile.h @@ -388,11 +388,6 @@ struct _EDKII_MEMORY_PROFILE_PROTOCOL { // #define SMRAM_PROFILE_COMMAND_GET_PROFILE_INFO 0x1 #define SMRAM_PROFILE_COMMAND_GET_PROFILE_DATA 0x2 -// -// Below 2 commands are now used by ECP only and only valid before SmmReadyToLock -// -#define SMRAM_PROFILE_COMMAND_REGISTER_IMAGE 0x3 -#define SMRAM_PROFILE_COMMAND_UNREGISTER_IMAGE 0x4 #define SMRAM_PROFILE_COMMAND_GET_PROFILE_DATA_BY_OFFSET 0x5 #define SMRAM_PROFILE_COMMAND_GET_RECORDING_STATE 0x6 -- 2.31.1
|
|
Re: [PATCH] UefiPayloadPkg/UefiPayloadEntry: Fix memory corruption
Ni, Ray
It's so lucky that no code calls AllocatePool so the bug didn't cause real issues. (I tried to remove AllocatePool() and build still passed.)
toggle quoted messageShow quoted text
Thanks for catching the bug. Reviewed-by: Ray Ni <ray.ni@...> Can you kindly share how you found this issue? Thanks, Ray
-----Original Message-----
From: Marvin Häuser <mhaeuser@...> Sent: Monday, August 9, 2021 3:40 AM To: devel@edk2.groups.io Cc: Dong, Guo <guo.dong@...>; Ni, Ray <ray.ni@...>; Ma, Maurice <maurice.ma@...>; You, Benjamin <benjamin.you@...>; Vitaly Cheptsov <vit9696@...> Subject: [PATCH] UefiPayloadPkg/UefiPayloadEntry: Fix memory corruption UefiPayloadEntry's AllocatePool() applies the "sizeof" operator to HOB index rather than the HOB header structure. This yields 4 Bytes compared to the 8 Bytes the structure header requires. Fix the call to allocate the required space instead. Cc: Guo Dong <guo.dong@...> Cc: Ray Ni <ray.ni@...> Cc: Maurice Ma <maurice.ma@...> Cc: Benjamin You <benjamin.you@...> Cc: Vitaly Cheptsov <vit9696@...> Signed-off-by: Marvin Häuser <mhaeuser@...> --- UefiPayloadPkg/UefiPayloadEntry/MemoryAllocation.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UefiPayloadPkg/UefiPayloadEntry/MemoryAllocation.c b/UefiPayloadPkg/UefiPayloadEntry/MemoryAllocation.c index 1204573b3e09..f3494969e5ac 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/MemoryAllocation.c +++ b/UefiPayloadPkg/UefiPayloadEntry/MemoryAllocation.c @@ -163,7 +163,7 @@ AllocatePool ( return NULL; } - Hob = (EFI_HOB_MEMORY_POOL *)CreateHob (EFI_HOB_TYPE_MEMORY_POOL, (UINT16)(sizeof (EFI_HOB_TYPE_MEMORY_POOL) + AllocationSize)); + Hob = (EFI_HOB_MEMORY_POOL *)CreateHob (EFI_HOB_TYPE_MEMORY_POOL, (UINT16)(sizeof (EFI_HOB_MEMORY_POOL) + AllocationSize)); return (VOID *)(Hob + 1); } -- 2.31.1
|
|
Re: [PATCH] SecurityPkg/DxeImageVerificationLib: Always lookup SHA-256 hash in dbx
Yao, Jiewen
Hi Marvin
toggle quoted messageShow quoted text
With this patch, the path "Action == EFI_IMAGE_EXECUTION_AUTH_SIG_FOUND" no longer exists. Do you think we should remove EFI_IMAGE_EXECUTION_AUTH_SIG_FOUND as well? Thank you Yao Jiewen
-----Original Message-----
|
|
[PATCH] MdeModulePkg PCD: FSP NotifyPhase APIs caused 100ms delay
GregX Yeh
https://bugzilla.tianocore.org/show_bug.cgi?id=3D3525
After PciSegmentLib using Dynamic PCD for Pcie base address such long delay found in FSP. The root cause is some of the PCD service PPIs not shadowed to memory and flash cache may have been disabled in NotifyPhase stage. Solution is to shadow all PCD service PPIs to memory. Signed-off-by: GregX Yeh <gregx.yeh@...> Cc: Jian J Wang <jian.j.wang@...> Cc: Hao A Wu <hao.a.wu@...> Cc: Dandan Bi <dandan.bi@...> Cc: Liming Gao <gaoliming@...> --- MdeModulePkg/Universal/PCD/Pei/Pcd.c | 71 +++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Universal/PCD/Pei/Pcd.c b/MdeModulePkg/Universal/= PCD/Pei/Pcd.c index 9c6346924f..f31e0be35f 100644 --- a/MdeModulePkg/Universal/PCD/Pei/Pcd.c +++ b/MdeModulePkg/Universal/PCD/Pei/Pcd.c @@ -1,7 +1,7 @@ /** @file=0D All Pcd Ppi services are implemented here.=0D =0D -Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>=0D +Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>=0D (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>=0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D @@ -339,6 +339,75 @@ PcdPeimInit ( {=0D EFI_STATUS Status;=0D =0D + Status =3D PeiServicesRegisterForShadow (FileHandle);=0D + if (Status =3D=3D EFI_ALREADY_STARTED) {=0D + //=0D + // This is now starting in memory, the second time starting.=0D + //=0D + EFI_PEI_PPI_DESCRIPTOR *OldPpiList;=0D + EFI_PEI_PPI_DESCRIPTOR *OldPpiList2;=0D + VOID *Ppi;=0D + VOID *Ppi2;=0D +=0D + OldPpiList =3D NULL;=0D + Status =3D PeiServicesLocatePpi (=0D + &gPcdPpiGuid,=0D + 0,=0D + &OldPpiList,=0D + &Ppi=0D + );=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + if (OldPpiList !=3D NULL) {=0D + Status =3D PeiServicesReInstallPpi (OldPpiList, &mPpiList[0]);=0D + ASSERT_EFI_ERROR (Status);=0D + }=0D +=0D + OldPpiList2 =3D NULL;=0D + Status =3D PeiServicesLocatePpi (=0D + &gGetPcdInfoPpiGuid,=0D + 0,=0D + &OldPpiList2,=0D + &Ppi2=0D + );=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + if (OldPpiList2 !=3D NULL) {=0D + Status =3D PeiServicesReInstallPpi (OldPpiList2, &mPpiList2[0]);=0D + ASSERT_EFI_ERROR (Status);=0D + }=0D +=0D + OldPpiList =3D NULL;=0D + Status =3D PeiServicesLocatePpi (=0D + &gEfiPeiPcdPpiGuid,=0D + 0,=0D + &OldPpiList,=0D + &Ppi=0D + );=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + if (OldPpiList !=3D NULL) {=0D + Status =3D PeiServicesReInstallPpi (OldPpiList, &mPpiList[1]);=0D + ASSERT_EFI_ERROR (Status);=0D + }=0D +=0D + OldPpiList2 =3D NULL;=0D + Status =3D PeiServicesLocatePpi (=0D + &gEfiGetPcdInfoPpiGuid,=0D + 0,=0D + &OldPpiList2,=0D + &Ppi2=0D + );=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + if (OldPpiList2 !=3D NULL) {=0D + Status =3D PeiServicesReInstallPpi (OldPpiList2, &mPpiList2[1]);=0D + ASSERT_EFI_ERROR (Status);=0D + }=0D +=0D + return Status;=0D + }=0D +=0D BuildPcdDatabase (FileHandle);=0D =0D //=0D --=20 2.32.0.windows.1
|
|
Re: [PATCH] SecurityPkg: TPM must go to Idle state on CRB command completion.
Yao, Jiewen
Would you please tell us how many TPM2 chip you have tested?
toggle quoted messageShow quoted text
I think we need consider the compatibility of exiting TPM2 chips, to make sure the code still work. Thank you Yao Jiewen
-----Original Message-----
|
|
Re: [PATCH] SecurityPkg: Debug code to audit BIOS TPM extend operations.
Yao, Jiewen
Some feedback:
toggle quoted messageShow quoted text
1) I think it is OK to add Tpm2PcrReadForActiveBank() API. But I feel we will add too many noise to dump Tpm2PcrReadForActiveBank() in the code everytime. I am not sure why it is needed. What is the problem statement? 2) Below definition does not follow EDKII coding style. Please use 2 "space" as indent. EFI_STATUS EFIAPI Tpm2PcrReadForActiveBank ( IN TPMI_DH_PCR PcrHandle, OUT TPML_DIGEST *HashList )
-----Original Message-----
|
|
Re: [PATCH] Reallocate TPM Active PCRs based on platform support.
Yao, Jiewen
Hi Rodrigo
toggle quoted messageShow quoted text
I don't understand the problem statement. This code has been there for long time. What is changed recently ? Thank you Yao Jiewen
-----Original Message-----
|
|
Re: [PATCH] SecurityPkg/DxeImageVerificationLib: Always lookup SHA-256 hash in dbx
Min Xu
On August 9, 2021 3:40 AM, Marvin Häuser wrote:
Subject: [PATCH] SecurityPkg/DxeImageVerificationLib: Always lookup SHA-256It seems there are 3 patches sent from Marvin Häuser and I suppose they're in one patch-set, right? Please follow the link below to send out patch-set for review. https://github.com/tianocore/tianocore.github.io/wiki/Laszlo's-unkempt-git-guide-for-edk2-contributors-and-maintainers For example, if there are 3 commits in one patch-set, then the subject of the commits looks like: [PATCH 0/4] This is the cover letter [PATCH 1/4] This is patch 1 Otherwise the reviewers are confused by the patches. Thanks! Xu, Min
|
|
[PATCH 2/3] efi_gdb.py: - Add gdb EFI commands and pretty Print
https://bugzilla.tianocore.org/show_bug.cgi?id=3500
Use efi_debugging.py Python Classes to implement EFI gdb commands: (gdb) help efi Commands for debugging EFI. efi <cmd> List of efi subcommands: efi devicepath -- Display an EFI device path. efi guid -- Display info about EFI GUID's. efi hob -- Dump EFI HOBs. Type 'hob -h' for more info. efi symbols -- Load Symbols for EFI. Type 'efi_symbols -h' for more info. efi table -- Dump EFI System Tables. Type 'table -h' for more info. This module is coded against a generic gdb remote serial stub. It should work with QEMU, JTAG debugger, or a generic EFI gdb remote serial stub. No modifications of EFI is required to load symbols. Example usage: OvmfPkg/build.sh qemu -gdb tcp::9000 gdb -ex "target remote localhost:9000" -ex "source efi_gdb.py" Cc: Leif Lindholm <leif@...> Cc: Michael D Kinney <michael.d.kinney@...> Cc: Hao A Wu <hao.a.wu@...> Signed-off-by: Andrew Fish <afish@...> --- efi_gdb.py | 918 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 918 insertions(+) create mode 100755 efi_gdb.py diff --git a/efi_gdb.py b/efi_gdb.py new file mode 100755 index 000000000000..f3e7fd9d0c28 --- /dev/null +++ b/efi_gdb.py @@ -0,0 +1,918 @@ +#!/usr/bin/python3 +''' +Copyright 2021 (c) Apple Inc. All rights reserved. +SPDX-License-Identifier: BSD-2-Clause-Patent + +EFI gdb commands based on efi_debugging classes. + +Example usage: +OvmfPkg/build.sh qemu -gdb tcp::9000 +gdb -ex "target remote localhost:9000" -ex "source efi_gdb.py" + +(gdb) help efi +Commands for debugging EFI. efi <cmd> + +List of efi subcommands: + +efi devicepath -- Display an EFI device path. +efi guid -- Display info about EFI GUID's. +efi hob -- Dump EFI HOBs. Type 'hob -h' for more info. +efi symbols -- Load Symbols for EFI. Type 'efi_symbols -h' for more info. +efi table -- Dump EFI System Tables. Type 'table -h' for more info. + +This module is coded against a generic gdb remote serial stub. It should work +with QEMU, JTAG debugger, or a generic EFI gdb remote serial stub. + +If you are debugging with QEMU or a JTAG hardware debugger you can insert +a CpuDeadLoop(); in your code, attach with gdb, and then `p Index=1` to +step past. If you have a debug stub in EFI you can use CpuBreakpoint();. +''' + +from gdb.printing import RegexpCollectionPrettyPrinter +from gdb.printing import register_pretty_printer +import gdb +import os +import sys +import uuid +import optparse +import shlex + +# gdb will not import from the same path as this script. +# so lets fix that for gdb... +sys.path.append(os.path.dirname(os.path.abspath(__file__))) + +from efi_debugging import PeTeImage, patch_ctypes # noqa: E402 +from efi_debugging import EfiHob, GuidNames, EfiStatusClass # noqa: E402 +from efi_debugging import EfiBootMode, EfiDevicePath # noqa: E402 +from efi_debugging import EfiConfigurationTable, EfiTpl # noqa: E402 + + +class GdbFileObject(object): + '''Provide a file like object required by efi_debugging''' + + def __init__(self): + self.inferior = gdb.selected_inferior() + self.offset = 0 + + def tell(self): + return self.offset + + def read(self, size=-1): + if size == -1: + # arbitrary default size + size = 0x1000000 + + try: + data = self.inferior.read_memory(self.offset, size) + except MemoryError: + data = bytearray(size) + assert False + if len(data) != size: + raise MemoryError( + f'gdb could not read memory 0x{size:x}' + + f' bytes from 0x{self.offset:08x}') + else: + # convert memoryview object to a bytestring. + return data.tobytes() + + def readable(self): + return True + + def seek(self, offset, whence=0): + if whence == 0: + self.offset = offset + elif whence == 1: + self.offset += offset + else: + # whence == 2 is seek from end + raise NotImplementedError + + def seekable(self): + return True + + def write(self, data): + self.inferior.write_memory(self.offset, data) + return len(data) + + def writable(self): + return True + + def truncate(self, size=None): + raise NotImplementedError + + def flush(self): + raise NotImplementedError + + def fileno(self): + raise NotImplementedError + + +class EfiSymbols: + """Class to manage EFI Symbols""" + + loaded = {} + stride = None + range = None + verbose = False + + def __init__(self, file=None): + EfiSymbols.file = file if file else GdbFileObject() + + @ classmethod + def __str__(cls): + return ''.join(f'{value}\n' for value in cls.loaded.values()) + + @ classmethod + def configure_search(cls, stride, range=None, verbose=False): + cls.stride = stride + cls.range = range + cls.verbose = verbose + + @ classmethod + def clear(cls): + cls.loaded = {} + + @ classmethod + def add_symbols_for_pecoff(cls, pecoff): + '''Tell lldb the location of the .text and .data sections.''' + + if pecoff.TextAddress in cls.loaded: + return 'Already Loaded: ' + try: + res = 'Loading Symbols Failed:' + res = gdb.execute('add-symbol-file ' + pecoff.CodeViewPdb + + ' ' + hex(pecoff.TextAddress) + + ' -s .data ' + hex(pecoff.DataAddress), + False, True) + + cls.loaded[pecoff.TextAddress] = pecoff + if cls.verbose: + print(f'\n{res:s}\n') + return '' + except gdb.error: + return res + + @ classmethod + def address_to_symbols(cls, address, reprobe=False): + ''' + Given an address search backwards for a PE/COFF (or TE) header + and load symbols. Return a status string. + ''' + if not isinstance(address, int): + address = int(address) + + pecoff = cls.address_in_loaded_pecoff(address) + if not reprobe and pecoff is not None: + # skip the probe of the remote + return f'{pecoff} is already loaded' + + pecoff = PeTeImage(cls.file, None) + if pecoff.pcToPeCoff(address, cls.stride, cls.range): + res = cls.add_symbols_for_pecoff(pecoff) + return f'{res}{pecoff}' + else: + return f'0x{address:08x} not in a PE/COFF (or TE) image' + + @ classmethod + def address_in_loaded_pecoff(cls, address): + if not isinstance(address, int): + address = int(address) + + for value in cls.loaded.values(): + if (address >= value.LoadAddress and + address <= value.EndLoadAddress): + return value + + return None + + @ classmethod + def unload_symbols(cls, address): + if not isinstance(address, int): + address = int(address) + + pecoff = cls.address_in_loaded_pecoff(address) + try: + res = 'Unloading Symbols Failed:' + res = gdb.execute( + f'remove-symbol-file -a {hex(pecoff.TextAddress):s}', + False, True) + del cls.loaded[pecoff.LoadAddress] + return res + except gdb.error: + return res + + +class CHAR16_PrettyPrinter(object): + + def __init__(self, val): + self.val = val + + def to_string(self): + if int(self.val) < 0x20: + return f"L'\\x{int(self.val):02x}'" + else: + return f"L'{chr(self.val):s}'" + + +class EFI_TPL_PrettyPrinter(object): + + def __init__(self, val): + self.val = val + + def to_string(self): + return str(EfiTpl(int(self.val))) + + +class EFI_STATUS_PrettyPrinter(object): + + def __init__(self, val): + self.val = val + + def to_string(self): + status = int(self.val) + return f'{str(EfiStatusClass(status)):s} (0x{status:08x})' + + +class EFI_BOOT_MODE_PrettyPrinter(object): + + def __init__(self, val): + self.val = val + + def to_string(self): + return str(EfiBootMode(int(self.val))) + + +class EFI_GUID_PrettyPrinter(object): + """Print 'EFI_GUID' as 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'""" + + def __init__(self, val): + self.val = val + + def to_string(self): + # if we could get a byte like object of *(unsigned char (*)[16]) + # then we could just use uuid.UUID() to convert + Data1 = int(self.val['Data1']) + Data2 = int(self.val['Data2']) + Data3 = int(self.val['Data3']) + Data4 = self.val['Data4'] + guid = f'{Data1:08X}-{Data2:04X}-' + guid += f'{Data3:04X}-' + guid += f'{int(Data4[0]):02X}{int(Data4[1]):02X}-' + guid += f'{int(Data4[2]):02X}{int(Data4[3]):02X}' + guid += f'{int(Data4[4]):02X}{int(Data4[5]):02X}' + guid += f'{int(Data4[6]):02X}{int(Data4[7]):02X}' + return str(GuidNames(guid)) + + +def build_pretty_printer(): + # Turn off via: disable pretty-printer global EFI + pp = RegexpCollectionPrettyPrinter("EFI") + # you can also tell gdb `x/sh <address>` to print CHAR16 string + pp.add_printer('CHAR16', '^CHAR16$', CHAR16_PrettyPrinter) + pp.add_printer('EFI_BOOT_MODE', '^EFI_BOOT_MODE$', + EFI_BOOT_MODE_PrettyPrinter) + pp.add_printer('EFI_GUID', '^EFI_GUID$', EFI_GUID_PrettyPrinter) + pp.add_printer('EFI_STATUS', '^EFI_STATUS$', EFI_STATUS_PrettyPrinter) + pp.add_printer('EFI_TPL', '^EFI_TPL$', EFI_TPL_PrettyPrinter) + return pp + + +class EfiDevicePathCmd (gdb.Command): + """Display an EFI device path. Type 'efi devicepath -h' for more info""" + + def __init__(self): + super(EfiDevicePathCmd, self).__init__( + "efi devicepath", gdb.COMMAND_NONE) + + self.file = GdbFileObject() + + def create_options(self, arg, from_tty): + usage = "usage: %prog [options] [arg]" + description = ( + "Command that can load EFI PE/COFF and TE image symbols. ") + + self.parser = optparse.OptionParser( + description=description, + prog='efi devicepath', + usage=usage, + add_help_option=False) + + self.parser.add_option( + '-v', + '--verbose', + action='store_true', + dest='verbose', + help='hex dump extra data', + default=False) + + self.parser.add_option( + '-n', + '--node', + action='store_true', + dest='node', + help='dump a single device path node', + default=False) + + self.parser.add_option( + '-h', + '--help', + action='store_true', + dest='help', + help='Show help for the command', + default=False) + + return self.parser.parse_args(shlex.split(arg)) + + def invoke(self, arg, from_tty): + '''gdb command to dump EFI device paths''' + + try: + (options, _) = self.create_options(arg, from_tty) + if options.help: + self.parser.print_help() + return + + dev_addr = int(gdb.parse_and_eval(arg)) + except ValueError: + print("Invalid argument!") + return + + if options.node: + print(EfiDevicePath( + self.file).device_path_node_str(dev_addr, + options.verbose)) + else: + device_path = EfiDevicePath(self.file, dev_addr, options.verbose) + if device_path.valid(): + print(device_path) + + +class EfiGuidCmd (gdb.Command): + """Display info about EFI GUID's. Type 'efi guid -h' for more info""" + + def __init__(self): + super(EfiGuidCmd, self).__init__("efi guid", + gdb.COMMAND_NONE, + gdb.COMPLETE_EXPRESSION) + self.file = GdbFileObject() + + def create_options(self, arg, from_tty): + usage = "usage: %prog [options] [arg]" + description = ( + "Show EFI_GUID values and the C name of the EFI_GUID variables" + "in the C code. If symbols are loaded the Guid.xref file" + "can be processed and the complete GUID database can be shown." + "This command also suports generating new GUID's, and showing" + "the value used to initialize the C variable.") + + self.parser = optparse.OptionParser( + description=description, + prog='efi guid', + usage=usage, + add_help_option=False) + + self.parser.add_option( + '-n', + '--new', + action='store_true', + dest='new', + help='Generate a new GUID', + default=False) + + self.parser.add_option( + '-v', + '--verbose', + action='store_true', + dest='verbose', + help='Also display GUID C structure values', + default=False) + + self.parser.add_option( + '-h', + '--help', + action='store_true', + dest='help', + help='Show help for the command', + default=False) + + return self.parser.parse_args(shlex.split(arg)) + + def invoke(self, arg, from_tty): + '''gdb command to dump EFI System Tables''' + + try: + (options, args) = self.create_options(arg, from_tty) + if options.help: + self.parser.print_help() + return + if len(args) >= 1: + # guid { 0x414e6bdd, 0xe47b, 0x47cc, + # { 0xb2, 0x44, 0xbb, 0x61, 0x02, 0x0c,0xf5, 0x16 }} + # this generates multiple args + guid = ' '.join(args) + except ValueError: + print('bad arguments!') + return + + if options.new: + guid = uuid.uuid4() + print(str(guid).upper()) + print(GuidNames.to_c_guid(guid)) + return + + if len(args) > 0: + if GuidNames.is_guid_str(arg): + # guid 05AD34BA-6F02-4214-952E-4DA0398E2BB9 + key = guid.upper() + name = GuidNames.to_name(key) + elif GuidNames.is_c_guid(arg): + # guid { 0x414e6bdd, 0xe47b, 0x47cc, + # { 0xb2, 0x44, 0xbb, 0x61, 0x02, 0x0c,0xf5, 0x16 }} + key = GuidNames.from_c_guid(arg) + name = GuidNames.to_name(key) + else: + # guid gEfiDxeServicesTableGuid + name = guid + try: + key = GuidNames.to_guid(name) + name = GuidNames.to_name(key) + except ValueError: + return + + extra = f'{GuidNames.to_c_guid(key)}: ' if options.verbose else '' + print(f'{key}: {extra}{name}') + + else: + for key, value in GuidNames._dict_.items(): + if options.verbose: + extra = f'{GuidNames.to_c_guid(key)}: ' + else: + extra = '' + print(f'{key}: {extra}{value}') + + +class EfiHobCmd (gdb.Command): + """Dump EFI HOBs. Type 'hob -h' for more info.""" + + def __init__(self): + super(EfiHobCmd, self).__init__("efi hob", gdb.COMMAND_NONE) + self.file = GdbFileObject() + + def create_options(self, arg, from_tty): + usage = "usage: %prog [options] [arg]" + description = ( + "Command that can load EFI PE/COFF and TE image symbols. ") + + self.parser = optparse.OptionParser( + description=description, + prog='efi hob', + usage=usage, + add_help_option=False) + + self.parser.add_option( + '-a', + '--address', + type="int", + dest='address', + help='Parse HOBs from address', + default=None) + + self.parser.add_option( + '-t', + '--type', + type="int", + dest='type', + help='Only dump HOBS of his type', + default=None) + + self.parser.add_option( + '-v', + '--verbose', + action='store_true', + dest='verbose', + help='hex dump extra data', + default=False) + + self.parser.add_option( + '-h', + '--help', + action='store_true', + dest='help', + help='Show help for the command', + default=False) + + return self.parser.parse_args(shlex.split(arg)) + + def invoke(self, arg, from_tty): + '''gdb command to dump EFI System Tables''' + + try: + (options, _) = self.create_options(arg, from_tty) + if options.help: + self.parser.print_help() + return + except ValueError: + print('bad arguments!') + return + + if options.address: + try: + value = gdb.parse_and_eval(options.address) + address = int(value) + except ValueError: + address = None + else: + address = None + + hob = EfiHob(self.file, + address, + options.verbose).get_hob_by_type(options.type) + print(hob) + + +class EfiTablesCmd (gdb.Command): + """Dump EFI System Tables. Type 'table -h' for more info.""" + + def __init__(self): + super(EfiTablesCmd, self).__init__("efi table", gdb.COMMAND_NONE) + + self.file = GdbFileObject() + + def create_options(self, arg, from_tty): + usage = "usage: %prog [options] [arg]" + description = "Dump EFI System Tables. Requires symbols to be loaded" + + self.parser = optparse.OptionParser( + description=description, + prog='efi table', + usage=usage, + add_help_option=False) + + self.parser.add_option( + '-h', + '--help', + action='store_true', + dest='help', + help='Show help for the command', + default=False) + + return self.parser.parse_args(shlex.split(arg)) + + def invoke(self, arg, from_tty): + '''gdb command to dump EFI System Tables''' + + try: + (options, _) = self.create_options(arg, from_tty) + if options.help: + self.parser.print_help() + return + except ValueError: + print('bad arguments!') + return + + gST = gdb.lookup_global_symbol('gST') + if gST is None: + print('Error: This command requires symbols for gST to be loaded') + return + + table = EfiConfigurationTable( + self.file, int(gST.value(gdb.selected_frame()))) + if table: + print(table, '\n') + + +class EfiSymbolsCmd (gdb.Command): + """Load Symbols for EFI. Type 'efi symbols -h' for more info.""" + + def __init__(self): + super(EfiSymbolsCmd, self).__init__("efi symbols", + gdb.COMMAND_NONE, + gdb.COMPLETE_EXPRESSION) + self.file = GdbFileObject() + self.gST = None + self.efi_symbols = EfiSymbols(self.file) + + def create_options(self, arg, from_tty): + usage = "usage: %prog [options]" + description = ( + "Command that can load EFI PE/COFF and TE image symbols. " + "If you are having trouble in PEI try adding --pei. " + "Given any address search backward for the PE/COFF (or TE header) " + "and then parse the PE/COFF image to get debug info. " + "The address can come from the current pc, pc values in the " + "frame, or an address provided to the command" + "") + + self.parser = optparse.OptionParser( + description=description, + prog='efi symbols', + usage=usage, + add_help_option=False) + + self.parser.add_option( + '-a', + '--address', + type="str", + dest='address', + help='Load symbols for image that contains address', + default=None) + + self.parser.add_option( + '-c', + '--clear', + action='store_true', + dest='clear', + help='Clear the cache of loaded images', + default=False) + + self.parser.add_option( + '-f', + '--frame', + action='store_true', + dest='frame', + help='Load symbols for current stack frame', + default=False) + + self.parser.add_option( + '-p', + '--pc', + action='store_true', + dest='pc', + help='Load symbols for pc', + default=False) + + self.parser.add_option( + '--pei', + action='store_true', + dest='pei', + help='Load symbols for PEI (searches every 4 bytes)', + default=False) + + self.parser.add_option( + '-e', + '--extended', + action='store_true', + dest='extended', + help='Try to load all symbols based on config tables', + default=False) + + self.parser.add_option( + '-r', + '--range', + type="long", + dest='range', + help='How far to search backward for start of PE/COFF Image', + default=None) + + self.parser.add_option( + '-s', + '--stride', + type="long", + dest='stride', + help='Boundary to search for PE/COFF header', + default=None) + + self.parser.add_option( + '-t', + '--thread', + action='store_true', + dest='thread', + help='Load symbols for the frames of all threads', + default=False) + + self.parser.add_option( + '-v', + '--verbose', + action='store_true', + dest='verbose', + help='Show more info on symbols loading in gdb', + default=False) + + self.parser.add_option( + '-h', + '--help', + action='store_true', + dest='help', + help='Show help for the command', + default=False) + + return self.parser.parse_args(shlex.split(arg)) + + def save_user_state(self): + self.pagination = gdb.parameter("pagination") + if self.pagination: + gdb.execute("set pagination off") + + self.user_selected_thread = gdb.selected_thread() + self.user_selected_frame = gdb.selected_frame() + + def restore_user_state(self): + self.user_selected_thread.switch() + self.user_selected_frame.select() + + if self.pagination: + gdb.execute("set pagination on") + + def canonical_address(self, address): + ''' + Scrub out 48-bit non canonical addresses + Raw frames in gdb can have some funky values + ''' + + # Skip lowest 256 bytes to avoid interrupt frames + if address > 0xFF and address < 0x00007FFFFFFFFFFF: + return True + if address >= 0xFFFF800000000000: + return True + + return False + + def pc_set_for_frames(self): + '''Return a set for the PC's in the current frame''' + pc_list = [] + frame = gdb.newest_frame() + while frame: + pc = int(frame.read_register('pc')) + if self.canonical_address(pc): + pc_list.append(pc) + frame = frame.older() + + return set(pc_list) + + def invoke(self, arg, from_tty): + '''gdb command to symbolicate all the frames from all the threads''' + + try: + (options, _) = self.create_options(arg, from_tty) + if options.help: + self.parser.print_help() + return + except ValueError: + print('bad arguments!') + return + + self.dont_repeat() + + self.save_user_state() + + if options.clear: + self.efi_symbols.clear() + return + + if options.pei: + # XIP code can be 4 byte aligned in the FV + options.stride = 4 + options.range = 0x100000 + self.efi_symbols.configure_search(options.stride, + options.range, + options.verbose) + + if options.thread: + thread_list = gdb.selected_inferior().threads() + else: + thread_list = (gdb.selected_thread(),) + + address = None + if options.address: + value = gdb.parse_and_eval(options.address) + address = int(value) + elif options.pc: + address = gdb.selected_frame().pc() + + if address: + res = self.efi_symbols.address_to_symbols(address) + print(res) + else: + + for thread in thread_list: + thread.switch() + + # You can not iterate over frames as you load symbols. Loading + # symbols changes the frames gdb can see due to inlining and + # boom. So we loop adding symbols for the current frame, and + # we test to see if new frames have shown up. If new frames + # show up we process those new frames. Thus 1st pass is the + # raw frame, and other passes are only new PC values. + NewPcSet = self.pc_set_for_frames() + while NewPcSet: + PcSet = self.pc_set_for_frames() + for pc in NewPcSet: + res = self.efi_symbols.address_to_symbols(pc) + print(res) + + NewPcSet = PcSet.symmetric_difference( + self.pc_set_for_frames()) + + # find the EFI System tables the 1st time + if self.gST is None: + gST = gdb.lookup_global_symbol('gST') + if gST is not None: + self.gST = int(gST.value(gdb.selected_frame())) + table = EfiConfigurationTable(self.file, self.gST) + else: + table = None + else: + table = EfiConfigurationTable(self.file, self.gST) + + if options.extended and table: + # load symbols from EFI System Table entry + for address, _ in table.DebugImageInfo(): + res = self.efi_symbols.address_to_symbols(address) + print(res) + + # sync up the GUID database from the build output + for m in gdb.objfiles(): + if GuidNames.add_build_guid_file(str(m.filename)): + break + + self.restore_user_state() + + +class EfiCmd (gdb.Command): + """Commands for debugging EFI. efi <cmd>""" + + def __init__(self): + super(EfiCmd, self).__init__("efi", + gdb.COMMAND_NONE, + gdb.COMPLETE_NONE, + True) + + def invoke(self, arg, from_tty): + '''default to loading symbols''' + if '-h' in arg or '--help' in arg: + gdb.execute('help efi') + else: + # default to loading all symbols + gdb.execute('efi symbols --extended') + + +class LoadEmulatorEfiSymbols(gdb.Breakpoint): + ''' + breakpoint for EmulatorPkg to load symbols + Note: make sure SecGdbScriptBreak is not optimized away! + Also turn off the dlopen() flow like on macOS. + ''' + def stop(self): + symbols = EfiSymbols() + # Emulator adds SizeOfHeaders so we need file alignment to search + symbols.configure_search(0x20) + + frame = gdb.newest_frame() + + try: + # gdb was looking at spill address, pre spill :( + LoadAddress = frame.read_register('rdx') + AddSymbolFlag = frame.read_register('rcx') + except gdb.error: + LoadAddress = frame.read_var('LoadAddress') + AddSymbolFlag = frame.read_var('AddSymbolFlag') + + if AddSymbolFlag == 1: + res = symbols.address_to_symbols(LoadAddress) + else: + res = symbols.unload_symbols(LoadAddress) + print(res) + + # keep running + return False + + +# Get python backtraces to debug errors in this script +gdb.execute("set python print-stack full") + +# tell efi_debugging how to walk data structures with pointers +try: + pointer_width = gdb.lookup_type('int').pointer().sizeof +except ValueError: + pointer_width = 8 +patch_ctypes(pointer_width) + +register_pretty_printer(None, build_pretty_printer(), replace=True) + +# gdb commands that we are adding +# add `efi` prefix gdb command +EfiCmd() + +# subcommands for `efi` +EfiSymbolsCmd() +EfiTablesCmd() +EfiHobCmd() +EfiDevicePathCmd() +EfiGuidCmd() + +# +bp = LoadEmulatorEfiSymbols('SecGdbScriptBreak', internal=True) +if bp.pending: + try: + gdb.selected_frame() + # Not the emulator so do this when you attach + gdb.execute('efi symbols --frame --extended', True) + gdb.execute('bt') + # If you want to skip the above commands comment them out + pass + except gdb.error: + # If you load the script and there is no target ignore the error. + pass +else: + # start the emulator + gdb.execute('run') -- 2.30.1 (Apple Git-130)
|
|