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 55446780091 for ; Wed, 23 Aug 2023 02:09:57 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=I2hGKHJrygfgiJYtCw6HSA7GU9Itzm3kYueKfCwC+Lo=; 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=1692756596; v=1; b=mvYN11rBeWPUh7k8lxjttH59D+Bhv7XeVfuqzvdE9JfdKLnwQQl9gHqD8vc7XgnwypriQAyC yP8eNSt1qrZZ7qo1u+4T1w5jNeDQ2fmnDAPPQ3XbMX9v/c6EhLO12JxlcqCnLYOcrl69h6Oxc/N 4305D56y5AhN65Ct74kZUTh0= X-Received: by 127.0.0.2 with SMTP id Ax2JYY7687511xTsdc8qJ9Ki; Tue, 22 Aug 2023 19:09:56 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.2909.1692756591367769539 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 759AC1515 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 AF71A3F762 for ; Tue, 22 Aug 2023 19:09:50 -0700 (PDT) From: "Abhimanyu Singh" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v2 4/6] uefi-sct/SctPkg: TCG MORLOCK Unlocked State Test Date: Tue, 22 Aug 2023 21:09:45 -0500 Message-Id: <20230823020947.124395-5-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: fKGIZHzUqnSfbA8DsNz2Yyrzx7686176AA= 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=mvYN11rB; 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 SCT spec: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4374 BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4419 -Implement MemoryOverwriteRequestControlLock Unlocked State test cases -Add Assertions 19, 20, 21, and 22 from SCT spec -Add Test Case to MemoryOverwriteRequestFunctionTest Cc: G Edhaya Chandran Cc: Barton Gao Cc: Carolyn Gjertsen Signed-off-by: Abhi Singh Change-Id: If9cbea790d6c0f5aaceb6834fb91f5e1f3752244 --- uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteReques= t/BlackBoxTest/Guid.h | 20 ++ uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteReques= t/BlackBoxTest/TCGMemoryOverwriteRequestBBTestMain.h | 7 + uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteReques= t/BlackBoxTest/Guid.c | 8 + uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteReques= t/BlackBoxTest/TCGMemoryOverwriteRequestBBTestFunction.c | 224 ++++++++++++= ++++++++ 4 files changed, 259 insertions(+) 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 index 29be47393385..daf17793c094 100644 --- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteR= equest/BlackBoxTest/Guid.h +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteR= equest/BlackBoxTest/Guid.h @@ -79,6 +79,18 @@ Abstract: #define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_018_GUID \=0D { 0xbbaa52b6, 0x5576, 0x4acd, {0xb9, 0x5f, 0x86, 0x22, 0x5e, 0xfc, 0xb0, 0= x31 }}=0D =0D +#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_019_GUID \=0D +{ 0x60b227e0, 0x9f5c, 0x412c, {0x88, 0x79, 0xd3, 0x59, 0xfc, 0xd0, 0xdd, 0= x3f }}=0D +=0D +#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_020_GUID \=0D +{ 0x2eba284a, 0xf701, 0x4c19, {0xbe, 0x5c, 0x39, 0x27, 0xb0, 0x68, 0x4f, 0= xd7 }}=0D +=0D +#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_021_GUID \=0D +{ 0x9a1b44ae, 0x08ce, 0x474c, {0xa5, 0x8e, 0xa6, 0xe2, 0xcf, 0xaf, 0x91, 0= x2c }}=0D +=0D +#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_022_GUID \=0D +{ 0x490d7b39, 0xcad4, 0x4e8c, {0xb1, 0x5d, 0x63, 0xd2, 0x0c, 0xb3, 0xe9, 0= x45 }}=0D +=0D extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid001;=0D =0D extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid002;=0D @@ -114,3 +126,11 @@ extern EFI_GUID gTCGMemoryOverwriteRequestTestFunction= AssertionGuid016; extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid017;=0D =0D extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid018;=0D +=0D +extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid019;=0D +=0D +extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid020;=0D +=0D +extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid021;=0D +=0D +extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid022;=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 index 553959762be8..15eedc60f19d 100644 --- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteR= equest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestMain.h +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteR= equest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestMain.h @@ -100,6 +100,13 @@ TCGMemoryOverwriteRequestControlLockSetVariable ( IN RESET_DATA *ResetData=0D );=0D =0D +EFI_STATUS=0D +TCGMemoryOverwriteRequestControlLockUnlockedState (=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 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 index 8574b51af6e4..c41a611d3a4e 100644 --- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteR= equest/BlackBoxTest/Guid.c +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteR= equest/BlackBoxTest/Guid.c @@ -63,3 +63,11 @@ EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertion= Guid016 =3D EFI_TEST_TCGMO EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid017 =3D EFI_TE= ST_TCGMORTESTFUNCTION_ASSERTION_017_GUID;=0D =0D EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid018 =3D EFI_TE= ST_TCGMORTESTFUNCTION_ASSERTION_018_GUID;=0D +=0D +EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid019 =3D EFI_TE= ST_TCGMORTESTFUNCTION_ASSERTION_019_GUID;=0D +=0D +EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid020 =3D EFI_TE= ST_TCGMORTESTFUNCTION_ASSERTION_020_GUID;=0D +=0D +EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid021 =3D EFI_TE= ST_TCGMORTESTFUNCTION_ASSERTION_021_GUID;=0D +=0D +EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid022 =3D EFI_TE= ST_TCGMORTESTFUNCTION_ASSERTION_022_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 index 5b6adbe550c7..77abab6e79be 100644 --- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteR= equest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestFunction.c +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteR= equest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestFunction.c @@ -41,6 +41,8 @@ Abstract: =0D #define LOCK_UNLOCKED_STATE_TEST 4=0D =0D +#define LOCK_NO_KEY_STATE_TEST 5=0D +=0D =0D /**=0D * Entry point for TCG Platform Reset Attack Mitigation MemoryOverwrite E= FI Variables Function Test.=0D @@ -148,6 +150,15 @@ BBTestTCGMemoryOverwriteRequestFunctionTest ( return Status;=0D }=0D }=0D + if (ResetData->CheckpointStep =3D=3D LOCK_UNLOCKED_STATE_TEST) {=0D + //=0D + // Test Checkpoint LOCK_UNLOCKED_STATE_TEST=0D + //=0D + TCGMemoryOverwriteRequestControlLockUnlockedState (StandardLib, Recove= ryLib, ResetData);=0D + if(EFI_ERROR(Status)) {=0D + return Status;=0D + }=0D + }=0D //=0D // After all Checkpoints have run=0D //=0D @@ -1015,3 +1026,216 @@ MORLOCK_SET_VARIABLE: =0D return EFI_SUCCESS;=0D }=0D +=0D +=0D +/**=0D + * MemoryOverwriteRequestControlLock in Unlocked State Test=0D + * When Unlocked, the Lock should stay unlocked when passed a valid value= of 0x00=0D + * Or when passed an invalud data value !=3D 0x00 or !=3D 0x01, such as 0= x02 the lock=0D + * must stay unlocked and return EFI_INVALID_PARAMETER=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 + * @param ResetData A pointer to the ResetData Buffer which is used = throughout=0D + * the test=0D + * @return EFI_SUCCESS Successfully.=0D + * @return Other value Something failed.=0D + */=0D +EFI_STATUS=0D +TCGMemoryOverwriteRequestControlLockUnlockedState (=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 MemoryOverwriteRequestControlLockDa= ta;=0D + UINT32 Attributes;=0D +=0D + if (ResetData->Step =3D=3D 0) {=0D + goto INITIAL_RESET;=0D + } else if (ResetData->Step =3D=3D 1) {=0D + goto MORLOCK_UNLOCKED_STATE;=0D + }=0D +=0D +INITIAL_RESET:=0D + //=0D + // Reset MORLock variable by performing a cold reset=0D + //=0D +=0D + ResetData->Step =3D 1;=0D + ResetData->CheckpointStep =3D LOCK_UNLOCKED_STATE_TEST;=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 + 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 +MORLOCK_UNLOCKED_STATE:=0D + //=0D + // TESTING MORLOCK scenarios when the Variable is in the Unlocked State= =0D + //=0D +=0D + ResetData->Step =3D 0;=0D + ResetData->CheckpointStep =3D LOCK_NO_KEY_STATE_TEST;=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 + //Setting MORLOCK to Unlocked when already in Unlocked State should retu= rn EFI_SUCCESS=0D + //and the MORLOCK value should still be =3D 0x00 or Unlocked=0D + //=0D + DataSize =3D sizeof(MemoryOverwriteRequestControlLockData);=0D + Attributes =3D TCG_MOR_VARIABLE_ATTRIBUTES;=0D + MemoryOverwriteRequestControlLockData =3D MOR_LOCK_DATA_UNLOCKED;=0D +=0D + Status =3D gtRT->SetVariable (=0D + L"MemoryOverwriteRequestControlLock", // Variable= Name=0D + &gEfiMemoryOverwriteRequestControlLockGuid, // VendorGu= id=0D + Attributes, // Attribut= es=0D + DataSize, // DataSize= =0D + &MemoryOverwriteRequestControlLockData // 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 + gTCGMemoryOverwriteRequestTestFunctionAssertionGuid019,= =0D + L"MemoryOverwriteRequestControlLock - Setting to Unlocke= d when Already Unlocked Should return EFI_SUCCESS",=0D + L"%a:%d:Status - %r",=0D + __FILE__,=0D + (UINTN)__LINE__,=0D + Status=0D + );=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 + 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 + gTCGMemoryOverwriteRequestTestFunctionAssertionGuid020,= =0D + L"MemoryOverwriteRequestControlLock - Lock value remains= Unlocked",=0D + L"%a:%d:Status - %r",=0D + __FILE__,=0D + (UINTN)__LINE__,=0D + Status=0D + );=0D +=0D + //=0D + //Setting MORLOCK with an invalid Data parameter !=3D 0x01 should return= EFI_INVALID_PARAMETER=0D + //and the MORLOCK value should still be =3D 0x00=0D + //=0D + DataSize =3D sizeof(MemoryOverwriteRequestControlLockData);=0D + Attributes =3D TCG_MOR_VARIABLE_ATTRIBUTES;=0D + MemoryOverwriteRequestControlLockData =3D 0x02;=0D +=0D + Status =3D gtRT->SetVariable (=0D + L"MemoryOverwriteRequestControlLock", // Variable= Name=0D + &gEfiMemoryOverwriteRequestControlLockGuid, // VendorGu= id=0D + Attributes, // Attribut= es=0D + DataSize, // DataSize= =0D + &MemoryOverwriteRequestControlLockData // Data=0D + );=0D + if (Status =3D=3D EFI_INVALID_PARAMETER) {=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 + gTCGMemoryOverwriteRequestTestFunctionAssertionGuid021,= =0D + L"MemoryOverwriteRequestControlLock - invalid Data =3D 0= x02 returns EFI_INVALID_PARAMETER",=0D + L"%a:%d:Status - %r",=0D + __FILE__,=0D + (UINTN)__LINE__,=0D + Status=0D + );=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 + 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 + gTCGMemoryOverwriteRequestTestFunctionAssertionGuid022,= =0D + L"MemoryOverwriteRequestControlLock - Lock value remains= Unlocked",=0D + L"%a:%d:Status - %r",=0D + __FILE__,=0D + (UINTN)__LINE__,=0D + Status=0D + );=0D +=0D + return EFI_SUCCESS;=0D +}=0D --=20 2.34.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#107965): https://edk2.groups.io/g/devel/message/107965 Mute This Topic: https://groups.io/mt/100907773/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-