From nobody Tue Feb 10 02:55:22 2026 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+107966+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+107966+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1692756593; cv=none; d=zohomail.com; s=zohoarc; b=UBMubJtfRhrnd4LWKltVjj6NqnLdRIHf0AEjcZ58X00WUsKT4eK7tknxOYCRbhmb0QKy8vfT0yzqM94BrH7kUUteqmmMZConPv2dmeg2rx5kVfMMV3Y7kS1isHwwBCPaPUdbmkiy4vBvJ+yBdRp1xqpChXd9b79pQELl6ZqmLXY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692756593; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=1f2R9/SyZB9blP6wOebMaCsMzcmMiirMOt06Aut+HCA=; b=CbGqppKLlpQRu9urybpssPncvRlSbGmbNfqiWwdUs3TqQbk4S99TjmxcDs+pqw8RbPczwJhiq6cWZ6urOgpjr+eNwWndZOh93+NtS0Q25J7jxF7UTEW3mOxkOj829r/R782iua+MBeQvVxfGr5hH2YjQJyt/+6ccz+4rvZ8W244= 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+107966+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 1692756593313598.7214453428955; Tue, 22 Aug 2023 19:09:53 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=rByzasDbhKpm/Qw4g2OEoukiVlx1ooBQjbK91dOlF/8=; c=relaxed/simple; d=groups.io; h=From:To: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=1692756592; v=1; b=jn6GxUjFCBUn1saqwgst1Fo7wECNqxI+cGBLrKxhwcE8MQKOc92Lwvd0NJ8NHoQgmD6Sof4v BwRdhfwdcPgDzhJ/XuP/v6nopwRHA/Fh2c2nMNW/Ofq+I4FhCa3wpnMfsxffop4VYCpv6fxDLGx 1KCvFaqsVpToS+1z2tBlaY3k= X-Received: by 127.0.0.2 with SMTP id 08drYY1788612xyyA6NEdbzX; Tue, 22 Aug 2023 19:09:52 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.2910.1692756591461388732 for ; Tue, 22 Aug 2023 19:09:51 -0700 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 53C3511FB for ; Tue, 22 Aug 2023 19:10:31 -0700 (PDT) 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 8BFFC3F7C5 for ; Tue, 22 Aug 2023 19:09:50 -0700 (PDT) From: "Abhimanyu Singh" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v2 1/6] uefi-sct/SctPkg: TCG Platform Reset Check Test Date: Tue, 22 Aug 2023 21:09:42 -0500 Message-Id: <20230823020947.124395-2-Abhi.Singh@arm.com> In-Reply-To: <20230823020947.124395-1-Abhi.Singh@arm.com> References: <20230823020947.124395-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: TzTAHMUgApPeaSyepDUZoFmpx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1692756594139100004 Content-Type: text/plain; charset="utf-8" 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 Change-Id: I774d5893e5aff47690dadf90c36c7b9e7e7ee584 --- 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 SctPkg/TestCase/UEFI/EFI/RuntimeServices/TimeServices/BlackBoxTest/TimeSer= vicesBBTest.inf SctPkg/TestCase/UEFI/EFI/RuntimeServices/VariableServices/BlackBoxTest/Var= iableServicesBBTest.inf +SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBo= xTest/TCGMemoryOverwriteRequestBBTest.inf =20 SctPkg/TestCase/UEFI/EFI/Protocol/GraphicsOutput/BlackBoxTest/GraphicsOutp= utBBTest.inf SctPkg/TestCase/UEFI/EFI/Protocol/Bis/BlackBoxTest/BisBBTest.inf 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 +# +# Copyright 2006 - 2015 Unified EFI, Inc.
+# Copyright (c) 2013, Intel Corporation. All rights reserved.
+# Copyright (c) 2023, Arm Inc. All rights reserved.
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the B= SD License +# which accompanies this distribution. The full text of the license may = be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IM= PLIED. +# +## +#/*++ +# +# Module Name: +# +# TCGMemoryOverwriteRequestBBTest.inf +# +# Abstract: +# +# Component description file for TCG MemoryOverwriteRequest UEFI variabl= es Test. +# +#--*/ + +[defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D TCGMemoryOverwriteRequestBBTest + FILE_GUID =3D ACA989CD-4AEE-45A3-B80F-E9A523BB7164 + MODULE_TYPE =3D UEFI_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D InitializeTestTCGMemoryOverwriteRequest + +[sources.common] + TCGMemoryOverwriteRequestBBTestMain.c + TCGMemoryOverwriteRequestBBTestMain.h + TCGMemoryOverwriteRequestBBTestFunction.c + Guid.c + +[Packages] + MdePkg/MdePkg.dec + SctPkg/SctPkg.dec + SctPkg/UEFI/UEFI.dec + +[LibraryClasses] + UefiDriverEntryPoint + SctLib + EfiTestLib + +[Protocols] + gEfiTestRecoveryLibraryGuid 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 + + Copyright 2006 - 2016 Unified EFI, Inc.
+ Copyright (c) 2013, Intel Corporation. All rights reserved.
+ Copyright (c) 2023, Arm Inc. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ +/*++ + +Module Name: + + guid.h + +Abstract: + + GUIDs auto-generated for EFI test assertion. + +--*/ + +#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_001_GUID \ +{ 0xd1c31d5f, 0x944f, 0x434c, {0x88, 0x26, 0xa6, 0xfb, 0x00, 0xd4, 0xbb, 0= x97 }} + +#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_002_GUID \ +{ 0xa6c191b1, 0x9bfb, 0x4231, {0xb9, 0x2d, 0x4e, 0xa2, 0x21, 0xf6, 0x4b, 0= x5d }} + +#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_003_GUID \ +{ 0x34d41a18, 0x8ffe, 0x456b, {0xa4, 0x82, 0x97, 0xb9, 0x9c, 0x50, 0x7d, 0= x9e }} + +#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_004_GUID \ +{ 0x002519c6, 0x859f, 0x4d25, {0xb1, 0x36, 0xb2, 0xef, 0x61, 0xe5, 0xd9, 0= x6f }} + +extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid001; + +extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid002; + +extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid003; + +extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid004; 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 + + Copyright 2006 - 2017 Unified EFI, Inc.
+ Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.
+ Copyright (c) 2023, Arm Inc. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ +/*++ + +Module Name: + + TCGMemoryOverwriteRequestTest.h + +Abstract: + + Test Driver of TCG MOR and MORLOCK EFI variables that are defined inside + TCG Platform Reset Attack Mitigation v1.10 Section 4 (UEFI Interface) + +--*/ + +#ifndef _TCG_MOR_BB_TEST_MAIN +#define _TCG_MOR_BB_TEST_MAIN + +#include "Efi.h" +#include "Guid.h" +#include +#include +#include +#include + +typedef struct _RESET_DATA { + UINTN Step; + UINTN CheckpointStep; +} RESET_DATA; + +#include EFI_TEST_PROTOCOL_DEFINITION(TestRecoveryLibrary) + +#define TCG_MOR_TEST_REVISION 0x00010000 + +#define MOR_BIT_LOW 0x0 +#define MOR_BIT_HIGH 0x1 + +#define MOR_LOCK_DATA_UNLOCKED 0x0 + + +// +// TEST GUID for TCG Platform Reset Attack Mitigation MemoryOverwriteReque= st (MOR) Test +// +#define EFI_TCG_MOR_TEST_GUID \ + { 0x265e661d, 0xd51e, 0x454b, {0xbb, 0xc9, 0x66, 0x5f, 0x46, 0xec, 0x0a,= 0x04 }} + +EFI_STATUS +EFIAPI +InitializeTestTCGMemoryOverwriteRequest ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ); + +EFI_STATUS +EFIAPI +UnloadTCGMemoryOverwriteRequestTest ( + IN EFI_HANDLE ImageHandle + ); + +EFI_STATUS +BBTestTCGMemoryOverwriteRequestFunctionTest ( + IN EFI_BB_TEST_PROTOCOL *This, + IN VOID *ClientInterface, + IN EFI_TEST_LEVEL TestLevel, + IN EFI_HANDLE SupportHandle + ); + +EFI_STATUS +TCGMemoryOverwriteRequestPlatformResetCheck ( + IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib, + IN EFI_TEST_RECOVERY_LIBRARY_PROTOCOL *RecoveryLib, + IN RESET_DATA *ResetData + ); + +// ***********************************************************************= ***** +// Entry GUIDs for Test +// ***********************************************************************= ***** + +#define EFI_TCG_MOR_TEST_ENTRY_GUID0101 \ + { 0x2104436a, 0x77c8, 0x4514, {0xb7, 0xd7, 0xaa, 0x8a, 0x6b, 0xd1, 0x8d,= 0xa4 }} + +#endif 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 + + Copyright 2006 - 2013 Unified EFI, Inc.
+ Copyright (c) 2013, Intel Corporation. All rights reserved.
+ Copyright (c) 2023, Arm Inc. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ +/*++ + +Module Name: + + guid.c + +Abstract: + + GUIDs auto-generated for EFI test assertion. + +--*/ + +#include "Efi.h" +#include "Guid.h" + +EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid001 =3D EFI_TE= ST_TCGMORTESTFUNCTION_ASSERTION_001_GUID; + +EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid002 =3D EFI_TE= ST_TCGMORTESTFUNCTION_ASSERTION_002_GUID; + +EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid003 =3D EFI_TE= ST_TCGMORTESTFUNCTION_ASSERTION_003_GUID; + +EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid004 =3D EFI_TE= ST_TCGMORTESTFUNCTION_ASSERTION_004_GUID; 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..82f9300dd296 --- /dev/null +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteR= equest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestFunction.c @@ -0,0 +1,410 @@ +/** @file + + Copyright 2006 - 2016 Unified EFI, Inc.
+ Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2023, Arm Inc. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ +/*++ + +Module Name: + + TCGMemoryOverwriteRequestBBTestFunction.c + +Abstract: + + Function Test Cases for the TCG MOR and MORLOCK EFI variables that are d= efined + in TCG Platform Reset Attack Mitigation v1.10 Section 4 (UEFI Interface) + +--*/ + +#include "SctLib.h" +#include "TCGMemoryOverwriteRequestBBTestMain.h" + +#define RECOVER_BUFFER_SIZE 2048 + +#define TCG_MOR_VARIABLE_ATTRIBUTES (EFI_VARIABLE_NON_VOLATILE | EFI_VARI= ABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS) + +#define CONTROL_PLATFORM_RESET_TEST 1 + +#define CONTROL_SET_VARIABLE_TEST 2 + + +/** + * Entry point for TCG Platform Reset Attack Mitigation MemoryOverwrite E= FI Variables Function Test. + * @param This A pointer to the EFI_BB_TEST_PROTOCOL instance. + * @param ClientInterface A pointer to the interface to be tested. + * @param TestLevel Test "thoroughness" control. + * @param SupportHandle A handle containing support protocols. + * @return EFI_SUCCESS Test cases ran Successfully, may still contain= errors in assertions. + * @return Other value Something failed. + */ +EFI_STATUS +BBTestTCGMemoryOverwriteRequestFunctionTest ( + IN EFI_BB_TEST_PROTOCOL *This, + IN VOID *ClientInterface, + IN EFI_TEST_LEVEL TestLevel, + IN EFI_HANDLE SupportHandle + ) +{ + EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib; + EFI_TEST_RECOVERY_LIBRARY_PROTOCOL *RecoveryLib; + EFI_STATUS Status; + RESET_DATA *ResetData; + UINT8 Buffer[RECOVER_BUFFER_SIZE]; + UINTN Size; + + ResetData =3D (RESET_DATA *)Buffer; + + // + // Get the Standard Library Interface + // + Status =3D gtBS->HandleProtocol ( + SupportHandle, + &gEfiStandardTestLibraryGuid, + (VOID **) &StandardLib + ); + if (EFI_ERROR(Status)) { + return Status; + } + + // + // Get the Recovery Library Interface + // + Status =3D gtBS->HandleProtocol ( + SupportHandle, + &gEfiTestRecoveryLibraryGuid, + (VOID **) &RecoveryLib + ); + if (EFI_ERROR(Status)) { + StandardLib->RecordAssertion ( + StandardLib, + EFI_TEST_ASSERTION_FAILED, + gTestGenericFailureGuid, + L"BS.HandleProtocol - Handle recovery library", + L"%a:%d:Status - %r", + __FILE__, + (UINTN)__LINE__, + Status + ); + return Status; + } + + // + // Read reset record + // + Status =3D RecoveryLib->ReadResetRecord ( + RecoveryLib, + &Size, + Buffer + ); + + // + // Check Reset Record's checkpoint for which test to run, all tests must= run so they are all included in the same function + // + if (EFI_ERROR(Status) || (Size < sizeof(RESET_DATA)) || (ResetData->Chec= kpointStep =3D=3D CONTROL_PLATFORM_RESET_TEST)) { + if (EFI_ERROR(Status) || Size < sizeof(RESET_DATA)) { // if true, Rese= tData has not been intialized by the tests yet, set Step =3D 0 to start the= first step of the tests + ResetData->Step =3D 0; + } + // + // Test Checkpoint CONTROL_PLATFORM_RESET_TEST + // + Status =3D TCGMemoryOverwriteRequestPlatformResetCheck (StandardLib, R= ecoveryLib, ResetData); + // + // Status is returned in the event that the MOR/MORLOCK variables do n= ot exist in occordance to spec, + // or the WriteResetRecord returns EFI_ERROR, test ends prematurely + // + if(EFI_ERROR(Status)) { + return Status; + } + } + // + // After all Checkpoints have run + // + return EFI_SUCCESS; +} + + +/** + * MOR & MORLock EFI variables are correctly created by platform + * Initially setting MOR bit 0 is then cleared upon platform reset + * @param StandardLib A pointer to EFI_STANDARD_TEST_LIBRARY_PROTOCOL + * instance. + * @param RecoveryLib A pointer to EFI_TEST_RECOVERY_LIBRARY_PROTOCOL + * instance. + * @return EFI_SUCCESS Successfully. + * @return Other value Something failed. + */ +EFI_STATUS +TCGMemoryOverwriteRequestPlatformResetCheck ( + IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib, + IN EFI_TEST_RECOVERY_LIBRARY_PROTOCOL *RecoveryLib, + IN RESET_DATA *ResetData + ) +{ + EFI_STATUS Status; + EFI_TEST_ASSERTION Result; + UINTN DataSize; + UINT8 MemoryOverwriteRequestControlData; + UINT8 MemoryOverwriteRequestControlLockDa= ta; + UINT32 Attributes; + + // + // Check Step to see which part of test remains to be executed + // + if (ResetData->Step =3D=3D 0) { + goto INITIAL_RESET; + } else if (ResetData->Step =3D=3D 1) { + goto MOR_VARIABLE_CHECK; + } else if (ResetData->Step =3D=3D 2) { + goto MOR_BIT_CLEAR_ON_RESET; + } + +INITIAL_RESET: + // + // Perform initial plaform reset + // + ResetData->Step =3D 1; + ResetData->CheckpointStep =3D CONTROL_PLATFORM_RESET_TEST; + + Status =3D RecoveryLib->WriteResetRecord ( + RecoveryLib, + sizeof (RESET_DATA), + (UINT8*)ResetData + ); + if (EFI_ERROR(Status)) { + StandardLib->RecordAssertion ( + StandardLib, + EFI_TEST_ASSERTION_FAILED, + gTestGenericFailureGuid, + L"TestRecoveryLib - WriteResetRecord", + L"%a:%d:Status - %r", + __FILE__, + (UINTN)__LINE__, + Status + ); + return Status; + } + SctPrint (L"System will cold reset after 1 second..."); + gtBS->Stall (1000000); + gtRT->ResetSystem ( + EfiResetCold, + EFI_SUCCESS, + 0, + NULL + ); + +MOR_VARIABLE_CHECK: + // + // Post system reset, Check if the MOR EFI var is correctly created by p= latform + // + + // Write reset record before the second reset (MOR_BIT_CLEAR_ON_RESET) + ResetData->Step =3D 2; + ResetData->CheckpointStep =3D CONTROL_PLATFORM_RESET_TEST; + + Status =3D RecoveryLib->WriteResetRecord ( + RecoveryLib, + sizeof (RESET_DATA), + (UINT8*)ResetData + ); + if (EFI_ERROR(Status)) { + StandardLib->RecordAssertion ( + StandardLib, + EFI_TEST_ASSERTION_FAILED, + gTestGenericFailureGuid, + L"TestRecoveryLib - WriteResetRecord", + L"%a:%d:Status - %r", + __FILE__, + (UINTN)__LINE__, + Status + ); + return Status; + } + + // + // GetVariable and check if the DataSize and Attributes are as expected + // + DataSize =3D sizeof(MemoryOverwriteRequestControlData); + Attributes =3D TCG_MOR_VARIABLE_ATTRIBUTES; + + Status =3D gtRT->GetVariable ( + L"MemoryOverwriteRequestControl", // VariableName + &gEfiMemoryOverwriteControlDataGuid, // VendorGuid + &Attributes, // Attributes + &DataSize, // DataSize + &MemoryOverwriteRequestControlData // Data + ); + if (EFI_ERROR (Status) || (DataSize !=3D 1) || (Attributes !=3D TCG_MOR_= VARIABLE_ATTRIBUTES)) { + Result =3D EFI_TEST_ASSERTION_FAILED; + } else { + Result =3D EFI_TEST_ASSERTION_PASSED; + } + + StandardLib->RecordAssertion ( + StandardLib, + Result, + gTCGMemoryOverwriteRequestTestFunctionAssertionGuid001, + L"MemoryOverwriteRequestControl - Validate that the MOR = Variable is created by the platform in accordance with TCG Spec", + L"%a:%d:Status - %r, DataSize - %d, Attributes - %x", + __FILE__, + (UINTN)__LINE__, + Status, + (UINTN)DataSize, + Attributes + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Set MemoryOverwriteRequestControlData bit 0 and verify the platform c= lears bit 0 upon system reset + // MOR bit 0 indicates to platform firmware that system memory must be w= iped during platform initialization + // + DataSize =3D sizeof(MemoryOverwriteRequestControlData); + Attributes =3D TCG_MOR_VARIABLE_ATTRIBUTES; + MemoryOverwriteRequestControlData |=3D MOR_BIT_HIGH << MOR_CLEAR_MEMORY_= BIT_OFFSET; + + Status =3D gtRT->SetVariable ( + L"MemoryOverwriteRequestControl", // VariableName + &gEfiMemoryOverwriteControlDataGuid, // VendorGuid + Attributes, // Attributes + DataSize, // DataSize + &MemoryOverwriteRequestControlData // Data + ); + if (Status =3D=3D EFI_SUCCESS) { + Result =3D EFI_TEST_ASSERTION_PASSED; + }else { + Result =3D EFI_TEST_ASSERTION_FAILED; + } + + StandardLib->RecordAssertion ( + StandardLib, + Result, + gTCGMemoryOverwriteRequestTestFunctionAssertionGuid002, + L"MemoryOverwriteRequestControl - SetVariable() with MOR= bit 0 set high returns EFI_SUCCESS", + L"%a:%d:Status - %r", + __FILE__, + (UINTN)__LINE__, + Status + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // Cold reset system again for step 2 + SctPrint (L"System will cold reset after 1 second and test will be resum= ed after reboot."); + gtBS->Stall (1000000); + gtRT->ResetSystem ( + EfiResetCold, + EFI_SUCCESS, + 0, + NULL + ); + +MOR_BIT_CLEAR_ON_RESET: + // + // Clear Step count and increment checkpoint for next test + // + + ResetData->Step =3D 0; + ResetData->CheckpointStep =3D CONTROL_SET_VARIABLE_TEST; + + Status =3D RecoveryLib->WriteResetRecord ( + RecoveryLib, + sizeof (RESET_DATA), + (UINT8*)ResetData + ); + if (EFI_ERROR(Status)) { + StandardLib->RecordAssertion ( + StandardLib, + EFI_TEST_ASSERTION_FAILED, + gTestGenericFailureGuid, + L"TestRecoveryLib - WriteResetRecord", + L"%a:%d:Status - %r", + __FILE__, + (UINTN)__LINE__, + Status + ); + return Status; + } + + // + // Check if the platform has cleared the set MOR bit 0 on reset + // + DataSize =3D sizeof(MemoryOverwriteRequestControlData); + Attributes =3D TCG_MOR_VARIABLE_ATTRIBUTES; + + Status =3D gtRT->GetVariable ( + L"MemoryOverwriteRequestControl", // VariableName + &gEfiMemoryOverwriteControlDataGuid, // VendorGuid + &Attributes, // Attributes + &DataSize, // DataSize + &MemoryOverwriteRequestControlData // Data + ); + if (EFI_ERROR (Status) || (MOR_CLEAR_MEMORY_VALUE (MemoryOverwriteReques= tControlData) !=3D MOR_BIT_LOW)) { + Result =3D EFI_TEST_ASSERTION_FAILED; + } else { + Result =3D EFI_TEST_ASSERTION_PASSED; + } + + StandardLib->RecordAssertion ( + StandardLib, + Result, + gTCGMemoryOverwriteRequestTestFunctionAssertionGuid003, + L"MemoryOverwriteRequestControl - Validate that MOR bit = 0 is cleared after a cold reset when the bit 0 is initially set", + L"%a:%d:Status - %r", + __FILE__, + (UINTN)__LINE__, + Status + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Verify MemoryOverwriteRequestControlLock is created as defined in TCG= spec + // + DataSize =3D sizeof(MemoryOverwriteRequestControlLockData); + Attributes =3D TCG_MOR_VARIABLE_ATTRIBUTES; + + Status =3D gtRT->GetVariable ( + L"MemoryOverwriteRequestControlLock", // Variable= Name + &gEfiMemoryOverwriteRequestControlLockGuid, // VendorGu= id + &Attributes, // Attribut= es + &DataSize, // DataSize + &MemoryOverwriteRequestControlLockData // Data + ); + if (EFI_ERROR (Status) || (MemoryOverwriteRequestControlLockData !=3D MO= R_LOCK_DATA_UNLOCKED) || + (DataSize !=3D 1) || (Attributes !=3D TCG_MOR_VARIABLE_ATTRIBUTES)) { + Result =3D EFI_TEST_ASSERTION_FAILED; + } else { + Result =3D EFI_TEST_ASSERTION_PASSED; + } + + StandardLib->RecordAssertion ( + StandardLib, + Result, + gTCGMemoryOverwriteRequestTestFunctionAssertionGuid004, + L"MemoryOverwriteRequestControlLock - Validate that MORL= OCK is created by the platform in accordance with TCG Spec", + L"%a:%d:Status - %r, DataSize - %d, Attributes - %x", + __FILE__, + (UINTN)__LINE__, + Status, + (UINTN)DataSize, + Attributes + ); + if (EFI_ERROR (Status)) { + return Status; + } + + return EFI_SUCCESS; +} 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 + + Copyright 2006 - 2016 Unified EFI, Inc.
+ Copyright (c) 2023, Arm Inc. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ +/*++ + +Module Name: + + TCG2MORTestMain.c + +Abstract: + + for EFI Driver TCG MemoryOverwriteRequest Test + +--*/ +#include "SctLib.h" +#include "TCGMemoryOverwriteRequestBBTestMain.h" + +EFI_GUID gEfiMemoryOverwriteControlDataGuid =3D MEMORY_ONLY_RESET_CONTROL_= GUID; + +EFI_GUID gEfiMemoryOverwriteRequestControlLockGuid =3D MEMORY_OVERWRITE_RE= QUEST_CONTROL_LOCK_GUID; + +EFI_BB_TEST_PROTOCOL_FIELD gEfiTCGMemoryOverwriteRequestTestProtocolField = =3D { + TCG_MOR_TEST_REVISION, + EFI_TCG_MOR_TEST_GUID, + L"TCG MemoryOverwriteRequest Test", + L"TCG MemoryOverwriteRequest Functionality Test" +}; + +EFI_GUID gSupportProtocolGuid1[2] =3D { + EFI_STANDARD_TEST_LIBRARY_GUID, + EFI_NULL_GUID +}; + +EFI_BB_TEST_ENTRY_FIELD gLoadTCGMemoryOverwriteRequestEntryField[] =3D { + + { + EFI_TCG_MOR_TEST_ENTRY_GUID0101, + L"Test MOR and MORLOCK", + L"Test for MOR and MORLOCK EFI variables in accordance with TCG spec", + EFI_TEST_LEVEL_DEFAULT, + gSupportProtocolGuid1, + EFI_TEST_CASE_AUTO, + BBTestTCGMemoryOverwriteRequestFunctionTest + }, + + EFI_NULL_GUID +}; + +EFI_BB_TEST_PROTOCOL *gTCGMemoryOverwriteRequestTestProt; + + +EFI_STATUS +EFIAPI +UnloadTCGMemoryOverwriteRequestTest ( + IN EFI_HANDLE ImageHandle + ); + +/** + * Creates/installs the BlackBox Interface and eminating Entry Point node= list. + * @param ImageHandle The test driver image handle + * @param SystemTable Pointer to System Table + * @return EFI_SUCCESS Indicates the interface was installed + * @return EFI_OUT_OF_RESOURCES Indicates space for the new handle could = not be allocated + * @return EFI_INVALID_PARAMETER: One of the parameters has an invalid va= lue. + */ +EFI_STATUS +EFIAPI +InitializeTestTCGMemoryOverwriteRequest ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + // + // initialize test utility lib + // + EfiInitializeTestLib (ImageHandle, SystemTable); + SctInitializeLib (ImageHandle, SystemTable); + + return EfiInitAndInstallBBTestInterface ( + &ImageHandle, + &gEfiTCGMemoryOverwriteRequestTestProtocolField, + gLoadTCGMemoryOverwriteRequestEntryField, + UnloadTCGMemoryOverwriteRequestTest, + &gTCGMemoryOverwriteRequestTestProt + ); +} + + +/** + * Unloads the BlackBox Interface and the Entry Point list. + * @param ImageHandle The image handle. + * @return EFI_SUCCESS The interface was uninstalled successfully. + */ +EFI_STATUS +EFIAPI +UnloadTCGMemoryOverwriteRequestTest ( + IN EFI_HANDLE ImageHandle + ) +{ + return EfiUninstallAndFreeBBTestInterface ( + ImageHandle, + gTCGMemoryOverwriteRequestTestProt + ); +} 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 Description =3D =20 +[Category Data] +Revision =3D 0x00010000 +CategoryGuid =3D 265E661D-D51E-454B-BBC9-665F46EC0A04 +InterfaceGuid =3D AFF115FB-387B-4C18-8C41-6AFC7F03BB90 +Name =3D RuntimeServicesTest\TCGMemoryOverwriteRequestTest +Description =3D Test TCG Platform Reset Attack Mitigation EFI variables + [Category Data] Revision =3D 0x00010000 CategoryGuid =3D 5B1B31A1-9562-11D2-8E3F-00A0C969723B --=20 2.34.1 -=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 (#107966): https://edk2.groups.io/g/devel/message/107966 Mute This Topic: https://groups.io/mt/100907774/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-