From: "Abhi.Singh" <abhi.si...@arm.com> SCT spec: https://bugzilla.tianocore.org/show_bug.cgi?id=4374
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4419 -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 <edhaya.chand...@arm.com> Cc: Barton Gao <gao...@byosoft.com.cn> Cc: Carolyn Gjertsen <carolyn.gjert...@amd.com> Signed-off-by: Abhi Singh <abhi.si...@arm.com> Reviewed-by: Stuart Yoder <stuart.yo...@arm.com> --- uefi-sct/SctPkg/UEFI/UEFI_SCT.dsc | 1 + uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTest.inf | 53 +++ uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/Guid.h | 46 ++ uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestMain.h | 95 +++++ uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/Guid.c | 37 ++ uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestFunction.c | 451 ++++++++++++++++++++ uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestMain.c | 115 +++++ uefi-sct/SctPkg/CommonGenFramework.sh | 1 + uefi-sct/SctPkg/Config/Data/Category.ini | 7 + 9 files changed, 806 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/TimeServicesBBTest.inf SctPkg/TestCase/UEFI/EFI/RuntimeServices/VariableServices/BlackBoxTest/VariableServicesBBTest.inf +SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTest.inf SctPkg/TestCase/UEFI/EFI/Protocol/GraphicsOutput/BlackBoxTest/GraphicsOutputBBTest.inf SctPkg/TestCase/UEFI/EFI/Protocol/Bis/BlackBoxTest/BisBBTest.inf diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTest.inf b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTest.inf new file mode 100644 index 000000000000..35d82043e2e7 --- /dev/null +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTest.inf @@ -0,0 +1,53 @@ +## @file +# +# Copyright 2006 - 2015 Unified EFI, Inc.<BR> +# Copyright (c) 2013, Intel Corporation. All rights reserved.<BR> +# Copyright (c) 2023, Arm Inc. All rights reserved.<BR> +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD 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 IMPLIED. +# +## +#/*++ +# +# Module Name: +# +# TCGMemoryOverwriteRequestBBTest.inf +# +# Abstract: +# +# Component description file for TCG MemoryOverwriteRequest UEFI variables Test. +# +#--*/ + +[defines] + INF_VERSION = 0x00010005 + BASE_NAME = TCGMemoryOverwriteRequestBBTest + FILE_GUID = ACA989CD-4AEE-45A3-B80F-E9A523BB7164 + MODULE_TYPE = UEFI_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = 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/TCGMemoryOverwriteRequest/BlackBoxTest/Guid.h b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/Guid.h new file mode 100644 index 000000000000..a3d87a3eb764 --- /dev/null +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/Guid.h @@ -0,0 +1,46 @@ +/** @file + + Copyright 2006 - 2016 Unified EFI, Inc.<BR> + Copyright (c) 2013, Intel Corporation. All rights reserved.<BR> + Copyright (c) 2023, Arm Inc. All rights reserved.<BR> + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD 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 IMPLIED. + +**/ +/*++ + +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, 0x97 }} + +#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_002_GUID \ +{ 0xa6c191b1, 0x9bfb, 0x4231, {0xb9, 0x2d, 0x4e, 0xa2, 0x21, 0xf6, 0x4b, 0x5d }} + +#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_003_GUID \ +{ 0x34d41a18, 0x8ffe, 0x456b, {0xa4, 0x82, 0x97, 0xb9, 0x9c, 0x50, 0x7d, 0x9e }} + +#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_004_GUID \ +{ 0x002519c6, 0x859f, 0x4d25, {0xb1, 0x36, 0xb2, 0xef, 0x61, 0xe5, 0xd9, 0x6f }} + +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/TCGMemoryOverwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestMain.h b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestMain.h new file mode 100644 index 000000000000..45bd921ecca4 --- /dev/null +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestMain.h @@ -0,0 +1,95 @@ +/** @file + + Copyright 2006 - 2017 Unified EFI, Inc.<BR> + Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR> + Copyright (c) 2023, Arm Inc. All rights reserved.<BR> + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD 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 IMPLIED. + +**/ +/*++ + +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 <Library/EfiTestLib.h> +#include <Guid/MemoryOverwriteControl.h> +#include <IndustryStandard/MemoryOverwriteRequestControlLock.h> +#include <SctLib.h> + +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 MemoryOverwriteRequest (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/TCGMemoryOverwriteRequest/BlackBoxTest/Guid.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/Guid.c new file mode 100644 index 000000000000..59c798a710f1 --- /dev/null +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/Guid.c @@ -0,0 +1,37 @@ +/** @file + + Copyright 2006 - 2013 Unified EFI, Inc.<BR> + Copyright (c) 2013, Intel Corporation. All rights reserved.<BR> + Copyright (c) 2023, Arm Inc. All rights reserved.<BR> + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD 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 IMPLIED. + +**/ +/*++ + +Module Name: + + guid.c + +Abstract: + + GUIDs auto-generated for EFI test assertion. + +--*/ + +#include "Efi.h" +#include "Guid.h" + +EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid001 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_001_GUID; + +EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid002 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_002_GUID; + +EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid003 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_003_GUID; + +EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid004 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_004_GUID; diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestFunction.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestFunction.c new file mode 100644 index 000000000000..8acad88b2365 --- /dev/null +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestFunction.c @@ -0,0 +1,451 @@ +/** @file + + Copyright 2006 - 2016 Unified EFI, Inc.<BR> + Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR> + Copyright (c) 2023, Arm Inc. All rights reserved.<BR> + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD 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 IMPLIED. + +**/ +/*++ + +Module Name: + + TCGMemoryOverwriteRequestBBTestFunction.c + +Abstract: + + Function Test Cases for the TCG MOR and MORLOCK EFI variables that are defined + 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_VARIABLE_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 EFI 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 = (RESET_DATA *)Buffer; + + BOOLEAN CheckpointStepMatched = FALSE; + + // + // Get the Standard Library Interface + // + Status = gtBS->OpenProtocol ( + SupportHandle, + &gEfiStandardTestLibraryGuid, + (VOID **) &StandardLib, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL + ); + if (EFI_ERROR(Status)) { + return Status; + } + + // + // Get the Recovery Library Interface + // + Status = gtBS->OpenProtocol ( + SupportHandle, + &gEfiTestRecoveryLibraryGuid, + (VOID **) &RecoveryLib, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL + ); + if (EFI_ERROR(Status)) { + StandardLib->RecordAssertion ( + StandardLib, + EFI_TEST_ASSERTION_FAILED, + gTestGenericFailureGuid, + L"BS.OpenProtocol - Handle recovery library", + L"%a:%d:Status - %r", + __FILE__, + (UINTN)__LINE__, + Status + ); + return Status; + } + + // + // Read reset record + // + Status = RecoveryLib->ReadResetRecord ( + RecoveryLib, + &Size, + Buffer + ); + + // + // if ResetRecord has not been written to yet, or EFI_ERROR from reading reset record, start the test from beginning + // + if (EFI_ERROR(Status) || Size < sizeof(RESET_DATA)) { + ResetData->Step = 0; + Status = TCGMemoryOverwriteRequestPlatformResetCheck (StandardLib, RecoveryLib, ResetData); + // + // In the event that the MOR/MORLOCK variables do not exist in accordance to spec, + // or the WriteResetRecord returns EFI_ERROR, test ends prematurely + // + if(EFI_ERROR(Status)) { + return Status; + } + } + + // + // Once TCGMemoryOverwriteRequestPlatformResetCheck has been invoked and ResetRecord written + // check ResetData->CheckpointStep for next test + // + if (ResetData->CheckpointStep == CONTROL_PLATFORM_RESET_TEST) { + // + // Test Checkpoint CONTROL_PLATFORM_RESET_TEST + // + Status = TCGMemoryOverwriteRequestPlatformResetCheck (StandardLib, RecoveryLib, ResetData); + if(EFI_ERROR(Status)) { + return Status; + } + CheckpointStepMatched = TRUE; + } + + if (!CheckpointStepMatched) { + return EFI_INVALID_PARAMETER; // incase of invalid CheckpointStep, return EFI_INVALID_PARAMETER + } + + // + // After all Checkpoints have run successfully + // + return EFI_SUCCESS; +} + + +/** + * Check 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 MemoryOverwriteRequestControlLockData; + UINT32 Attributes; + + // + // Check Step to see which part of test remains to be executed + // + switch (ResetData->Step) { + case 0: + goto INITIAL_RESET; + case 1: + goto MOR_VARIABLE_CHECK; + case 2: + goto MOR_BIT_CLEAR_ON_RESET; + default: + return EFI_INVALID_PARAMETER; + } + +INITIAL_RESET: + // + // Perform initial plaform reset + // + ResetData->Step = 1; + ResetData->CheckpointStep = CONTROL_PLATFORM_RESET_TEST; + + Status = 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 and test will be resumed after reboot."); + Status = gtBS->Stall(1000000); + if (EFI_ERROR(Status)) { + // Handle stall error + SctPrint(L"Error: Failed to stall the system.\n"); + return Status; + } + gtRT->ResetSystem ( + EfiResetCold, + EFI_SUCCESS, + 0, + NULL + ); + SctPrint(L"Error: Failed to perform a cold reset.\n"); + return EFI_DEVICE_ERROR; + +MOR_VARIABLE_CHECK: + // + // Post system reset, Check if the MOR variable is correctly created by platform + // + + // Write reset record before the second reset (MOR_BIT_CLEAR_ON_RESET) + ResetData->Step = 2; + ResetData->CheckpointStep = CONTROL_PLATFORM_RESET_TEST; + + Status = 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 = sizeof(MemoryOverwriteRequestControlData); + Attributes = TCG_MOR_VARIABLE_ATTRIBUTES; + + Status = gtRT->GetVariable ( + L"MemoryOverwriteRequestControl", // VariableName + &gEfiMemoryOverwriteControlDataGuid, // VendorGuid + &Attributes, // Attributes + &DataSize, // DataSize + &MemoryOverwriteRequestControlData // Data + ); + if (EFI_ERROR (Status) || (DataSize != 1) || (Attributes != TCG_MOR_VARIABLE_ATTRIBUTES)) { + Result = EFI_TEST_ASSERTION_FAILED; + } else { + Result = 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, + (UINTN)Attributes + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Set MemoryOverwriteRequestControlData bit 0 and verify the platform clears bit 0 upon system reset + // MOR bit 0 indicates to platform firmware that system memory must be wiped during platform initialization + // + DataSize = sizeof(MemoryOverwriteRequestControlData); + Attributes = TCG_MOR_VARIABLE_ATTRIBUTES; + MemoryOverwriteRequestControlData |= MOR_BIT_HIGH << MOR_CLEAR_MEMORY_BIT_OFFSET; + + Status = gtRT->SetVariable ( + L"MemoryOverwriteRequestControl", // VariableName + &gEfiMemoryOverwriteControlDataGuid, // VendorGuid + Attributes, // Attributes + DataSize, // DataSize + &MemoryOverwriteRequestControlData // Data + ); + if (Status == EFI_SUCCESS) { + Result = EFI_TEST_ASSERTION_PASSED; + }else { + Result = 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 resumed after reboot."); + Status = gtBS->Stall(1000000); + if (EFI_ERROR(Status)) { + // Handle stall error + SctPrint(L"Error: Failed to stall the system.\n"); + return Status; + } + gtRT->ResetSystem ( + EfiResetCold, + EFI_SUCCESS, + 0, + NULL + ); + SctPrint(L"Error: Failed to perform a cold reset.\n"); + return EFI_DEVICE_ERROR; + +MOR_BIT_CLEAR_ON_RESET: + // + // Clear Step count and increment checkpoint for next test + // + + ResetData->Step = 0; + ResetData->CheckpointStep = CONTROL_SET_VARIABLE_TEST; + + Status = 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 = sizeof(MemoryOverwriteRequestControlData); + Attributes = TCG_MOR_VARIABLE_ATTRIBUTES; + + Status = gtRT->GetVariable ( + L"MemoryOverwriteRequestControl", // VariableName + &gEfiMemoryOverwriteControlDataGuid, // VendorGuid + &Attributes, // Attributes + &DataSize, // DataSize + &MemoryOverwriteRequestControlData // Data + ); + if (EFI_ERROR (Status) || (MOR_CLEAR_MEMORY_VALUE (MemoryOverwriteRequestControlData) != MOR_BIT_LOW)) { + Result = EFI_TEST_ASSERTION_FAILED; + } else { + Result = 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 the TCG Platform Reset Attack Mitigation spec + // + DataSize = sizeof(MemoryOverwriteRequestControlLockData); + Attributes = TCG_MOR_VARIABLE_ATTRIBUTES; + + Status = gtRT->GetVariable ( + L"MemoryOverwriteRequestControlLock", // VariableName + &gEfiMemoryOverwriteRequestControlLockGuid, // VendorGuid + &Attributes, // Attributes + &DataSize, // DataSize + &MemoryOverwriteRequestControlLockData // Data + ); + if (EFI_ERROR (Status) || (MemoryOverwriteRequestControlLockData != MOR_LOCK_DATA_UNLOCKED) || + (DataSize != 1) || (Attributes != TCG_MOR_VARIABLE_ATTRIBUTES)) { + Result = EFI_TEST_ASSERTION_FAILED; + } else { + Result = EFI_TEST_ASSERTION_PASSED; + } + + StandardLib->RecordAssertion ( + StandardLib, + Result, + gTCGMemoryOverwriteRequestTestFunctionAssertionGuid004, + L"MemoryOverwriteRequestControlLock - Validate that MORLOCK is created by the platform in accordance with the TCG Spec", + L"%a:%d:Status - %r, DataSize - %d, Attributes - %x", + __FILE__, + (UINTN)__LINE__, + Status, + (UINTN)DataSize, + (UINTN)Attributes + ); + if (EFI_ERROR (Status)) { + return Status; + } + + return EFI_SUCCESS; +} diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestMain.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestMain.c new file mode 100644 index 000000000000..db01df9db5e2 --- /dev/null +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestMain.c @@ -0,0 +1,115 @@ +/** @file + + Copyright 2006 - 2016 Unified EFI, Inc.<BR> + Copyright (c) 2023, Arm Inc. All rights reserved.<BR> + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD 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 IMPLIED. + +**/ +/*++ + +Module Name: + + TCG2MORTestMain.c + +Abstract: + + for EFI Driver TCG MemoryOverwriteRequest Test + +--*/ +#include "SctLib.h" +#include "TCGMemoryOverwriteRequestBBTestMain.h" + +EFI_GUID gEfiMemoryOverwriteControlDataGuid = MEMORY_ONLY_RESET_CONTROL_GUID; + +EFI_GUID gEfiMemoryOverwriteRequestControlLockGuid = MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_GUID; + +EFI_BB_TEST_PROTOCOL_FIELD gEfiTCGMemoryOverwriteRequestTestProtocolField = { + TCG_MOR_TEST_REVISION, + EFI_TCG_MOR_TEST_GUID, + L"TCG MemoryOverwriteRequest Test", + L"TCG MemoryOverwriteRequest Functionality Test" +}; + +EFI_GUID gSupportProtocolGuid1[2] = { + EFI_STANDARD_TEST_LIBRARY_GUID, + EFI_NULL_GUID +}; + +EFI_BB_TEST_ENTRY_FIELD gLoadTCGMemoryOverwriteRequestEntryField[] = { + + { + 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 value. + */ +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/CommonGenFramework.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 $Framework/Test/ > NUL fi + cp $ProcessorType/TCGMemoryOverwriteRequestBBTest.efi $Framework/Test/ > NUL # ********************************************* # Copy ENTS binary diff --git a/uefi-sct/SctPkg/Config/Data/Category.ini b/uefi-sct/SctPkg/Config/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 = AFF115FB-387B-4C18-8C41-6AFC7F03BB90 Name = RuntimeServicesTest\MiscRuntimeServicesTest Description = +[Category Data] +Revision = 0x00010000 +CategoryGuid = 265E661D-D51E-454B-BBC9-665F46EC0A04 +InterfaceGuid = AFF115FB-387B-4C18-8C41-6AFC7F03BB90 +Name = RuntimeServicesTest\TCGMemoryOverwriteRequestTest +Description = Test TCG Platform Reset Attack Mitigation EFI variables + [Category Data] Revision = 0x00010000 CategoryGuid = 5B1B31A1-9562-11D2-8E3F-00A0C969723B -- 2.34.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#116407): https://edk2.groups.io/g/devel/message/116407 Mute This Topic: https://groups.io/mt/104756650/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-