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 8B062AC0A0E for ; Thu, 15 Feb 2024 03:31:20 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=CPtHLIwGGR7vxj6X+VouT/I1EukgZNtYoLuRw80jGd4=; 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=1707967879; v=1; b=AV2rZa+TzMcRsAUuT2a78gfKA91aUiXNOqBfqKeIlEopmhpBuAFlP7QNxaGqbOdXd+SHSdiT oKy57Ml/zJR4IDmib8OoKU/qnsLA41V9jVVFN47DEO03RH/lQbrID9hfqj0ucKaZTRNyAuZVGLF NeX2/uvDJnKwd2f2RLsM4eBM= X-Received: by 127.0.0.2 with SMTP id XQj9YY7687511xCuB8ZakwYK; Wed, 14 Feb 2024 19:31:19 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.6410.1707967878453574846 for ; Wed, 14 Feb 2024 19:31:18 -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 CF157DA7; Wed, 14 Feb 2024 19:31:58 -0800 (PST) X-Received: from beelzebub.ast.arm.com (abhsin07-ThinkStation-P720.austin.arm.com [10.118.30.31]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 110153F7B4; Wed, 14 Feb 2024 19:31:18 -0800 (PST) From: "Abhimanyu Singh" To: devel@edk2.groups.io Cc: "Abhi.Singh" , G Edhaya Chandran , Barton Gao , Carolyn Gjertsen Subject: [edk2-devel] [PATCH v3 1/7] uefi-sct/SctPkg: TCG Platform Reset Check Test Date: Wed, 14 Feb 2024 21:30:50 -0600 Message-Id: <20240215033056.331060-2-Abhi.Singh@arm.com> In-Reply-To: <20240215033056.331060-1-Abhi.Singh@arm.com> References: <20240215033056.331060-1-Abhi.Singh@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,Abhi.Singh@arm.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: j0u11gX1W9igcpNeA4s18XKqx7686176AA= 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=AV2rZa+T; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=arm.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io From: "Abhi.Singh" SCT spec: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4374 BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4419 -Implement initial test infrastructure for all test cases including updates to: CommonGenFramework.sh, UEFI_SCT.dsc, and Category.ini. -Add Guid.c and Guid.h files to cover the assertions 4/49 assertions defined in the SCT spec -Add TCGMemoryOverwriteRequestBBTestMain.h alongside used define/global variables -Add Platform Reset Check Test -check if the platform creates the MOR & MORLOCK EFI variables as defined in the TCG Spec -sets MOR bit 0 and validate if the platform clears the MOR bit 0 upon reset. Cc: G Edhaya Chandran Cc: Barton Gao Cc: Carolyn Gjertsen Signed-off-by: Abhi Singh --- uefi-sct/SctPkg/UEFI/UEFI_SCT.dsc = | 1 + uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteReques= t/BlackBoxTest/TCGMemoryOverwriteRequestBBTest.inf | 53 +++ uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteReques= t/BlackBoxTest/Guid.h | 46 +++ uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteReques= t/BlackBoxTest/TCGMemoryOverwriteRequestBBTestMain.h | 95 +++++ uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteReques= t/BlackBoxTest/Guid.c | 37 ++ uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteReques= t/BlackBoxTest/TCGMemoryOverwriteRequestBBTestFunction.c | 410 ++++++++++++= ++++++++ uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteReques= t/BlackBoxTest/TCGMemoryOverwriteRequestBBTestMain.c | 115 ++++++ uefi-sct/SctPkg/CommonGenFramework.sh = | 1 + uefi-sct/SctPkg/Config/Data/Category.ini = | 7 + 9 files changed, 765 insertions(+) diff --git a/uefi-sct/SctPkg/UEFI/UEFI_SCT.dsc b/uefi-sct/SctPkg/UEFI/UEFI_= SCT.dsc index 155490fa39d3..536d5f2ed37a 100644 --- a/uefi-sct/SctPkg/UEFI/UEFI_SCT.dsc +++ b/uefi-sct/SctPkg/UEFI/UEFI_SCT.dsc @@ -235,6 +235,7 @@ [Components] SctPkg/TestCase/UEFI/EFI/RuntimeServices/MiscRuntimeServices/BlackBoxTest/= MiscRuntimeServicesBBTest.inf=0D SctPkg/TestCase/UEFI/EFI/RuntimeServices/TimeServices/BlackBoxTest/TimeSer= vicesBBTest.inf=0D SctPkg/TestCase/UEFI/EFI/RuntimeServices/VariableServices/BlackBoxTest/Var= iableServicesBBTest.inf=0D +SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBo= xTest/TCGMemoryOverwriteRequestBBTest.inf=0D =0D SctPkg/TestCase/UEFI/EFI/Protocol/GraphicsOutput/BlackBoxTest/GraphicsOutp= utBBTest.inf=0D SctPkg/TestCase/UEFI/EFI/Protocol/Bis/BlackBoxTest/BisBBTest.inf=0D diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOve= rwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTest.inf b/uefi-sct/S= ctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxT= est/TCGMemoryOverwriteRequestBBTest.inf new file mode 100644 index 000000000000..35d82043e2e7 --- /dev/null +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteR= equest/BlackBoxTest/TCGMemoryOverwriteRequestBBTest.inf @@ -0,0 +1,53 @@ +## @file=0D +#=0D +# Copyright 2006 - 2015 Unified EFI, Inc.
=0D +# Copyright (c) 2013, Intel Corporation. All rights reserved.
=0D +# Copyright (c) 2023, Arm Inc. All rights reserved.
=0D +#=0D +# This program and the accompanying materials=0D +# are licensed and made available under the terms and conditions of the B= SD License=0D +# which accompanies this distribution. The full text of the license may = be found at=0D +# http://opensource.org/licenses/bsd-license.php=0D +#=0D +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,=0D +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IM= PLIED.=0D +#=0D +##=0D +#/*++=0D +#=0D +# Module Name:=0D +#=0D +# TCGMemoryOverwriteRequestBBTest.inf=0D +#=0D +# Abstract:=0D +#=0D +# Component description file for TCG MemoryOverwriteRequest UEFI variabl= es Test.=0D +#=0D +#--*/=0D +=0D +[defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D TCGMemoryOverwriteRequestBBTest=0D + FILE_GUID =3D ACA989CD-4AEE-45A3-B80F-E9A523BB7164=0D + MODULE_TYPE =3D UEFI_DRIVER=0D + VERSION_STRING =3D 1.0=0D + ENTRY_POINT =3D InitializeTestTCGMemoryOverwriteRequest=0D +=0D +[sources.common]=0D + TCGMemoryOverwriteRequestBBTestMain.c=0D + TCGMemoryOverwriteRequestBBTestMain.h=0D + TCGMemoryOverwriteRequestBBTestFunction.c=0D + Guid.c=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + SctPkg/SctPkg.dec=0D + SctPkg/UEFI/UEFI.dec=0D +=0D +[LibraryClasses]=0D + UefiDriverEntryPoint=0D + SctLib=0D + EfiTestLib=0D +=0D +[Protocols]=0D + gEfiTestRecoveryLibraryGuid=0D diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOve= rwriteRequest/BlackBoxTest/Guid.h b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Runti= meServices/TCGMemoryOverwriteRequest/BlackBoxTest/Guid.h new file mode 100644 index 000000000000..a3d87a3eb764 --- /dev/null +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteR= equest/BlackBoxTest/Guid.h @@ -0,0 +1,46 @@ +/** @file=0D +=0D + Copyright 2006 - 2016 Unified EFI, Inc.
=0D + Copyright (c) 2013, Intel Corporation. All rights reserved.
=0D + Copyright (c) 2023, Arm Inc. All rights reserved.
=0D +=0D + This program and the accompanying materials=0D + are licensed and made available under the terms and conditions of the BS= D License=0D + which accompanies this distribution. The full text of the license may b= e found at=0D + http://opensource.org/licenses/bsd-license.php=0D +=0D + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,=0D + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED.=0D +=0D +**/=0D +/*++=0D +=0D +Module Name:=0D +=0D + guid.h=0D +=0D +Abstract:=0D +=0D + GUIDs auto-generated for EFI test assertion.=0D +=0D +--*/=0D +=0D +#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_001_GUID \=0D +{ 0xd1c31d5f, 0x944f, 0x434c, {0x88, 0x26, 0xa6, 0xfb, 0x00, 0xd4, 0xbb, 0= x97 }}=0D +=0D +#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_002_GUID \=0D +{ 0xa6c191b1, 0x9bfb, 0x4231, {0xb9, 0x2d, 0x4e, 0xa2, 0x21, 0xf6, 0x4b, 0= x5d }}=0D +=0D +#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_003_GUID \=0D +{ 0x34d41a18, 0x8ffe, 0x456b, {0xa4, 0x82, 0x97, 0xb9, 0x9c, 0x50, 0x7d, 0= x9e }}=0D +=0D +#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_004_GUID \=0D +{ 0x002519c6, 0x859f, 0x4d25, {0xb1, 0x36, 0xb2, 0xef, 0x61, 0xe5, 0xd9, 0= x6f }}=0D +=0D +extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid001;=0D +=0D +extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid002;=0D +=0D +extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid003;=0D +=0D +extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid004;=0D diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOve= rwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestMain.h b/uefi-sct= /SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBo= xTest/TCGMemoryOverwriteRequestBBTestMain.h new file mode 100644 index 000000000000..45bd921ecca4 --- /dev/null +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteR= equest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestMain.h @@ -0,0 +1,95 @@ +/** @file=0D +=0D + Copyright 2006 - 2017 Unified EFI, Inc.
=0D + Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.
=0D + Copyright (c) 2023, Arm Inc. All rights reserved.
=0D +=0D + This program and the accompanying materials=0D + are licensed and made available under the terms and conditions of the BS= D License=0D + which accompanies this distribution. The full text of the license may b= e found at=0D + http://opensource.org/licenses/bsd-license.php=0D +=0D + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,=0D + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED.=0D +=0D +**/=0D +/*++=0D +=0D +Module Name:=0D +=0D + TCGMemoryOverwriteRequestTest.h=0D +=0D +Abstract:=0D +=0D + Test Driver of TCG MOR and MORLOCK EFI variables that are defined inside= =0D + TCG Platform Reset Attack Mitigation v1.10 Section 4 (UEFI Interface)=0D +=0D +--*/=0D +=0D +#ifndef _TCG_MOR_BB_TEST_MAIN=0D +#define _TCG_MOR_BB_TEST_MAIN=0D +=0D +#include "Efi.h"=0D +#include "Guid.h"=0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +typedef struct _RESET_DATA {=0D + UINTN Step;=0D + UINTN CheckpointStep;=0D +} RESET_DATA;=0D +=0D +#include EFI_TEST_PROTOCOL_DEFINITION(TestRecoveryLibrary)=0D +=0D +#define TCG_MOR_TEST_REVISION 0x00010000=0D +=0D +#define MOR_BIT_LOW 0x0=0D +#define MOR_BIT_HIGH 0x1=0D +=0D +#define MOR_LOCK_DATA_UNLOCKED 0x0=0D +=0D +=0D +//=0D +// TEST GUID for TCG Platform Reset Attack Mitigation MemoryOverwriteReque= st (MOR) Test=0D +//=0D +#define EFI_TCG_MOR_TEST_GUID \=0D + { 0x265e661d, 0xd51e, 0x454b, {0xbb, 0xc9, 0x66, 0x5f, 0x46, 0xec, 0x0a,= 0x04 }}=0D +=0D +EFI_STATUS=0D +EFIAPI=0D +InitializeTestTCGMemoryOverwriteRequest (=0D + IN EFI_HANDLE ImageHandle,=0D + IN EFI_SYSTEM_TABLE *SystemTable=0D + );=0D +=0D +EFI_STATUS=0D +EFIAPI=0D +UnloadTCGMemoryOverwriteRequestTest (=0D + IN EFI_HANDLE ImageHandle=0D + );=0D +=0D +EFI_STATUS=0D +BBTestTCGMemoryOverwriteRequestFunctionTest (=0D + IN EFI_BB_TEST_PROTOCOL *This,=0D + IN VOID *ClientInterface,=0D + IN EFI_TEST_LEVEL TestLevel,=0D + IN EFI_HANDLE SupportHandle=0D + );=0D +=0D +EFI_STATUS=0D +TCGMemoryOverwriteRequestPlatformResetCheck (=0D + IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib,=0D + IN EFI_TEST_RECOVERY_LIBRARY_PROTOCOL *RecoveryLib,=0D + IN RESET_DATA *ResetData=0D + );=0D +=0D +// ***********************************************************************= *****=0D +// Entry GUIDs for Test=0D +// ***********************************************************************= *****=0D +=0D +#define EFI_TCG_MOR_TEST_ENTRY_GUID0101 \=0D + { 0x2104436a, 0x77c8, 0x4514, {0xb7, 0xd7, 0xaa, 0x8a, 0x6b, 0xd1, 0x8d,= 0xa4 }}=0D +=0D +#endif=0D diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOve= rwriteRequest/BlackBoxTest/Guid.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Runti= meServices/TCGMemoryOverwriteRequest/BlackBoxTest/Guid.c new file mode 100644 index 000000000000..59c798a710f1 --- /dev/null +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteR= equest/BlackBoxTest/Guid.c @@ -0,0 +1,37 @@ +/** @file=0D +=0D + Copyright 2006 - 2013 Unified EFI, Inc.
=0D + Copyright (c) 2013, Intel Corporation. All rights reserved.
=0D + Copyright (c) 2023, Arm Inc. All rights reserved.
=0D +=0D + This program and the accompanying materials=0D + are licensed and made available under the terms and conditions of the BS= D License=0D + which accompanies this distribution. The full text of the license may b= e found at=0D + http://opensource.org/licenses/bsd-license.php=0D +=0D + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,=0D + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED.=0D +=0D +**/=0D +/*++=0D +=0D +Module Name:=0D +=0D + guid.c=0D +=0D +Abstract:=0D +=0D + GUIDs auto-generated for EFI test assertion.=0D +=0D +--*/=0D +=0D +#include "Efi.h"=0D +#include "Guid.h"=0D +=0D +EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid001 =3D EFI_TE= ST_TCGMORTESTFUNCTION_ASSERTION_001_GUID;=0D +=0D +EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid002 =3D EFI_TE= ST_TCGMORTESTFUNCTION_ASSERTION_002_GUID;=0D +=0D +EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid003 =3D EFI_TE= ST_TCGMORTESTFUNCTION_ASSERTION_003_GUID;=0D +=0D +EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid004 =3D EFI_TE= ST_TCGMORTESTFUNCTION_ASSERTION_004_GUID;=0D diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOve= rwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestFunction.c b/uefi= -sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/Bla= ckBoxTest/TCGMemoryOverwriteRequestBBTestFunction.c new file mode 100644 index 000000000000..2f11926f123f --- /dev/null +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteR= equest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestFunction.c @@ -0,0 +1,410 @@ +/** @file=0D +=0D + Copyright 2006 - 2016 Unified EFI, Inc.
=0D + Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.
=0D + Copyright (c) 2023, Arm Inc. All rights reserved.
=0D +=0D + This program and the accompanying materials=0D + are licensed and made available under the terms and conditions of the BS= D License=0D + which accompanies this distribution. The full text of the license may b= e found at=0D + http://opensource.org/licenses/bsd-license.php=0D +=0D + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,=0D + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED.=0D +=0D +**/=0D +/*++=0D +=0D +Module Name:=0D +=0D + TCGMemoryOverwriteRequestBBTestFunction.c=0D +=0D +Abstract:=0D +=0D + Function Test Cases for the TCG MOR and MORLOCK EFI variables that are d= efined=0D + in TCG Platform Reset Attack Mitigation v1.10 Section 4 (UEFI Interface)= =0D +=0D +--*/=0D +=0D +#include "SctLib.h"=0D +#include "TCGMemoryOverwriteRequestBBTestMain.h"=0D +=0D +#define RECOVER_BUFFER_SIZE 2048=0D +=0D +#define TCG_MOR_VARIABLE_ATTRIBUTES (EFI_VARIABLE_NON_VOLATILE | EFI_VARI= ABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS)=0D +=0D +#define CONTROL_PLATFORM_RESET_TEST 1=0D +=0D +#define CONTROL_SET_VARIABLE_TEST 2=0D +=0D +=0D +/**=0D + * Entry point for TCG Platform Reset Attack Mitigation MemoryOverwrite E= FI Variables Function Test.=0D + * @param This A pointer to the EFI_BB_TEST_PROTOCOL instance= .=0D + * @param ClientInterface A pointer to the interface to be tested.=0D + * @param TestLevel Test "thoroughness" control.=0D + * @param SupportHandle A handle containing support protocols.=0D + * @return EFI_SUCCESS Test cases ran Successfully, may still contain= errors in assertions.=0D + * @return Other value Something failed.=0D + */=0D +EFI_STATUS=0D +BBTestTCGMemoryOverwriteRequestFunctionTest (=0D + IN EFI_BB_TEST_PROTOCOL *This,=0D + IN VOID *ClientInterface,=0D + IN EFI_TEST_LEVEL TestLevel,=0D + IN EFI_HANDLE SupportHandle=0D + )=0D +{=0D + EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib;=0D + EFI_TEST_RECOVERY_LIBRARY_PROTOCOL *RecoveryLib;=0D + EFI_STATUS Status;=0D + RESET_DATA *ResetData;=0D + UINT8 Buffer[RECOVER_BUFFER_SIZE];=0D + UINTN Size;=0D +=0D + ResetData =3D (RESET_DATA *)Buffer;=0D +=0D + //=0D + // Get the Standard Library Interface=0D + //=0D + Status =3D gtBS->HandleProtocol (=0D + SupportHandle,=0D + &gEfiStandardTestLibraryGuid,=0D + (VOID **) &StandardLib=0D + );=0D + if (EFI_ERROR(Status)) {=0D + return Status;=0D + }=0D +=0D + //=0D + // Get the Recovery Library Interface=0D + //=0D + Status =3D gtBS->HandleProtocol (=0D + SupportHandle,=0D + &gEfiTestRecoveryLibraryGuid,=0D + (VOID **) &RecoveryLib=0D + );=0D + if (EFI_ERROR(Status)) {=0D + StandardLib->RecordAssertion (=0D + StandardLib,=0D + EFI_TEST_ASSERTION_FAILED,=0D + gTestGenericFailureGuid,=0D + L"BS.HandleProtocol - Handle recovery library",=0D + L"%a:%d:Status - %r",=0D + __FILE__,=0D + (UINTN)__LINE__,=0D + Status=0D + );=0D + return Status;=0D + }=0D +=0D + //=0D + // Read reset record=0D + //=0D + Status =3D RecoveryLib->ReadResetRecord (=0D + RecoveryLib,=0D + &Size,=0D + Buffer=0D + );=0D +=0D + //=0D + // Check Reset Record's checkpoint for which test to run, all tests must= run so they are all included in the same function=0D + //=0D + if (EFI_ERROR(Status) || (Size < sizeof(RESET_DATA)) || (ResetData->Chec= kpointStep =3D=3D CONTROL_PLATFORM_RESET_TEST)) {=0D + if (EFI_ERROR(Status) || Size < sizeof(RESET_DATA)) { // if ResetRecor= d has not been written to yet, or EFI_ERROR, start the test from beginning= =0D + ResetData->Step =3D 0;=0D + }=0D + //=0D + // Test Checkpoint CONTROL_PLATFORM_RESET_TEST=0D + //=0D + Status =3D TCGMemoryOverwriteRequestPlatformResetCheck (StandardLib, R= ecoveryLib, ResetData);=0D + //=0D + // Status is returned in the event that the MOR/MORLOCK variables do n= ot exist in occordance to spec,=0D + // or the WriteResetRecord returns EFI_ERROR, test ends prematurely=0D + //=0D + if(EFI_ERROR(Status)) {=0D + return Status;=0D + }=0D + }=0D + //=0D + // After all Checkpoints have run=0D + //=0D + return EFI_SUCCESS;=0D +}=0D +=0D +=0D +/**=0D + * Check MOR & MORLOCK EFI variables are correctly created by platform=0D + * Initially setting MOR bit 0 is then cleared upon platform reset=0D + * @param StandardLib A pointer to EFI_STANDARD_TEST_LIBRARY_PROTOCOL= =0D + * instance.=0D + * @param RecoveryLib A pointer to EFI_TEST_RECOVERY_LIBRARY_PROTOCOL= =0D + * instance.=0D + * @return EFI_SUCCESS Successfully.=0D + * @return Other value Something failed.=0D + */=0D +EFI_STATUS=0D +TCGMemoryOverwriteRequestPlatformResetCheck (=0D + IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib,=0D + IN EFI_TEST_RECOVERY_LIBRARY_PROTOCOL *RecoveryLib,=0D + IN RESET_DATA *ResetData=0D + )=0D +{=0D + EFI_STATUS Status;=0D + EFI_TEST_ASSERTION Result;=0D + UINTN DataSize;=0D + UINT8 MemoryOverwriteRequestControlData;= =0D + UINT8 MemoryOverwriteRequestControlLockDa= ta;=0D + UINT32 Attributes;=0D +=0D + //=0D + // Check Step to see which part of test remains to be executed=0D + //=0D + if (ResetData->Step =3D=3D 0) {=0D + goto INITIAL_RESET;=0D + } else if (ResetData->Step =3D=3D 1) {=0D + goto MOR_VARIABLE_CHECK;=0D + } else if (ResetData->Step =3D=3D 2) {=0D + goto MOR_BIT_CLEAR_ON_RESET;=0D + }=0D +=0D +INITIAL_RESET:=0D + //=0D + // Perform initial plaform reset=0D + //=0D + ResetData->Step =3D 1;=0D + ResetData->CheckpointStep =3D CONTROL_PLATFORM_RESET_TEST;=0D +=0D + Status =3D RecoveryLib->WriteResetRecord (=0D + RecoveryLib,=0D + sizeof (RESET_DATA),=0D + (UINT8*)ResetData=0D + );=0D + if (EFI_ERROR(Status)) {=0D + StandardLib->RecordAssertion (=0D + StandardLib,=0D + EFI_TEST_ASSERTION_FAILED,=0D + gTestGenericFailureGuid,=0D + L"TestRecoveryLib - WriteResetRecord",=0D + L"%a:%d:Status - %r",=0D + __FILE__,=0D + (UINTN)__LINE__,=0D + Status=0D + );=0D + return Status;=0D + }=0D + SctPrint (L"System will cold reset after 1 second...");=0D + gtBS->Stall (1000000);=0D + gtRT->ResetSystem (=0D + EfiResetCold,=0D + EFI_SUCCESS,=0D + 0,=0D + NULL=0D + );=0D +=0D +MOR_VARIABLE_CHECK:=0D + //=0D + // Post system reset, Check if the MOR variable is correctly created by = platform=0D + //=0D +=0D + // Write reset record before the second reset (MOR_BIT_CLEAR_ON_RESET)=0D + ResetData->Step =3D 2;=0D + ResetData->CheckpointStep =3D CONTROL_PLATFORM_RESET_TEST;=0D +=0D + Status =3D RecoveryLib->WriteResetRecord (=0D + RecoveryLib,=0D + sizeof (RESET_DATA),=0D + (UINT8*)ResetData=0D + );=0D + if (EFI_ERROR(Status)) {=0D + StandardLib->RecordAssertion (=0D + StandardLib,=0D + EFI_TEST_ASSERTION_FAILED,=0D + gTestGenericFailureGuid,=0D + L"TestRecoveryLib - WriteResetRecord",=0D + L"%a:%d:Status - %r",=0D + __FILE__,=0D + (UINTN)__LINE__,=0D + Status=0D + );=0D + return Status;=0D + }=0D +=0D + //=0D + // GetVariable and check if the DataSize and Attributes are as expected= =0D + //=0D + DataSize =3D sizeof(MemoryOverwriteRequestControlData);=0D + Attributes =3D TCG_MOR_VARIABLE_ATTRIBUTES;=0D +=0D + Status =3D gtRT->GetVariable (=0D + L"MemoryOverwriteRequestControl", // VariableName=0D + &gEfiMemoryOverwriteControlDataGuid, // VendorGuid=0D + &Attributes, // Attributes=0D + &DataSize, // DataSize=0D + &MemoryOverwriteRequestControlData // Data=0D + );=0D + if (EFI_ERROR (Status) || (DataSize !=3D 1) || (Attributes !=3D TCG_MOR_= VARIABLE_ATTRIBUTES)) {=0D + Result =3D EFI_TEST_ASSERTION_FAILED;=0D + } else {=0D + Result =3D EFI_TEST_ASSERTION_PASSED;=0D + }=0D +=0D + StandardLib->RecordAssertion (=0D + StandardLib,=0D + Result,=0D + gTCGMemoryOverwriteRequestTestFunctionAssertionGuid001,= =0D + L"MemoryOverwriteRequestControl - Validate that the MOR = Variable is created by the platform in accordance with TCG Spec",=0D + L"%a:%d:Status - %r, DataSize - %d, Attributes - %x",=0D + __FILE__,=0D + (UINTN)__LINE__,=0D + Status,=0D + (UINTN)DataSize,=0D + Attributes=0D + );=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + //=0D + // Set MemoryOverwriteRequestControlData bit 0 and verify the platform c= lears bit 0 upon system reset=0D + // MOR bit 0 indicates to platform firmware that system memory must be w= iped during platform initialization=0D + //=0D + DataSize =3D sizeof(MemoryOverwriteRequestControlData);=0D + Attributes =3D TCG_MOR_VARIABLE_ATTRIBUTES;=0D + MemoryOverwriteRequestControlData |=3D MOR_BIT_HIGH << MOR_CLEAR_MEMORY_= BIT_OFFSET;=0D +=0D + Status =3D gtRT->SetVariable (=0D + L"MemoryOverwriteRequestControl", // VariableName=0D + &gEfiMemoryOverwriteControlDataGuid, // VendorGuid=0D + Attributes, // Attributes=0D + DataSize, // DataSize=0D + &MemoryOverwriteRequestControlData // Data=0D + );=0D + if (Status =3D=3D EFI_SUCCESS) {=0D + Result =3D EFI_TEST_ASSERTION_PASSED;=0D + }else {=0D + Result =3D EFI_TEST_ASSERTION_FAILED;=0D + }=0D +=0D + StandardLib->RecordAssertion (=0D + StandardLib,=0D + Result,=0D + gTCGMemoryOverwriteRequestTestFunctionAssertionGuid002,= =0D + L"MemoryOverwriteRequestControl - SetVariable() with MOR= bit 0 set high returns EFI_SUCCESS",=0D + L"%a:%d:Status - %r",=0D + __FILE__,=0D + (UINTN)__LINE__,=0D + Status=0D + );=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + // Cold reset system again for step 2=0D + SctPrint (L"System will cold reset after 1 second and test will be resum= ed after reboot.");=0D + gtBS->Stall (1000000);=0D + gtRT->ResetSystem (=0D + EfiResetCold,=0D + EFI_SUCCESS,=0D + 0,=0D + NULL=0D + );=0D +=0D +MOR_BIT_CLEAR_ON_RESET:=0D + //=0D + // Clear Step count and increment checkpoint for next test=0D + //=0D +=0D + ResetData->Step =3D 0;=0D + ResetData->CheckpointStep =3D CONTROL_SET_VARIABLE_TEST;=0D +=0D + Status =3D RecoveryLib->WriteResetRecord (=0D + RecoveryLib,=0D + sizeof (RESET_DATA),=0D + (UINT8*)ResetData=0D + );=0D + if (EFI_ERROR(Status)) {=0D + StandardLib->RecordAssertion (=0D + StandardLib,=0D + EFI_TEST_ASSERTION_FAILED,=0D + gTestGenericFailureGuid,=0D + L"TestRecoveryLib - WriteResetRecord",=0D + L"%a:%d:Status - %r",=0D + __FILE__,=0D + (UINTN)__LINE__,=0D + Status=0D + );=0D + return Status;=0D + }=0D +=0D + //=0D + // Check if the platform has cleared the set MOR bit 0 on reset=0D + //=0D + DataSize =3D sizeof(MemoryOverwriteRequestControlData);=0D + Attributes =3D TCG_MOR_VARIABLE_ATTRIBUTES;=0D +=0D + Status =3D gtRT->GetVariable (=0D + L"MemoryOverwriteRequestControl", // VariableName=0D + &gEfiMemoryOverwriteControlDataGuid, // VendorGuid=0D + &Attributes, // Attributes=0D + &DataSize, // DataSize=0D + &MemoryOverwriteRequestControlData // Data=0D + );=0D + if (EFI_ERROR (Status) || (MOR_CLEAR_MEMORY_VALUE (MemoryOverwriteReques= tControlData) !=3D MOR_BIT_LOW)) {=0D + Result =3D EFI_TEST_ASSERTION_FAILED;=0D + } else {=0D + Result =3D EFI_TEST_ASSERTION_PASSED;=0D + }=0D +=0D + StandardLib->RecordAssertion (=0D + StandardLib,=0D + Result,=0D + gTCGMemoryOverwriteRequestTestFunctionAssertionGuid003,= =0D + L"MemoryOverwriteRequestControl - Validate that MOR bit = 0 is cleared after a cold reset when the bit 0 is initially set",=0D + L"%a:%d:Status - %r",=0D + __FILE__,=0D + (UINTN)__LINE__,=0D + Status=0D + );=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + //=0D + // Verify MemoryOverwriteRequestControlLock is created as defined in the= TCG Platform Reset Attack Mitigation spec=0D + //=0D + DataSize =3D sizeof(MemoryOverwriteRequestControlLockData);=0D + Attributes =3D TCG_MOR_VARIABLE_ATTRIBUTES;=0D +=0D + Status =3D gtRT->GetVariable (=0D + L"MemoryOverwriteRequestControlLock", // Variable= Name=0D + &gEfiMemoryOverwriteRequestControlLockGuid, // VendorGu= id=0D + &Attributes, // Attribut= es=0D + &DataSize, // DataSize= =0D + &MemoryOverwriteRequestControlLockData // Data=0D + );=0D + if (EFI_ERROR (Status) || (MemoryOverwriteRequestControlLockData !=3D MO= R_LOCK_DATA_UNLOCKED) ||=0D + (DataSize !=3D 1) || (Attributes !=3D TCG_MOR_VARIABLE_ATTRIBUTES)) = {=0D + Result =3D EFI_TEST_ASSERTION_FAILED;=0D + } else {=0D + Result =3D EFI_TEST_ASSERTION_PASSED;=0D + }=0D +=0D + StandardLib->RecordAssertion (=0D + StandardLib,=0D + Result,=0D + gTCGMemoryOverwriteRequestTestFunctionAssertionGuid004,= =0D + L"MemoryOverwriteRequestControlLock - Validate that MORL= OCK is created by the platform in accordance with the TCG Spec",=0D + L"%a:%d:Status - %r, DataSize - %d, Attributes - %x",=0D + __FILE__,=0D + (UINTN)__LINE__,=0D + Status,=0D + (UINTN)DataSize,=0D + Attributes=0D + );=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + return EFI_SUCCESS;=0D +}=0D diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOve= rwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestMain.c b/uefi-sct= /SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBo= xTest/TCGMemoryOverwriteRequestBBTestMain.c new file mode 100644 index 000000000000..db01df9db5e2 --- /dev/null +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteR= equest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestMain.c @@ -0,0 +1,115 @@ +/** @file=0D +=0D + Copyright 2006 - 2016 Unified EFI, Inc.
=0D + Copyright (c) 2023, Arm Inc. All rights reserved.
=0D +=0D + This program and the accompanying materials=0D + are licensed and made available under the terms and conditions of the BS= D License=0D + which accompanies this distribution. The full text of the license may b= e found at=0D + http://opensource.org/licenses/bsd-license.php=0D +=0D + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,=0D + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED.=0D +=0D +**/=0D +/*++=0D +=0D +Module Name:=0D +=0D + TCG2MORTestMain.c=0D +=0D +Abstract:=0D +=0D + for EFI Driver TCG MemoryOverwriteRequest Test=0D +=0D +--*/=0D +#include "SctLib.h"=0D +#include "TCGMemoryOverwriteRequestBBTestMain.h"=0D +=0D +EFI_GUID gEfiMemoryOverwriteControlDataGuid =3D MEMORY_ONLY_RESET_CONTROL_= GUID;=0D +=0D +EFI_GUID gEfiMemoryOverwriteRequestControlLockGuid =3D MEMORY_OVERWRITE_RE= QUEST_CONTROL_LOCK_GUID;=0D +=0D +EFI_BB_TEST_PROTOCOL_FIELD gEfiTCGMemoryOverwriteRequestTestProtocolField = =3D {=0D + TCG_MOR_TEST_REVISION,=0D + EFI_TCG_MOR_TEST_GUID,=0D + L"TCG MemoryOverwriteRequest Test",=0D + L"TCG MemoryOverwriteRequest Functionality Test"=0D +};=0D +=0D +EFI_GUID gSupportProtocolGuid1[2] =3D {=0D + EFI_STANDARD_TEST_LIBRARY_GUID,=0D + EFI_NULL_GUID=0D +};=0D +=0D +EFI_BB_TEST_ENTRY_FIELD gLoadTCGMemoryOverwriteRequestEntryField[] =3D {=0D +=0D + {=0D + EFI_TCG_MOR_TEST_ENTRY_GUID0101,=0D + L"Test MOR and MORLOCK",=0D + L"Test for MOR and MORLOCK EFI variables in accordance with TCG spec",= =0D + EFI_TEST_LEVEL_DEFAULT,=0D + gSupportProtocolGuid1,=0D + EFI_TEST_CASE_AUTO,=0D + BBTestTCGMemoryOverwriteRequestFunctionTest=0D + },=0D +=0D + EFI_NULL_GUID=0D +};=0D +=0D +EFI_BB_TEST_PROTOCOL *gTCGMemoryOverwriteRequestTestProt;=0D +=0D +=0D +EFI_STATUS=0D +EFIAPI=0D +UnloadTCGMemoryOverwriteRequestTest (=0D + IN EFI_HANDLE ImageHandle=0D + );=0D +=0D +/**=0D + * Creates/installs the BlackBox Interface and eminating Entry Point node= list.=0D + * @param ImageHandle The test driver image handle=0D + * @param SystemTable Pointer to System Table=0D + * @return EFI_SUCCESS Indicates the interface was installed=0D + * @return EFI_OUT_OF_RESOURCES Indicates space for the new handle could = not be allocated=0D + * @return EFI_INVALID_PARAMETER: One of the parameters has an invalid va= lue.=0D + */=0D +EFI_STATUS=0D +EFIAPI=0D +InitializeTestTCGMemoryOverwriteRequest (=0D + IN EFI_HANDLE ImageHandle,=0D + IN EFI_SYSTEM_TABLE *SystemTable=0D + )=0D +{=0D + //=0D + // initialize test utility lib=0D + //=0D + EfiInitializeTestLib (ImageHandle, SystemTable);=0D + SctInitializeLib (ImageHandle, SystemTable);=0D +=0D + return EfiInitAndInstallBBTestInterface (=0D + &ImageHandle,=0D + &gEfiTCGMemoryOverwriteRequestTestProtocolField,=0D + gLoadTCGMemoryOverwriteRequestEntryField,=0D + UnloadTCGMemoryOverwriteRequestTest,=0D + &gTCGMemoryOverwriteRequestTestProt=0D + );=0D +}=0D +=0D +=0D +/**=0D + * Unloads the BlackBox Interface and the Entry Point list.=0D + * @param ImageHandle The image handle.=0D + * @return EFI_SUCCESS The interface was uninstalled successfully.=0D + */=0D +EFI_STATUS=0D +EFIAPI=0D +UnloadTCGMemoryOverwriteRequestTest (=0D + IN EFI_HANDLE ImageHandle=0D + )=0D +{=0D + return EfiUninstallAndFreeBBTestInterface (=0D + ImageHandle,=0D + gTCGMemoryOverwriteRequestTestProt=0D + );=0D +}=0D diff --git a/uefi-sct/SctPkg/CommonGenFramework.sh b/uefi-sct/SctPkg/Common= GenFramework.sh index fb9043b56bca..886e7eb7596b 100755 --- a/uefi-sct/SctPkg/CommonGenFramework.sh +++ b/uefi-sct/SctPkg/CommonGenFramework.sh @@ -226,6 +226,7 @@ then if [ -e $ProcessorType/RiscVBootProtocolBBTest.efi ]; then cp $ProcessorType/RiscVBootProtocolBBTest.efi $Framewor= k/Test/ > NUL fi + cp $ProcessorType/TCGMemoryOverwriteRequestBBTest.efi $Framework/= Test/ > NUL =20 # ********************************************* # Copy ENTS binary diff --git a/uefi-sct/SctPkg/Config/Data/Category.ini b/uefi-sct/SctPkg/Con= fig/Data/Category.ini index b34d35db9ac8..bf02ccea9218 100644 --- a/uefi-sct/SctPkg/Config/Data/Category.ini +++ b/uefi-sct/SctPkg/Config/Data/Category.ini @@ -165,6 +165,13 @@ InterfaceGuid =3D AFF115FB-387B-4C18-8C41-6AFC7F03BB90 Name =3D RuntimeServicesTest\MiscRuntimeServicesTest=0D Description =3D=0D =0D +[Category Data]=0D +Revision =3D 0x00010000=0D +CategoryGuid =3D 265E661D-D51E-454B-BBC9-665F46EC0A04=0D +InterfaceGuid =3D AFF115FB-387B-4C18-8C41-6AFC7F03BB90=0D +Name =3D RuntimeServicesTest\TCGMemoryOverwriteRequestTest=0D +Description =3D Test TCG Platform Reset Attack Mitigation EFI variables= =0D +=0D [Category Data]=0D Revision =3D 0x00010000=0D CategoryGuid =3D 5B1B31A1-9562-11D2-8E3F-00A0C969723B=0D --=20 2.34.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#115479): https://edk2.groups.io/g/devel/message/115479 Mute This Topic: https://groups.io/mt/104367128/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-