From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 7840DD8094F for ; Mon, 4 Mar 2024 19:10:10 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=JRRrtDDu7rL/VDlQ9+piPc9nz/s47q4RazmGEd8Qmhg=; c=relaxed/simple; d=groups.io; h=Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References:From:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1709579409; v=1; b=w7BblYc3CORwUVcGPemz0/waXVDZtOlZsUhenISoruBgLN6Iawe+ng7YegnZymVrVPCWDIIw x9ZpCuYDovP4LUxJdB5ZJHV2sSOH3ApP7i1eVEa9BMJYnt+yizk3356x7Qd/HEH8IYEMLmMXsD8 1Q7mgXhcqEXsJut3TKJRVZeM= X-Received: by 127.0.0.2 with SMTP id Hz43YY7687511xQjn7LeRedv; Mon, 04 Mar 2024 11:10:09 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.166.1709579408098663879 for ; Mon, 04 Mar 2024 11:10:08 -0800 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 567A92F4; Mon, 4 Mar 2024 11:10:44 -0800 (PST) X-Received: from [10.119.35.208] (unknown [10.119.35.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 66E6A3F738; Mon, 4 Mar 2024 11:10:07 -0800 (PST) Message-ID: Date: Mon, 4 Mar 2024 13:10:06 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [edk2-devel] [PATCH v1 2/3] ShellPkg: UefiShellDebug1CommandsLib: Image Execution Table in Dmem.c To: Sam Kaynor , devel@edk2.groups.io Cc: Ray Ni , Zhichao Gao References: <20240124205605.69439-1-Sam.Kaynor@arm.com> <20240124205605.69439-3-Sam.Kaynor@arm.com> From: "Stuart Yoder" In-Reply-To: <20240124205605.69439-3-Sam.Kaynor@arm.com> Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,stuart.yoder@arm.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: fFCjOGh0pgpfxlJudqZrliFhx7686176AA= Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=w7BblYc3; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=arm.com (policy=none) Hi Sam, See inline comments... On 1/24/24 2:56 PM, Sam Kaynor wrote: > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4352 >=20 > Implemented dumping of the Image Execution Table using Dmem.c >=20 > Cc: Ray Ni > Cc: Zhichao Gao > Signed-off-by: Sam Kaynor > --- > ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c = | 139 ++++++++++++++++++++ > ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.= uni | 3 + > 2 files changed, 142 insertions(+) >=20 > diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c b/ShellPk= g/Library/UefiShellDebug1CommandsLib/Dmem.c > index 1ae7b1f3d85c..5b0730b75268 100644 > --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c > +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c > @@ -138,6 +138,142 @@ DisplayRtProperties ( > return (ShellStatus); > } > =20 > +/** > + Retrieve the ImageExecutionTable Entry ImageName from Device Path > + > + @param[in] Address The pointer to the ImageExecutionTable. > +**/ > +EFI_STATUS > +GetBaseName ( > + IN CHAR16 *FileName, > + OUT CHAR16 **BaseName > + ) > +{ > + UINT32 StrLen; > + CHAR16 *StrTail; > + > + StrLen =3D StrSize(FileName); > + > + for (StrTail =3D FileName + StrLen - 1; StrTail !=3D FileName && *StrT= ail !=3D L'\\'; StrTail--) { > + } > + > + if (StrTail =3D=3D FileName) { > + return EFI_NOT_FOUND; > + } > + *BaseName =3D StrTail+1; > + > + return EFI_SUCCESS; > +} > + > +/** > + Retrieve the ImageExecutionTable entries > + > + @param[in] Address The pointer to the ImageExecutionTable. > +**/ > +EFI_STATUS > +GetImageExecutionInfo ( > + IN UINT64 Address > + ) > +{ > + EFI_STATUS Status; > + EFI_IMAGE_EXECUTION_INFO *InfoPtr; > + VOID *ptr; > + CHAR16 *ImagePath; > + CHAR16 *ImageName; > + UINTN *NumberOfImages; > + CHAR16 *ActionType; > + > + Status =3D EfiGetSystemConfigurationTable (&gEfiImageSecurityDatabaseG= uid, &ptr); > + > + NumberOfImages =3D ptr; > + > + ptr +=3D sizeof(NumberOfImages); The arithmetic to advance to the table entries isn't super clear as written. I think you need to define a variable for the table header EFI_IMAGE_EXECUTION_INFO_TABLE and use that. The Memory Attribute Table is similar. Take a look at how they handled the pointer arithmetic here: https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Core/Dxe/Misc/Me= moryAttributesTable.c#L197 > + for (int Image =3D 0; Image < *NumberOfImages; Image++) { > + InfoPtr =3D ptr; > + ImagePath =3D ptr + sizeof(EFI_IMAGE_EXECUTION_INFO); > + > + GetBaseName(ImagePath,&ImageName); > + > + switch(InfoPtr->Action) { > + case EFI_IMAGE_EXECUTION_AUTHENTICATION: > + ActionType =3D L"AUTHENTICATION"; > + break; > + case EFI_IMAGE_EXECUTION_AUTH_UNTESTED: > + ActionType =3D L"AUTHENTICATION UNTESTED"; > + break; > + case EFI_IMAGE_EXECUTION_AUTH_SIG_FAILED: > + ActionType =3D L"AUTHENTICATION SIGNATURE FAILED"; > + break; > + case EFI_IMAGE_EXECUTION_AUTH_SIG_PASSED: > + ActionType =3D L"AUTHENTICATION SIGNATURE PASSED"; > + break; > + case EFI_IMAGE_EXECUTION_AUTH_SIG_NOT_FOUND: > + ActionType =3D L"AUTHENTICATION SIGNATURE NOT FOUND"; > + break; > + case EFI_IMAGE_EXECUTION_AUTH_SIG_FOUND: > + ActionType =3D L"AUTHENTICATION SIGNATURE FOUND"; > + break; > + case EFI_IMAGE_EXECUTION_POLICY_FAILED: > + ActionType =3D L"POILCY FAILED"; > + break; > + case EFI_IMAGE_EXECUTION_INITIALIZED: > + ActionType =3D L"INITIALIZED"; > + break; > + default: > + ActionType =3D L"invalid action"; > + } > + > + ShellPrintHiiEx( > + -1, > + -1, > + NULL, > + STRING_TOKEN (STR_DMEM_IMG_EXE_ENTRY), > + gShellDebug1HiiHandle, > + ImageName, > + ActionType > + ); When running this code I noticed that the column of action type strings were not aligned. Can you set a field width to align them? > + > + ptr +=3D InfoPtr->InfoSize; Move the above to the part of the for loop statement that increments for each iteration of the loop. > + } > + > + return Status; > +} > + > +/** > + Display the ImageExecutionTable entries > + > + @param[in] Address The pointer to the ImageExecutionTable. > +**/ > +SHELL_STATUS > +DisplayImageExecutionEntries ( > + IN UINT64 Address > + ) > +{ > + EFI_IMAGE_EXECUTION_INFO_TABLE *ImageExecutionTable; > + SHELL_STATUS ShellStatus; > + EFI_STATUS Status; > + > + ShellStatus =3D SHELL_SUCCESS; > + > + if (Address !=3D 0) { > + Status =3D EfiGetSystemConfigurationTable (&gEfiImageSecurityDatabas= eGuid, (VOID **)&ImageExecutionTable); > + if (EFI_ERROR (Status)) { > + ShellStatus =3D SHELL_NOT_FOUND; > + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMEM_ERR_GET_FAIL= ), gShellDebug1HiiHandle, L"ImageExecutionTable"); > + } else { > + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMEM_IMG_EXE_TABL= E), gShellDebug1HiiHandle); > + Status =3D GetImageExecutionInfo(Address); > + } > + } else { > + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMEM_ERR_NOT_FOUND)= , gShellDebug1HiiHandle, L"ImageExecutionTable"); > + } > + > + return (ShellStatus); > +} > + > + > + > STATIC CONST SHELL_PARAM_ITEM ParamList[] =3D { > { L"-mmio", TypeFlag }, > { L"-verbose", TypeFlag }, > @@ -368,6 +504,9 @@ ShellCommandRunDmem ( > if (ShellStatus =3D=3D SHELL_SUCCESS) { > ShellStatus =3D DisplayRtProperties (RtPropertiesTableAddre= ss); > } > + if (ShellStatus =3D=3D SHELL_SUCCESS) { > + ShellStatus =3D DisplayImageExecutionEntries (ImageExecution= TableAddress); > + } > } > =20 > } else { > diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1C= ommandsLib.uni b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug= 1CommandsLib.uni > index 299b0ba44f31..eee9384e3ffb 100644 > --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Commands= Lib.uni > +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Commands= Lib.uni > @@ -144,6 +144,9 @@ > " UPDATE_CAPSULE = %d\r\n" > " QUERY_CAPSULE_CAPA= BILITIES %d\r\n" > " QUERY_VARIABLE_INF= O %d\r\n" > +#string STR_DMEM_IMG_EXE_TABLE #language en-US "\r\nImage Execution T= able\r\n" > + "---------------------= -------------------\r\n" > +#string STR_DMEM_IMG_EXE_ENTRY #language en-US "%s: %s\r\n" > #string STR_DMEM_ERR_NOT_FOUND #language en-US "\r\n%H%s%N: Table ad= dress not found.\r\n" > #string STR_DMEM_ERR_GET_FAIL #language en-US "\r\n%H%s%N: Unable t= o get table information.\r\n" > =20 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#116339): https://edk2.groups.io/g/devel/message/116339 Mute This Topic: https://groups.io/mt/103940859/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-