From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.92.41.29]) by mx.groups.io with SMTP id smtpd.web12.711.1597091324333181984 for ; Mon, 10 Aug 2020 13:28:44 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@outlook.com header.s=selector1 header.b=Cys6GsGU; spf=pass (domain: outlook.com, ip: 40.92.41.29, mailfrom: michael.kubacki@outlook.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SK4NksoP2MfDHoQt0hpbYsb6aTsXd591VSWxab+hcZmB4bXIyKkhsdBb6ESJkwC0sRpaxiCMGgP69AFADVbSlglW3omVAfYtnwobkPmgfhlchU56lKuDTthcnvpH0VIAoyT/Zyw0Lva2L4Fdthb8S82oAosLR8QgLhxEwwnuZq7QPf0y01CTfxzZCMN58+w8O59dJCKwl0KjZb6uHEoV+sol73y40ucIhRLDMgLcAQW1dWsqduwdXCbMboKWlHg24cWpoEEdf12oxNlb9DnpsBYvFMhPuRTCSORGRc/LUwMT3k4JVkvxEZfm0ldoTCX3rOagWzGCglSgCNf/GfjlCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pGwT5iqyCWSm8xpelyc9aLi/z/3qdd9eCvVncB3/QKw=; b=XhwA5p2AOKDyMiNfzjkPdnxzJrv1ZyL0Zip43b9+evnj9XVqvadsMsbuSKnTQwe0/yKpBYmAOpFqNzrSCrawohLpXHpHXTMP/qUdBZYJmT8hpE5AwpgMbCKOIRZyWxKcVD1zNO+rIKTlnJe+Reh4W5V7mRwzOKPSRz8lqEHZzRY8rkizrAIaAp2cVq4sk87OI5woeQxhNxEGxuTuTKfHsvACWg8ybcsL512teTgpjEXZOy3LJuJkFLgBPcL/C5uychMRjtu7rCry3agBw91VreaqrLPTd3Vbb5zMRTHV7GPKrKKlFLnYB3OSBtYWnAYy3KDm1gxRYEYh08B8Whrt3A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pGwT5iqyCWSm8xpelyc9aLi/z/3qdd9eCvVncB3/QKw=; b=Cys6GsGUDa/NX/fQ6RQ9Fe6zEyz86AYRN4SOWBZhIVlSU8UMdRLEItFdHH9tJdpozKB5ka1JU7JMomlxTPYVI6hHcKYvBwx0of0TckGdiwXW/NfQqKn3rxOLKmSK3gYcymTLKdkJiZXSdPtD6Ev6JTaGAvZStozUBOcORJ1FYKkzlrgX+YjrM7py5NsacWNUm4PC5i61Vw9lLT58iLoPxOAQXgjf1WXH3Qsob6k3kTGNg2v0gxwjwN9X61oSqyVhPUoEFBS+MWene9OuG33WkiV/4aGjs+rEoKzDC0SbYzuJ36vCsU/cgPPsi7jF6Sv2F1AE+gtzRXlqMz6eyFP69w== Received: from MW2NAM10FT048.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e87::53) by MW2NAM10HT123.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e87::272) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.16; Mon, 10 Aug 2020 20:28:42 +0000 Received: from MWHPR07MB3440.namprd07.prod.outlook.com (2a01:111:e400:7e87::44) by MW2NAM10FT048.mail.protection.outlook.com (2a01:111:e400:7e87::98) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.16 via Frontend Transport; Mon, 10 Aug 2020 20:28:42 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:12CC2D2D25E212BBFD64C5B58DD65E7CD56E858B72ED618209A3D70C903C9523;UpperCasedChecksum:817D3AB969630193E069D66262490EE821328906EE41B4F3C4D8D82A2EC95EE0;SizeAsReceived:7804;Count:49 Received: from MWHPR07MB3440.namprd07.prod.outlook.com ([fe80::9856:570e:1735:974e]) by MWHPR07MB3440.namprd07.prod.outlook.com ([fe80::9856:570e:1735:974e%7]) with mapi id 15.20.3261.024; Mon, 10 Aug 2020 20:28:42 +0000 From: "Michael Kubacki" To: devel@edk2.groups.io CC: Liming Gao , Michael D Kinney , Guomin Jiang , Wei6 Xu Subject: [PATCH v2 5/6] FmpDevicePkg: Add Last Attempt Status support to dependency libs Date: Mon, 10 Aug 2020 13:27:52 -0700 Message-ID: X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20200810202753.1318-1-michael.kubacki@outlook.com> References: <20200810202753.1318-1-michael.kubacki@outlook.com> X-ClientProxiedBy: MWHPR13CA0008.namprd13.prod.outlook.com (2603:10b6:300:16::18) To MWHPR07MB3440.namprd07.prod.outlook.com (2603:10b6:301:69::28) Return-Path: michael.kubacki@outlook.com X-Microsoft-Original-Message-ID: <20200810202753.1318-6-michael.kubacki@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (2001:4898:80e8:1:cc6:648f:7db1:5bf9) by MWHPR13CA0008.namprd13.prod.outlook.com (2603:10b6:300:16::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.10 via Frontend Transport; Mon, 10 Aug 2020 20:28:42 +0000 X-Mailer: git-send-email 2.28.0.windows.1 X-Microsoft-Original-Message-ID: <20200810202753.1318-6-michael.kubacki@outlook.com> X-TMN: [58mmZZHS5pSkjgiFX1aSe3sBbDUPEl0Kh32Ts/dbtZ6d/i2klsIJZ47/io/L5B5D] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 49 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: e56245fc-e9fd-478f-e139-08d83d6bf92e X-MS-TrafficTypeDiagnostic: MW2NAM10HT123: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zhTeaJRx1KRgIV4J0Pny24LjRZkLx1qQTOUNDuBvqzYUv8o0H0mZ3hXHQdCfOQgH+aNNX6na8CjRUfPDMb5wEi8o6PHJaw8s1XF4po+oHPH4U3psi+FbFipkJnE7jO6Wz6/Wh6+8AW6iBtd/nSeZfAX1EpLpkjfjrsCl7i/hpXmBwQaeUfIZot4xwVFXyGvk6KAD3PqdUcExBsRWPInpUA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:0;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR07MB3440.namprd07.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:;DIR:OUT;SFP:1901; X-MS-Exchange-AntiSpam-MessageData: jAvn6LgBUJpDsiOaJzY1KJUGqKXuV9wUIOtAOgHTXjHMJKAaV9hJkVTTqNZ2zTO2lAexWaUd1663xT5Zx2X4JcKGjUjHGOv/H6iqUcEL+Hsp/fOw0rtUnmOYj2jnD5WYtA6V+15j29niddsfE0JbhAEw+rUx77yrKtSZi7NDw/Ju1m3YKt7l8Q3ioHwv7i6BQKmtHvUhm3gvVqFE3QSUSg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e56245fc-e9fd-478f-e139-08d83d6bf92e X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2020 20:28:42.6977 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: MW2NAM10FT048.eop-nam10.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2NAM10HT123 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain From: Michael Kubacki The FMP dependency libraries are leveraged during firmware update to check for dependencies required to update the image. This change adds granular Last Attempt Status code support to these services so failures can be more easily observed during the firmware update process via Last Attempt Status codes. Cc: Liming Gao Cc: Michael D Kinney Cc: Guomin Jiang Cc: Wei6 Xu Signed-off-by: Michael Kubacki --- FmpDevicePkg/FmpDxe/FmpDxe.c = | 25 +++++- FmpDevicePkg/Library/FmpDependencyCheckLib/FmpDependencyCheckLib.c = | 38 +++++--- FmpDevicePkg/Library/FmpDependencyCheckLibNull/FmpDependencyCheckLibNull.c= | 9 +- FmpDevicePkg/Library/FmpDependencyLib/FmpDependencyLib.c = | 95 +++++++++++++++++--- FmpDevicePkg/Test/UnitTest/Library/FmpDependencyLib/EvaluateDependencyUnit= Test.c | 7 +- FmpDevicePkg/Include/Library/FmpDependencyCheckLib.h = | 8 +- FmpDevicePkg/Include/Library/FmpDependencyLib.h = | 44 +++++---- 7 files changed, 179 insertions(+), 47 deletions(-) diff --git a/FmpDevicePkg/FmpDxe/FmpDxe.c b/FmpDevicePkg/FmpDxe/FmpDxe.c index aeb888c86bc3..84a8e15cfc17 100644 --- a/FmpDevicePkg/FmpDxe/FmpDxe.c +++ b/FmpDevicePkg/FmpDxe/FmpDxe.c @@ -929,7 +929,17 @@ CheckTheImageInternal ( // // Get the dependency from Image. // - Dependencies =3D GetImageDependency ((EFI_FIRMWARE_IMAGE_AUTHENTICATION = *)Image, ImageSize, &DependenciesSize); + Dependencies =3D GetImageDependency ( + (EFI_FIRMWARE_IMAGE_AUTHENTICATION *) Image, + ImageSize, + &DependenciesSize, + &LocalLastAttemptStatus + ); + if (LocalLastAttemptStatus !=3D LAST_ATTEMPT_STATUS_SUCCESS) { + Status =3D EFI_ABORTED; + *LastAttemptStatus =3D LocalLastAttemptStatus; + goto cleanup; + } =20 // // Check the FmpPayloadHeader @@ -968,11 +978,20 @@ CheckTheImageInternal ( // // Evaluate dependency expression // - Private->DependenciesSatisfied =3D CheckFmpDependency (Private->Descript= or.ImageTypeId, Version, Dependencies, DependenciesSize); + Private->DependenciesSatisfied =3D CheckFmpDependency ( + Private->Descriptor.ImageTypeId, + Version, + Dependencies, + DependenciesSize, + &LocalLastAttemptStatus + ); if (!Private->DependenciesSatisfied) { DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckTheImage() - Dependency check f= ailed.\n", mImageIdName)); *ImageUpdatable =3D IMAGE_UPDATABLE_INVALID; Status =3D EFI_SUCCESS; + if (LocalLastAttemptStatus !=3D LAST_ATTEMPT_STATUS_SUCCESS) { + *LastAttemptStatus =3D LocalLastAttemptStatus; + } goto cleanup; } =20 @@ -1184,7 +1203,7 @@ SetTheImage ( // // Get the dependency from Image. // - Dependencies =3D GetImageDependency ((EFI_FIRMWARE_IMAGE_AUTHENTICATION = *)Image, ImageSize, &DependenciesSize); + Dependencies =3D GetImageDependency ((EFI_FIRMWARE_IMAGE_AUTHENTICATION = *)Image, ImageSize, &DependenciesSize, &LastAttemptStatus); =20 // // No functional error in CheckTheImage. Attempt to get the Version to diff --git a/FmpDevicePkg/Library/FmpDependencyCheckLib/FmpDependencyCheckL= ib.c b/FmpDevicePkg/Library/FmpDependencyCheckLib/FmpDependencyCheckLib.c index 02ed600e0e95..d1e3b6b93bc2 100644 --- a/FmpDevicePkg/Library/FmpDependencyCheckLib/FmpDependencyCheckLib.c +++ b/FmpDevicePkg/Library/FmpDependencyCheckLib/FmpDependencyCheckLib.c @@ -17,6 +17,8 @@ #include #include #include +#include +#include =20 /** Check dependency for firmware update. @@ -25,6 +27,10 @@ @param[in] Version New version. @param[in] Dependencies Fmp dependency. @param[in] DependenciesSize Size, in bytes, of the Fmp dependency. + @param[out] LastAttemptStatus An optional pointer to a UINT32 that hold= s the + last attempt status to report back to the= caller. + A function error code may not always be a= ccompanied + by a last attempt status code. =20 @retval TRUE Dependencies are satisfied. @retval FALSE Dependencies are unsatisfied or dependency check fails. @@ -36,7 +42,8 @@ CheckFmpDependency ( IN EFI_GUID ImageTypeId, IN UINT32 Version, IN EFI_FIRMWARE_IMAGE_DEP *Dependencies, OPTIONAL - IN UINT32 DependenciesSize + IN UINT32 DependenciesSize, + OUT UINT32 *LastAttemptStatus OPTIONAL ) { EFI_STATUS Status; @@ -44,6 +51,7 @@ CheckFmpDependency ( UINTN Index; EFI_FIRMWARE_MANAGEMENT_PROTOCOL *Fmp; UINTN ImageInfoSize; + UINT32 LocalLastAttemptStatus; UINT32 *DescriptorVer; UINT8 FmpImageInfoCount; UINTN *DescriptorSize; @@ -55,14 +63,15 @@ CheckFmpDependency ( UINTN FmpVersionsCount; BOOLEAN IsSatisfied; =20 - FmpImageInfoBuf =3D NULL; - DescriptorVer =3D NULL; - DescriptorSize =3D NULL; - NumberOfFmpInstance =3D 0; - FmpVersions =3D NULL; - FmpVersionsCount =3D 0; - IsSatisfied =3D TRUE; - PackageVersionName =3D NULL; + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_SUCCESS; + FmpImageInfoBuf =3D NULL; + DescriptorVer =3D NULL; + DescriptorSize =3D NULL; + NumberOfFmpInstance =3D 0; + FmpVersions =3D NULL; + FmpVersionsCount =3D 0; + IsSatisfied =3D TRUE; + PackageVersionName =3D NULL; =20 // // Get ImageDescriptors of all FMP instances, and archive them for depen= dency evaluation. @@ -77,30 +86,35 @@ CheckFmpDependency ( if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "CheckFmpDependency: Get Firmware Management Prot= ocol failed. (%r)", Status)); IsSatisfied =3D FALSE; + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_MEMORY= _ALLOCATION_FAILED; goto cleanup; } =20 FmpImageInfoBuf =3D AllocateZeroPool (sizeof(EFI_FIRMWARE_IMAGE_DESCRIPT= OR *) * NumberOfFmpInstance); if (FmpImageInfoBuf =3D=3D NULL) { IsSatisfied =3D FALSE; + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_MEMORY= _ALLOCATION_FAILED; goto cleanup; } =20 DescriptorVer =3D AllocateZeroPool (sizeof(UINT32) * NumberOfFmpInstance= ); if (DescriptorVer =3D=3D NULL ) { IsSatisfied =3D FALSE; + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_MEMORY= _ALLOCATION_FAILED; goto cleanup; } =20 DescriptorSize =3D AllocateZeroPool (sizeof(UINTN) * NumberOfFmpInstance= ); if (DescriptorSize =3D=3D NULL ) { IsSatisfied =3D FALSE; + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_MEMORY= _ALLOCATION_FAILED; goto cleanup; } =20 FmpVersions =3D AllocateZeroPool (sizeof(FMP_DEPEX_CHECK_VERSION_DATA) *= NumberOfFmpInstance); if (FmpVersions =3D=3D NULL) { IsSatisfied =3D FALSE; + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_MEMORY= _ALLOCATION_FAILED; goto cleanup; } =20 @@ -164,7 +178,7 @@ CheckFmpDependency ( // Evaluate firmware image's depex, against the version of other Fmp ins= tances. // if (Dependencies !=3D NULL) { - IsSatisfied =3D EvaluateDependency (Dependencies, DependenciesSize, Fm= pVersions, FmpVersionsCount); + IsSatisfied =3D EvaluateDependency (Dependencies, DependenciesSize, Fm= pVersions, FmpVersionsCount, &LocalLastAttemptStatus); } =20 if (!IsSatisfied) { @@ -194,5 +208,9 @@ CheckFmpDependency ( FreePool (FmpVersions); } =20 + if (LastAttemptStatus !=3D NULL && LocalLastAttemptStatus !=3D LAST_ATTE= MPT_STATUS_SUCCESS) { + *LastAttemptStatus =3D LocalLastAttemptStatus; + } + return IsSatisfied; } diff --git a/FmpDevicePkg/Library/FmpDependencyCheckLibNull/FmpDependencyCh= eckLibNull.c b/FmpDevicePkg/Library/FmpDependencyCheckLibNull/FmpDependency= CheckLibNull.c index 55e9af22909d..8937fb56d919 100644 --- a/FmpDevicePkg/Library/FmpDependencyCheckLibNull/FmpDependencyCheckLibN= ull.c +++ b/FmpDevicePkg/Library/FmpDependencyCheckLibNull/FmpDependencyCheckLibN= ull.c @@ -1,6 +1,7 @@ /** @file Null instance of FmpDependencyCheckLib. =20 + Copyright (c) Microsoft Corporation.
Copyright (c) 2020, Intel Corporation. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent @@ -16,7 +17,10 @@ @param[in] Version New version. @param[in] Dependencies Fmp dependency. @param[in] DependenciesSize Size, in bytes, of the Fmp dependency. - + @param[out] LastAttemptStatus An optional pointer to a UINT32 that hold= s the + last attempt status to report back to the= caller. + A function error code may not always be a= ccompanied + by a last attempt status code. @retval TRUE Dependencies are satisfied. @retval FALSE Dependencies are unsatisfied or dependency check fails. =20 @@ -27,7 +31,8 @@ CheckFmpDependency ( IN EFI_GUID ImageTypeId, IN UINT32 Version, IN EFI_FIRMWARE_IMAGE_DEP *Dependencies, OPTIONAL - IN UINT32 DependenciesSize + IN UINT32 DependenciesSize, + OUT UINT32 *LastAttemptStatus OPTIONAL ) { return TRUE; diff --git a/FmpDevicePkg/Library/FmpDependencyLib/FmpDependencyLib.c b/Fmp= DevicePkg/Library/FmpDependencyLib/FmpDependencyLib.c index 5ef25d2415cf..2045570b0628 100644 --- a/FmpDevicePkg/Library/FmpDependencyLib/FmpDependencyLib.c +++ b/FmpDevicePkg/Library/FmpDependencyLib/FmpDependencyLib.c @@ -13,6 +13,8 @@ #include #include #include +#include +#include =20 // // Define the initial size of the dependency expression evaluation stack @@ -203,6 +205,10 @@ Pop ( parameter is optional and can be set to = NULL. @param[in] FmpVersionsCount Element count of the array. When FmpVers= ions is NULL, FmpVersionsCount must be 0. + @param[out] LastAttemptStatus An optional pointer to a UINT32 that hol= ds the + last attempt status to report back to th= e caller. + A function error code may not always be = accompanied + by a last attempt status code. =20 @retval TRUE Dependency expressions evaluate to TRUE. @retval FALSE Dependency expressions evaluate to FALSE. @@ -211,10 +217,11 @@ Pop ( BOOLEAN EFIAPI EvaluateDependency ( - IN EFI_FIRMWARE_IMAGE_DEP *Dependencies, - IN UINTN DependenciesSize, - IN FMP_DEPEX_CHECK_VERSION_DATA *FmpVersions OPTIONAL, - IN UINTN FmpVersionsCount + IN EFI_FIRMWARE_IMAGE_DEP *Dependencies, + IN UINTN DependenciesSize, + IN FMP_DEPEX_CHECK_VERSION_DATA *FmpVersions, OPTIONAL + IN UINTN FmpVersionsCount, + OUT UINT32 *LastAttemptStatus OPTIONAL ) { EFI_STATUS Status; @@ -224,6 +231,9 @@ EvaluateDependency ( DEPEX_ELEMENT Element2; GUID ImageTypeId; UINT32 Version; + UINT32 LocalLastAttemptStatus; + + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_SUCCESS; =20 // // Check if parameter is valid. @@ -249,6 +259,7 @@ EvaluateDependency ( case EFI_FMP_DEP_PUSH_GUID: if (Iterator + sizeof (EFI_GUID) >=3D (UINT8 *) Dependencies->Depend= encies + DependenciesSize) { DEBUG ((DEBUG_ERROR, "EvaluateDependency: GUID extends beyond end = of dependency expression!\n")); + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_GU= ID_BEYOND_DEPEX; goto Error; } =20 @@ -259,6 +270,7 @@ EvaluateDependency ( if(CompareGuid (&FmpVersions[Index].ImageTypeId, &ImageTypeId)){ Status =3D Push (FmpVersions[Index].Version, VersionType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERRO= R_PUSH_FAILURE; goto Error; } break; @@ -266,18 +278,21 @@ EvaluateDependency ( } if (Index =3D=3D FmpVersionsCount) { DEBUG ((DEBUG_ERROR, "EvaluateDependency: %g is not found!\n", &Im= ageTypeId)); + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_FM= P_NOT_FOUND; goto Error; } break; case EFI_FMP_DEP_PUSH_VERSION: if (Iterator + sizeof (UINT32) >=3D (UINT8 *) Dependencies->Dependen= cies + DependenciesSize ) { DEBUG ((DEBUG_ERROR, "EvaluateDependency: VERSION extends beyond e= nd of dependency expression!\n")); + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_VE= RSION_BEYOND_DEPEX; goto Error; } =20 Version =3D *(UINT32 *) (Iterator + 1); Status =3D Push (Version, VersionType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PU= SH_FAILURE; goto Error; } Iterator =3D Iterator + sizeof (UINT32); @@ -286,154 +301,191 @@ EvaluateDependency ( Iterator +=3D AsciiStrnLenS ((CHAR8 *) Iterator, DependenciesSize - = (Iterator - Dependencies->Dependencies)); if (Iterator =3D=3D (UINT8 *) Dependencies->Dependencies + Dependenc= iesSize) { DEBUG ((DEBUG_ERROR, "EvaluateDependency: STRING extends beyond en= d of dependency expression!\n")); + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_VE= RSION_STR_BEYOND_DEPEX; goto Error; } break; case EFI_FMP_DEP_AND: Status =3D Pop (&Element1, BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D Pop (&Element2, BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D Push (Element1.Value.Boolean & Element2.Value.Boolean, Bo= oleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PU= SH_FAILURE; goto Error; } break; case EFI_FMP_DEP_OR: Status =3D Pop (&Element1, BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D Pop(&Element2, BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D Push (Element1.Value.Boolean | Element2.Value.Boolean, Bo= oleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PU= SH_FAILURE; goto Error; } break; case EFI_FMP_DEP_NOT: Status =3D Pop (&Element1, BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D Push (!(Element1.Value.Boolean), BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PU= SH_FAILURE; goto Error; } break; case EFI_FMP_DEP_TRUE: Status =3D Push (TRUE, BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PU= SH_FAILURE; goto Error; } break; case EFI_FMP_DEP_FALSE: Status =3D Push (FALSE, BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PU= SH_FAILURE; goto Error; } break; case EFI_FMP_DEP_EQ: Status =3D Pop (&Element1, VersionType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D Pop (&Element2, VersionType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D (Element1.Value.Version =3D=3D Element2.Value.Version) ? = Push (TRUE, BooleanType) : Push (FALSE, BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PU= SH_FAILURE; goto Error; } break; case EFI_FMP_DEP_GT: Status =3D Pop (&Element1, VersionType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D Pop (&Element2, VersionType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D (Element1.Value.Version > Element2.Value.Version) ? Push= (TRUE, BooleanType) : Push (FALSE, BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PU= SH_FAILURE; goto Error; } break; case EFI_FMP_DEP_GTE: Status =3D Pop (&Element1, VersionType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D Pop (&Element2, VersionType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D (Element1.Value.Version >=3D Element2.Value.Version) ? Pu= sh (TRUE, BooleanType) : Push (FALSE, BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PU= SH_FAILURE; goto Error; } break; case EFI_FMP_DEP_LT: Status =3D Pop (&Element1, VersionType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D Pop (&Element2, VersionType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus=3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_POP= _FAILURE; goto Error; } Status =3D (Element1.Value.Version < Element2.Value.Version) ? Push= (TRUE, BooleanType) : Push (FALSE, BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PU= SH_FAILURE; goto Error; } break; case EFI_FMP_DEP_LTE: Status =3D Pop (&Element1, VersionType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D Pop (&Element2, VersionType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D (Element1.Value.Version <=3D Element2.Value.Version) ? Pu= sh (TRUE, BooleanType) : Push (FALSE, BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PU= SH_FAILURE; goto Error; } break; case EFI_FMP_DEP_END: Status =3D Pop (&Element1, BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } return Element1.Value.Boolean; default: DEBUG ((DEBUG_ERROR, "EvaluateDependency: Unknown Opcode - %02x!\n",= *Iterator)); + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_UNKN= OWN_OPCODE; goto Error; } Iterator++; } =20 DEBUG ((DEBUG_ERROR, "EvaluateDependency: No EFI_FMP_DEP_END Opcode in e= xpression!\n")); + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_NO_END_O= PCODE; =20 Error: + if (LastAttemptStatus !=3D NULL && LocalLastAttemptStatus !=3D LAST_ATTE= MPT_STATUS_SUCCESS) { + *LastAttemptStatus =3D LocalLastAttemptStatus; + } + return FALSE; } =20 /** Validate the dependency expression and output its size. =20 - @param[in] Dependencies Pointer to the EFI_FIRMWARE_IMAGE_DEP. - @param[in] MaxDepexSize Max size of the dependency. - @param[out] DepexSize Size of dependency. + @param[in] Dependencies Pointer to the EFI_FIRMWARE_IMAGE_DEP. + @param[in] MaxDepexSize Max size of the dependency. + @param[out] DepexSize Size of dependency. + @param[out] LastAttemptStatus An optional pointer to a UINT32 that hol= ds the + last attempt status to report back to th= e caller. + A function error code may not always be = accompanied + by a last attempt status code. =20 @retval TRUE The dependency expression is valid. @retval FALSE The dependency expression is invalid. @@ -444,7 +496,8 @@ EFIAPI ValidateDependency ( IN EFI_FIRMWARE_IMAGE_DEP *Dependencies, IN UINTN MaxDepexSize, - OUT UINT32 *DepexSize + OUT UINT32 *DepexSize, + OUT UINT32 *LastAttemptStatus OPTIONAL ) { UINT8 *Depex; @@ -489,20 +542,30 @@ ValidateDependency ( } return TRUE; default: + if (LastAttemptStatus !=3D NULL) { + *LastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_UNKNOW= N_OPCODE; + } return FALSE; } } =20 + if (LastAttemptStatus !=3D NULL) { + *LastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_NO_END_OP= CODE; + } + return FALSE; } =20 /** Get dependency from firmware image. =20 - @param[in] Image Points to the firmware image. - @param[in] ImageSize Size, in bytes, of the firmware image. - @param[out] DepexSize Size, in bytes, of the dependency. - + @param[in] Image Points to the firmware image. + @param[in] ImageSize Size, in bytes, of the firmware image. + @param[out] DepexSize Size, in bytes, of the dependency. + @param[out] LastAttemptStatus An optional pointer to a UINT32 that hol= ds the + last attempt status to report back to th= e caller. + A function error code may not always be = accompanied + by a last attempt status code. @retval The pointer to dependency. @retval Null =20 @@ -512,7 +575,8 @@ EFIAPI GetImageDependency ( IN EFI_FIRMWARE_IMAGE_AUTHENTICATION *Image, IN UINTN ImageSize, - OUT UINT32 *DepexSize + OUT UINT32 *DepexSize, + OUT UINT32 *LastAttemptStatus OPTIONAL ) { EFI_FIRMWARE_IMAGE_DEP *Depex; @@ -530,6 +594,9 @@ GetImageDependency ( // // Pointer overflow. Invalid image. // + if (LastAttemptStatus !=3D NULL) { + *LastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_GET_DEPE= X_FAILURE; + } return NULL; } =20 @@ -539,7 +606,7 @@ GetImageDependency ( // // Validate the dependency and get the size of dependency // - if (ValidateDependency (Depex, MaxDepexSize, DepexSize)) { + if (ValidateDependency (Depex, MaxDepexSize, DepexSize, LastAttemptStatu= s)) { return Depex; } =20 diff --git a/FmpDevicePkg/Test/UnitTest/Library/FmpDependencyLib/EvaluateDe= pendencyUnitTest.c b/FmpDevicePkg/Test/UnitTest/Library/FmpDependencyLib/Ev= aluateDependencyUnitTest.c index f8ccdd906f29..92a1ac815d51 100644 --- a/FmpDevicePkg/Test/UnitTest/Library/FmpDependencyLib/EvaluateDependenc= yUnitTest.c +++ b/FmpDevicePkg/Test/UnitTest/Library/FmpDependencyLib/EvaluateDependenc= yUnitTest.c @@ -1,6 +1,7 @@ /** @file Unit tests of EvaluateDependency API in FmpDependencyLib. =20 + Copyright (c) Microsoft Corporation.
Copyright (c) 2020, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -162,6 +163,7 @@ EvaluateDependencyTest ( { BASIC_TEST_CONTEXT *TestContext; BOOLEAN EvaluationResult; + UINT32 LastAttemptStatus; =20 TestContext =3D (BASIC_TEST_CONTEXT *)Context; =20 @@ -169,8 +171,9 @@ EvaluateDependencyTest ( (EFI_FIRMWARE_IMAGE_DEP *)TestContext->Dependencies= , TestContext->DependenciesSize, mFmpVersions, - sizeof(mFmpVersions)/sizeof(FMP_DEPEX_CHECK_VERSION= _DATA) - ); + sizeof(mFmpVersions)/sizeof(FMP_DEPEX_CHECK_VERSION= _DATA), + &LastAttemptStatus + ); =20 UT_ASSERT_EQUAL (EvaluationResult, TestContext->ExpectedResult); =20 diff --git a/FmpDevicePkg/Include/Library/FmpDependencyCheckLib.h b/FmpDevi= cePkg/Include/Library/FmpDependencyCheckLib.h index ec380c4947bd..708cbb06ba74 100644 --- a/FmpDevicePkg/Include/Library/FmpDependencyCheckLib.h +++ b/FmpDevicePkg/Include/Library/FmpDependencyCheckLib.h @@ -2,6 +2,7 @@ Fmp Capsule Dependency check functions for Firmware Management Protocol = based firmware updates. =20 + Copyright (c) Microsoft Corporation.
Copyright (c) 2020, Intel Corporation. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent @@ -21,6 +22,10 @@ @param[in] Version New version. @param[in] Dependencies Fmp dependency. @param[in] DependenciesSize Size, in bytes, of the Fmp dependency. + @param[out] LastAttemptStatus An optional pointer to a UINT32 that hold= s the + last attempt status to report back to the= caller. + A function error code may not always be a= ccompanied + by a last attempt status code. =20 @retval TRUE Dependencies are satisfied. @retval FALSE Dependencies are unsatisfied or dependency check fails. @@ -32,7 +37,8 @@ CheckFmpDependency ( IN EFI_GUID ImageTypeId, IN UINT32 Version, IN EFI_FIRMWARE_IMAGE_DEP *Dependencies, OPTIONAL - IN UINT32 DependenciesSize + IN UINT32 DependenciesSize, + OUT UINT32 *LastAttemptStatus OPTIONAL ); =20 #endif diff --git a/FmpDevicePkg/Include/Library/FmpDependencyLib.h b/FmpDevicePkg= /Include/Library/FmpDependencyLib.h index c732903425b4..b8e9c4341165 100644 --- a/FmpDevicePkg/Include/Library/FmpDependencyLib.h +++ b/FmpDevicePkg/Include/Library/FmpDependencyLib.h @@ -26,9 +26,13 @@ typedef struct { /** Validate the dependency expression and output its size. =20 - @param[in] Dependencies Pointer to the EFI_FIRMWARE_IMAGE_DEP. - @param[in] MaxDepexSize Max size of the dependency. - @param[out] DepexSize Size of dependency. + @param[in] Dependencies Pointer to the EFI_FIRMWARE_IMAGE_DEP. + @param[in] MaxDepexSize Max size of the dependency. + @param[out] DepexSize Size of dependency. + @param[out] LastAttemptStatus An optional pointer to a UINT32 that hol= ds the + last attempt status to report back to th= e caller. + A function error code may not always be = accompanied + by a last attempt status code. =20 @retval TRUE The dependency expression is valid. @retval FALSE The dependency expression is invalid. @@ -39,16 +43,20 @@ EFIAPI ValidateDependency ( IN EFI_FIRMWARE_IMAGE_DEP *Dependencies, IN UINTN MaxDepexSize, - OUT UINT32 *DepexSize + OUT UINT32 *DepexSize, + OUT UINT32 *LastAttemptStatus OPTIONAL ); =20 /** Get dependency from firmware image. =20 - @param[in] Image Points to the firmware image. - @param[in] ImageSize Size, in bytes, of the firmware image. - @param[out] DepexSize Size, in bytes, of the dependency. - + @param[in] Image Points to the firmware image. + @param[in] ImageSize Size, in bytes, of the firmware image. + @param[out] DepexSize Size, in bytes, of the dependency. + @param[out] LastAttemptStatus An optional pointer to a UINT32 that hol= ds the + last attempt status to report back to th= e caller. + A function error code may not always be = accompanied + by a last attempt status code. @retval The pointer to dependency. @retval Null =20 @@ -56,9 +64,10 @@ ValidateDependency ( EFI_FIRMWARE_IMAGE_DEP* EFIAPI GetImageDependency ( - IN EFI_FIRMWARE_IMAGE_AUTHENTICATION *Image, - IN UINTN ImageSize, - OUT UINT32 *DepexSize + IN EFI_FIRMWARE_IMAGE_AUTHENTICATION *Image, + IN UINTN ImageSize, + OUT UINT32 *DepexSize, + OUT UINT32 *LastAttemptStatus OPTIONAL ); =20 /** @@ -73,6 +82,10 @@ GetImageDependency ( parameter is optional and can be set to = NULL. @param[in] FmpVersionsCount Element count of the array. When FmpVers= ions is NULL, FmpVersionsCount must be 0. + @param[out] LastAttemptStatus An optional pointer to a UINT32 that hol= ds the + last attempt status to report back to th= e caller. + A function error code may not always be = accompanied + by a last attempt status code. =20 @retval TRUE Dependency expressions evaluate to TRUE. @retval FALSE Dependency expressions evaluate to FALSE. @@ -81,10 +94,11 @@ GetImageDependency ( BOOLEAN EFIAPI EvaluateDependency ( - IN EFI_FIRMWARE_IMAGE_DEP *Dependencies, - IN UINTN DependenciesSize, - IN FMP_DEPEX_CHECK_VERSION_DATA *FmpVersions OPTIONAL, - IN UINTN FmpVersionsCount + IN EFI_FIRMWARE_IMAGE_DEP *Dependencies, + IN UINTN DependenciesSize, + IN FMP_DEPEX_CHECK_VERSION_DATA *FmpVersions, OPTIONAL + IN UINTN FmpVersionsCount, + OUT UINT32 *LastAttemptStatus OPTIONAL ); =20 #endif --=20 2.28.0.windows.1