From nobody Mon Sep 16 19:19:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+114355+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+114355+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1706129857; cv=none; d=zohomail.com; s=zohoarc; b=cWgkM+tYVaHfkEmpenOp5onjuXlTcRNOZyFYrvQMj9iQo3MvLs5GraRKDlLvFcp+f/8+SrKWyCsG0jvUkE54agT+sHwgkrNrgKlKdxqcqf4xZvmlb7ecsGe90ZiI2fUBT6h+QOb9LsQWPHAT3kNIkdPVjo6MSRbr1ooCikpUChI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706129857; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=BTb9Ih3ot3/rIw3Cd4iJhuSFEZTiSam3/QGrQx94md0=; b=KDr92nw2Dtu8Yji8OIDRAh5Yn700NY1y2jaT99O+MUgYkXAON/zWep+qVOV49iS6/nJEjZ0n/gEF64BjztVad2IPhNBV4ySeHu/WFel2IK9GzHAVHeoER76zL+gUVv0v1CypYN1GVagAYDz9f2sP+kzt9lmBiTfj9vFRZkzFW/A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+114355+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706129857406281.10549531534696; Wed, 24 Jan 2024 12:57:37 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=BTb9Ih3ot3/rIw3Cd4iJhuSFEZTiSam3/QGrQx94md0=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706129856; v=1; b=CgAD1Dg7hEEJMCIIPNWwx5R023cdwx1cL3TEZ1BWN3TUvO0W8mZuMwFtbi6tnDuW27BvoWdG zz4BUVSmuLRfrBNilZZdJWswrTpgfKwPa+xewR9Zs6jbFCE+Ta4a3BbMVsJXd3GsGJ+dQZ2kqRv sr3boGxqj8yl9+B6OlxPA2Sg= X-Received: by 127.0.0.2 with SMTP id JyzJYY1788612xVWkGrneQ4X; Wed, 24 Jan 2024 12:57:36 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.35231.1706129856154771870 for ; Wed, 24 Jan 2024 12:57:36 -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 A954E1FB; Wed, 24 Jan 2024 12:58:20 -0800 (PST) X-Received: from beelzebub.ast.arm.com (u203625-lin.austin.arm.com [10.118.28.39]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C9FFB3F73F; Wed, 24 Jan 2024 12:57:35 -0800 (PST) From: "Sam Kaynor" To: devel@edk2.groups.io Cc: stuart.yoder@arm.com, Sam Kaynor , Ray Ni , Zhichao Gao Subject: [edk2-devel] [PATCH v1 2/3] ShellPkg: UefiShellDebug1CommandsLib: Image Execution Table in Dmem.c Date: Wed, 24 Jan 2024 14:56:05 -0600 Message-Id: <20240124205605.69439-3-Sam.Kaynor@arm.com> In-Reply-To: <20240124205605.69439-1-Sam.Kaynor@arm.com> References: <20240124205605.69439-1-Sam.Kaynor@arm.com> MIME-Version: 1.0 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,sam.kaynor@arm.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 10qAK793eptBoZitI6RRCrMvx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706129858426100005 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4352 Implemented dumping of the Image Execution Table using Dmem.c 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(+) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c b/ShellPkg/= 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 && *StrTai= l !=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 (&gEfiImageSecurityDatabaseGui= d, &ptr); + + NumberOfImages =3D ptr; + + ptr +=3D sizeof(NumberOfImages); + + 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 + ); + + ptr +=3D InfoPtr->InfoSize; + } + + 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 (&gEfiImageSecurityDatabaseG= uid, (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_TABLE)= , 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 (RtPropertiesTableAddress); } + if (ShellStatus =3D=3D SHELL_SUCCESS) { + ShellStatus =3D DisplayImageExecutionEntries (ImageExecutionTa= bleAddress); + } } =20 } else { diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Com= mandsLib.uni b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1C= ommandsLib.uni index 299b0ba44f31..eee9384e3ffb 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLi= b.uni +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLi= b.uni @@ -144,6 +144,9 @@ " UPDATE_CAPSULE = %d\r\n" " QUERY_CAPSULE_CAPABIL= ITIES %d\r\n" " QUERY_VARIABLE_INFO = %d\r\n" +#string STR_DMEM_IMG_EXE_TABLE #language en-US "\r\nImage Execution Tab= le\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 addre= ss not found.\r\n" #string STR_DMEM_ERR_GET_FAIL #language en-US "\r\n%H%s%N: Unable to g= et table information.\r\n" =20 --=20 2.25.1