From: "Abhimanyu Singh" <Abhi.Singh@arm.com>
To: devel@edk2.groups.io
Subject: [edk2-devel] [PATCH v2 6/6] uefi-sct/SctPkg: TCG MORLOCK Locked with Key State Test
Date: Thu, 21 Sep 2023 11:37:48 -0500 [thread overview]
Message-ID: <20230921163748.275971-7-Abhi.Singh@arm.com> (raw)
In-Reply-To: <20230921163748.275971-1-Abhi.Singh@arm.com>
SCT spec: https://bugzilla.tianocore.org/show_bug.cgi?id=4374
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4419
-Implement MemoryOverwriteRequestControlLock Locked with
Key State test cases
-Add remaining Assertions 33 - 49 from SCT spec
-Add Test Case to MemoryOverwriteRequestFunctionTest
Cc: G Edhaya Chandran <Edhaya.Chandran@arm.com>
Cc: Barton Gao <gaojie@byosoft.com.cn>
Cc: Carolyn Gjertsen <Carolyn.Gjertsen@amd.com>
Signed-off-by: Abhi Singh <Abhi.Singh@arm.com>
Change-Id: Ifade96b0c6ec9e7f9bfb0eba8ceeb92380271e8b
---
uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/Guid.h | 85 +++
uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestMain.h | 11 +-
uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/Guid.c | 34 ++
uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestFunction.c | 623 ++++++++++++++++++++
4 files changed, 752 insertions(+), 1 deletion(-)
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
index 023e7a37322c..cf7f3e180f54 100644
--- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/Guid.h
+++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/Guid.h
@@ -121,6 +121,57 @@ Abstract:
#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_032_GUID \
{ 0xc8894201, 0x7a3a, 0x47d4, {0xa8, 0x8d, 0xdf, 0x4b, 0x03, 0xff, 0xde, 0x4f }}
+#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_033_GUID \
+{ 0x38a813ac, 0x8eb9, 0x46ce, {0xa8, 0x6b, 0x40, 0x8c, 0x07, 0x5f, 0xc7, 0xed }}
+
+#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_034_GUID \
+{ 0x919b8392, 0xcb78, 0x49ff, {0xa3, 0x18, 0x49, 0x78, 0x76, 0xe0, 0xf8, 0xf8 }}
+
+#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_035_GUID \
+{ 0x219abaf2, 0x04a9, 0x407c, {0xb5, 0xde, 0xa0, 0x03, 0x6e, 0x65, 0xb0, 0xb9 }}
+
+#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_036_GUID \
+{ 0x9a51640a, 0xff14, 0x402b, {0xb0, 0x57, 0xa0, 0xc4, 0xf7, 0x20, 0x8e, 0x44 }}
+
+#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_037_GUID \
+{ 0x8ccd0dbb, 0x9b0a, 0x4bfb, {0xa0, 0x7e, 0xc6, 0x06, 0x8b, 0x91, 0x0d, 0xfb }}
+
+#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_038_GUID \
+{ 0xde6f4e17, 0xe375, 0x4dcb, {0x8f, 0x07, 0x77, 0x7e, 0x62, 0x49, 0xea, 0x2c }}
+
+#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_039_GUID \
+{ 0x4ab6927b, 0x5ee4, 0x4748, {0xa4, 0x9d, 0x2d, 0xf3, 0x70, 0x01, 0x41, 0xd5 }}
+
+#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_040_GUID \
+{ 0x33142ecf, 0x0f92, 0x4625, {0xb7, 0xf6, 0x7f, 0x15, 0x25, 0x74, 0xd3, 0x03 }}
+
+#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_041_GUID \
+{ 0xf73c04df, 0x2e42, 0x4174, {0x82, 0x18, 0x0f, 0x25, 0x46, 0x4a, 0x55, 0xe9 }}
+
+#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_042_GUID \
+{ 0xd4eacf82, 0x55d1, 0x4ba1, {0xbe, 0x89, 0x6a, 0x2e, 0x44, 0x0f, 0xc7, 0xc0 }}
+
+#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_043_GUID \
+{ 0xfd88fe63, 0x5ed4, 0x482a, {0x98, 0x44, 0x23, 0x90, 0xf9, 0x09, 0x1c, 0x20 }}
+
+#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_044_GUID \
+{ 0x176f16cb, 0xf3a4, 0x4f12, {0x8f, 0x96, 0x4a, 0xc1, 0x8b, 0xdd, 0x6e, 0x3c }}
+
+#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_045_GUID \
+{ 0xf0d5e7b3, 0xdc0f, 0x4a18, {0xb9, 0x78, 0x09, 0x3b, 0x15, 0x55, 0x66, 0xbf }}
+
+#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_046_GUID \
+{ 0x9bf14c4b, 0x2950, 0x4c4e, {0x8b, 0xa3, 0x06, 0x46, 0xf1, 0x27, 0x8c, 0x05 }}
+
+#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_047_GUID \
+{ 0xb0468dee, 0xb1d0, 0x4795, {0x9f, 0xbf, 0xbe, 0x3f, 0x40, 0x2f, 0x3d, 0x6f }}
+
+#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_048_GUID \
+{ 0x1f7dd903, 0xcd58, 0x4d6f, {0x80, 0xd6, 0x4f, 0x6d, 0xcb, 0x4a, 0xd6, 0xc9 }}
+
+#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_049_GUID \
+{ 0x439179c2, 0x744d, 0x43bc, {0xb0, 0x67, 0x7b, 0x65, 0x60, 0x62, 0x6f, 0x5e }}
+
extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid001;
extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid002;
@@ -184,3 +235,37 @@ extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid030;
extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid031;
extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid032;
+
+extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid033;
+
+extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid034;
+
+extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid035;
+
+extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid036;
+
+extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid037;
+
+extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid038;
+
+extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid039;
+
+extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid040;
+
+extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid041;
+
+extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid042;
+
+extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid043;
+
+extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid044;
+
+extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid045;
+
+extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid046;
+
+extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid047;
+
+extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid048;
+
+extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid049;
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
index 94ed476f86ad..76b3c76340cf 100644
--- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestMain.h
+++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestMain.h
@@ -50,11 +50,13 @@ typedef struct _RESET_DATA {
#define MOR_LOCK_DATA_UNLOCKED 0x0
#define MOR_LOCK_DATA_LOCKED_WITHOUT_KEY 0x1
+#define MOR_LOCK_DATA_LOCKED_WITH_KEY 0x2
+#define MOR_LOCK_NO_KEY_SIZE 1
#define MOR_LOCK_WITH_KEY_SIZE 8
#define MOR_LOCK_TEST_KEY 0x11111111
-
+#define MOR_LOCK_INVALID_TEST_KEY 0x22222222
//
// TEST GUID for TCG Platform Reset Attack Mitigation MemoryOverwriteRequest (MOR) Test
@@ -118,6 +120,13 @@ TCGMemoryOverwriteRequestControlLockLockedNoKeyState (
IN RESET_DATA *ResetData
);
+EFI_STATUS
+TCGMemoryOverwriteRequestControlLockLockedWithKeyState (
+ IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib,
+ IN EFI_TEST_RECOVERY_LIBRARY_PROTOCOL *RecoveryLib,
+ IN RESET_DATA *ResetData
+ );
+
// ****************************************************************************
// Entry GUIDs for Test
// ****************************************************************************
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
index 11d49306059d..6bde8f686a16 100644
--- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/Guid.c
+++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/Guid.c
@@ -91,3 +91,37 @@ EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid030 = EFI_TEST_TCGMO
EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid031 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_031_GUID;
EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid032 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_032_GUID;
+
+EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid033 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_033_GUID;
+
+EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid034 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_034_GUID;
+
+EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid035 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_035_GUID;
+
+EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid036 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_036_GUID;
+
+EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid037 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_037_GUID;
+
+EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid038 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_038_GUID;
+
+EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid039 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_039_GUID;
+
+EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid040 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_040_GUID;
+
+EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid041 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_041_GUID;
+
+EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid042 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_042_GUID;
+
+EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid043 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_043_GUID;
+
+EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid044 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_044_GUID;
+
+EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid045 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_045_GUID;
+
+EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid046 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_046_GUID;
+
+EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid047 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_047_GUID;
+
+EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid048 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_048_GUID;
+
+EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid049 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_049_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
index 5f5f369124f2..32f3a9cb58d5 100644
--- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestFunction.c
+++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestFunction.c
@@ -170,6 +170,15 @@ BBTestTCGMemoryOverwriteRequestFunctionTest (
return Status;
}
}
+ if (ResetData->CheckpointStep == LOCK_WITH_KEY_STATE_TEST) {
+ //
+ // Test Checkpoint LOCK_WITH_KEY_STATE_TEST
+ //
+ TCGMemoryOverwriteRequestControlLockLockedWithKeyState (StandardLib, RecoveryLib, ResetData);
+ if(EFI_ERROR(Status)) {
+ return Status;
+ }
+ }
//
// After all Checkpoints have run
//
@@ -1664,3 +1673,617 @@ MORLOCK_LOCKED_STATE:
return EFI_SUCCESS;
}
+
+
+/**
+ * MemoryOverwriteRequestControlLock in Locked with Key State Test
+ * When Unlocked, a valid SetVariable() with an 8 byte key must return EFI_SUCCESS
+ * and the Lock value must be 0x02 (MOR_LOCK_DATA_LOCKED_WITH_KEY), in order to
+ * unlock, the same 8 byte key must be passed.
+ *
+ * When Locked with an 8 byte key, SetVariable() with the same 8 byte key
+ * must return EFI_SUCCESS and the Lock value must be 0x00 or MOR_LOCK_DATA_UNLOCKED.
+ *
+ * When Locked with an 8 byte Key, SetVariable() with DataSize != 8 and
+ * Data = 0x01 (MOR_LOCK_DATA_LOCKED_WITHOUT_KEY) or 0x00 (MOR_LOCK_DATA_UNLOCKED)
+ * must return EFI_ACCESS_DENIED
+ * and value must still equal to 0x02 (MOR_LOCK_DATA_LOCKED_WITH_KEY).
+ *
+ * When Locked with an 8 byte Key, SetVariable() with 8 byte key != key used to set
+ * the lock, in this case 0x11111111 (MOR_LOCK_TEST_KEY), must return EFI_ACCESS_DENIED
+ * and lock value must be updated to 0x01 (MOR_LOCK_DATA_LOCKED_WITHOUT_KEY)
+ * to prevent dictonary attack.
+ *
+ * @param StandardLib A pointer to EFI_STANDARD_TEST_LIBRARY_PROTOCOL
+ * instance.
+ * @param RecoveryLib A pointer to EFI_TEST_RECOVERY_LIBRARY_PROTOCOL
+ * instance.
+ * @param ResetData A pointer to the ResetData Buffer which is used throughout
+ * the test
+ * @return EFI_SUCCESS Successfully.
+ * @return Other value Something failed.
+ */
+EFI_STATUS
+TCGMemoryOverwriteRequestControlLockLockedWithKeyState (
+ 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 MemoryOverwriteRequestControlLockData;
+ UINTN MemoryOverwriteControlLockKeyValue;
+ UINT8 MemoryOverwriteRequestControlData;
+ UINT8 MemoryOverwriteRequestControlDataCached;
+ UINT32 Attributes;
+
+ if (ResetData->Step == 0) {
+ goto INITIAL_RESET;
+ } else if (ResetData->Step == 1) {
+ goto MORLOCK_LOCKED_KEY_STATE;
+ }
+
+INITIAL_RESET:
+ //
+ // Reset MORLock variable by performing a cold reset
+ //
+
+ ResetData->Step = 1;
+ ResetData->CheckpointStep = LOCK_WITH_KEY_STATE_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...");
+ gtBS->Stall (1000000);
+ gtRT->ResetSystem (
+ EfiResetCold,
+ EFI_SUCCESS,
+ 0,
+ NULL
+ );
+
+MORLOCK_LOCKED_KEY_STATE:
+ //
+ // MORLOCK Reboot system to clear Lock, and invoke SetVariable() with valid 8 byte key
+ // In this case = 0x11111111, must return EFI_SUCCESS and GetVariable() value must = 0x02
+ //
+
+ DataSize = MOR_LOCK_WITH_KEY_SIZE;
+ Attributes = TCG_MOR_VARIABLE_ATTRIBUTES;
+ MemoryOverwriteControlLockKeyValue = MOR_LOCK_TEST_KEY;
+
+ Status = gtRT->SetVariable (
+ L"MemoryOverwriteRequestControlLock", // VariableName
+ &gEfiMemoryOverwriteRequestControlLockGuid, // VendorGuid
+ Attributes, // Attributes
+ DataSize, // DataSize
+ &MemoryOverwriteControlLockKeyValue // Data
+ );
+ if (Status == EFI_SUCCESS) {
+ Result = EFI_TEST_ASSERTION_PASSED;
+ } else {
+ Result = EFI_TEST_ASSERTION_FAILED;
+ }
+
+ StandardLib->RecordAssertion (
+ StandardLib,
+ Result,
+ gTCGMemoryOverwriteRequestTestFunctionAssertionGuid033,
+ L"MemoryOverwriteRequestControlLock - Setting to Locked with key = 0x11111111 when Unlocked returns EFI_SUCCESS",
+ L"%a:%d:Status - %r",
+ __FILE__,
+ (UINTN)__LINE__,
+ Status
+ );
+
+ 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_LOCKED_WITH_KEY)) {
+ Result = EFI_TEST_ASSERTION_FAILED;
+ } else {
+ Result = EFI_TEST_ASSERTION_PASSED;
+ }
+
+ StandardLib->RecordAssertion (
+ StandardLib,
+ Result,
+ gTCGMemoryOverwriteRequestTestFunctionAssertionGuid034,
+ L"MemoryOverwriteRequestControlLock - Lock State is now Locked and Key = 0x11111111",
+ L"%a:%d:Status - %r",
+ __FILE__,
+ (UINTN)__LINE__,
+ Status
+ );
+
+ //
+ // Locked with 8 byte key, invoke SetVariable() with the same valid 8 byte key used to lock
+ // In this case = 0x11111111, must return EFI_SUCCESS and GetVariable() value must = 0x00
+ //
+ DataSize = MOR_LOCK_WITH_KEY_SIZE;
+ Attributes = TCG_MOR_VARIABLE_ATTRIBUTES;
+ MemoryOverwriteControlLockKeyValue = MOR_LOCK_TEST_KEY;
+
+ Status = gtRT->SetVariable (
+ L"MemoryOverwriteRequestControlLock", // VariableName
+ &gEfiMemoryOverwriteRequestControlLockGuid, // VendorGuid
+ Attributes, // Attributes
+ DataSize, // DataSize
+ &MemoryOverwriteControlLockKeyValue // Data
+ );
+ if (Status == EFI_SUCCESS) {
+ Result = EFI_TEST_ASSERTION_PASSED;
+ } else {
+ Result = EFI_TEST_ASSERTION_FAILED;
+ }
+
+ StandardLib->RecordAssertion (
+ StandardLib,
+ Result,
+ gTCGMemoryOverwriteRequestTestFunctionAssertionGuid035,
+ L"MemoryOverwriteRequestControlLock - Setting to unlocked with key = 0x11111111 when Locked with the same key returns EFI_SUCCESS",
+ L"%a:%d:Status - %r",
+ __FILE__,
+ (UINTN)__LINE__,
+ Status
+ );
+
+ 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)) {
+ Result = EFI_TEST_ASSERTION_FAILED;
+ } else {
+ Result = EFI_TEST_ASSERTION_PASSED;
+ }
+
+ StandardLib->RecordAssertion (
+ StandardLib,
+ Result,
+ gTCGMemoryOverwriteRequestTestFunctionAssertionGuid036,
+ L"MemoryOverwriteRequestControlLock - Lock State is now Unlocked",
+ L"%a:%d:Status - %r",
+ __FILE__,
+ (UINTN)__LINE__,
+ Status
+ );
+
+ //
+ // Lock with same 8 byte key again, verify EFI_SUCCESS is returned
+ // unlock attempt: invoke SetVariable() with the same valid 8 byte
+ // key used to lock = 0x11111111, but with invalid DataSize == 1
+ // must return EFI_ACCESS_DENIED and GetVariable() value must = 0x02
+ //
+ DataSize = MOR_LOCK_WITH_KEY_SIZE;
+ Attributes = TCG_MOR_VARIABLE_ATTRIBUTES;
+ MemoryOverwriteControlLockKeyValue = MOR_LOCK_TEST_KEY;
+
+ Status = gtRT->SetVariable (
+ L"MemoryOverwriteRequestControlLock", // VariableName
+ &gEfiMemoryOverwriteRequestControlLockGuid, // VendorGuid
+ Attributes, // Attributes
+ DataSize, // DataSize
+ &MemoryOverwriteControlLockKeyValue // Data
+ );
+ if (Status == EFI_SUCCESS) {
+ Result = EFI_TEST_ASSERTION_PASSED;
+ } else {
+ Result = EFI_TEST_ASSERTION_FAILED;
+ }
+
+ StandardLib->RecordAssertion (
+ StandardLib,
+ Result,
+ gTCGMemoryOverwriteRequestTestFunctionAssertionGuid037,
+ L"MemoryOverwriteRequestControlLock - Setting to Locked with key = 0x11111111 when Unlocked returns EFI_SUCCESS",
+ L"%a:%d:Status - %r",
+ __FILE__,
+ (UINTN)__LINE__,
+ Status
+ );
+
+ DataSize = MOR_LOCK_NO_KEY_SIZE; // invalid datasize == 1
+ Attributes = TCG_MOR_VARIABLE_ATTRIBUTES;
+ MemoryOverwriteControlLockKeyValue = MOR_LOCK_TEST_KEY;
+
+ Status = gtRT->SetVariable (
+ L"MemoryOverwriteRequestControlLock", // VariableName
+ &gEfiMemoryOverwriteRequestControlLockGuid, // VendorGuid
+ Attributes, // Attributes
+ DataSize, // DataSize
+ &MemoryOverwriteControlLockKeyValue // Data
+ );
+ if (Status == EFI_ACCESS_DENIED) {
+ Result = EFI_TEST_ASSERTION_PASSED;
+ } else {
+ Result = EFI_TEST_ASSERTION_FAILED;
+ }
+
+ StandardLib->RecordAssertion (
+ StandardLib,
+ Result,
+ gTCGMemoryOverwriteRequestTestFunctionAssertionGuid038,
+ L"MemoryOverwriteRequestControlLock - Attempting to unlock by passing Invalid DataSize returns EFI_ACCESS_DENIED",
+ L"%a:%d:Status - %r",
+ __FILE__,
+ (UINTN)__LINE__,
+ Status
+ );
+
+ 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_LOCKED_WITH_KEY)) {
+ Result = EFI_TEST_ASSERTION_FAILED;
+ } else {
+ Result = EFI_TEST_ASSERTION_PASSED;
+ }
+
+ StandardLib->RecordAssertion (
+ StandardLib,
+ Result,
+ gTCGMemoryOverwriteRequestTestFunctionAssertionGuid039,
+ L"MemoryOverwriteRequestControlLock - Lock State is still Locked with Key = 0x11111111",
+ L"%a:%d:Status - %r",
+ __FILE__,
+ (UINTN)__LINE__,
+ Status
+ );
+
+ //
+ // invoke MORLOCK SetVariable() with Data value = 0x00 to change to unlocked
+ // must return EFI_ACCESS_DENIED and GetVariable() value must still = 0x02
+ //
+ DataSize = sizeof(MemoryOverwriteRequestControlLockData);
+ Attributes = TCG_MOR_VARIABLE_ATTRIBUTES;
+ MemoryOverwriteRequestControlLockData = MOR_LOCK_DATA_UNLOCKED;
+
+ Status = gtRT->SetVariable (
+ L"MemoryOverwriteRequestControlLock", // VariableName
+ &gEfiMemoryOverwriteRequestControlLockGuid, // VendorGuid
+ Attributes, // Attributes
+ DataSize, // DataSize
+ &MemoryOverwriteRequestControlLockData // Data
+ );
+ if (Status == EFI_ACCESS_DENIED) {
+ Result = EFI_TEST_ASSERTION_PASSED;
+ } else {
+ Result = EFI_TEST_ASSERTION_FAILED;
+ }
+
+ StandardLib->RecordAssertion (
+ StandardLib,
+ Result,
+ gTCGMemoryOverwriteRequestTestFunctionAssertionGuid040,
+ L"MemoryOverwriteRequestControlLock - Setting to Unlocked when Locked with key returns EFI_ACCESS_DENIED",
+ L"%a:%d:Status - %r",
+ __FILE__,
+ (UINTN)__LINE__,
+ Status
+ );
+
+ 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_LOCKED_WITH_KEY)) {
+ Result = EFI_TEST_ASSERTION_FAILED;
+ } else {
+ Result = EFI_TEST_ASSERTION_PASSED;
+ }
+
+ StandardLib->RecordAssertion (
+ StandardLib,
+ Result,
+ gTCGMemoryOverwriteRequestTestFunctionAssertionGuid041,
+ L"MemoryOverwriteRequestControlLock - Lock State is still Locked with Key = 0x11111111",
+ L"%a:%d:Status - %r",
+ __FILE__,
+ (UINTN)__LINE__,
+ Status
+ );
+
+ //
+ // invoke MORLOCK SetVariable() with Data value = 0x01 to change to locked without key
+ // must return EFI_ACCESS_DENIED and GetVariable() value must still = 0x02
+ //
+ DataSize = sizeof(MemoryOverwriteRequestControlLockData);
+ Attributes = TCG_MOR_VARIABLE_ATTRIBUTES;
+ MemoryOverwriteRequestControlLockData = MOR_LOCK_DATA_LOCKED_WITHOUT_KEY;
+
+ Status = gtRT->SetVariable (
+ L"MemoryOverwriteRequestControlLock", // VariableName
+ &gEfiMemoryOverwriteRequestControlLockGuid, // VendorGuid
+ Attributes, // Attributes
+ DataSize, // DataSize
+ &MemoryOverwriteRequestControlLockData // Data
+ );
+ if (Status == EFI_ACCESS_DENIED) {
+ Result = EFI_TEST_ASSERTION_PASSED;
+ } else {
+ Result = EFI_TEST_ASSERTION_FAILED;
+ }
+
+ StandardLib->RecordAssertion (
+ StandardLib,
+ Result,
+ gTCGMemoryOverwriteRequestTestFunctionAssertionGuid042,
+ L"MemoryOverwriteRequestControlLock - Setting to Locked without key when Locked with key returns EFI_ACCESS_DENIED",
+ L"%a:%d:Status - %r",
+ __FILE__,
+ (UINTN)__LINE__,
+ Status
+ );
+
+ 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_LOCKED_WITH_KEY)) {
+ Result = EFI_TEST_ASSERTION_FAILED;
+ } else {
+ Result = EFI_TEST_ASSERTION_PASSED;
+ }
+
+ StandardLib->RecordAssertion (
+ StandardLib,
+ Result,
+ gTCGMemoryOverwriteRequestTestFunctionAssertionGuid043,
+ L"MemoryOverwriteRequestControlLock - Lock State is still Locked with Key = 0x11111111",
+ L"%a:%d:Status - %r",
+ __FILE__,
+ (UINTN)__LINE__,
+ Status
+ );
+
+ //
+ // Once Locked with key, MOR SetVariable() call to set MOR Bit 0 must return EFI_ACCESS_DENIED
+ // and MOR value must not change
+ //
+ DataSize = sizeof(MemoryOverwriteRequestControlData);
+ Attributes = TCG_MOR_VARIABLE_ATTRIBUTES;
+ // getting current MOR value that will be used to check that the variable is unchanged
+ Status = gtRT->GetVariable (
+ L"MemoryOverwriteRequestControl", // VariableName
+ &gEfiMemoryOverwriteControlDataGuid, // VendorGuid
+ &Attributes, // Attributes
+ &DataSize, // DataSize
+ &MemoryOverwriteRequestControlData // Data
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ // caching variable and setting the bit 0
+ MemoryOverwriteRequestControlDataCached = MemoryOverwriteRequestControlData;
+
+ 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_ACCESS_DENIED) {
+ Result = EFI_TEST_ASSERTION_PASSED;
+ } else {
+ Result = EFI_TEST_ASSERTION_FAILED;
+ }
+
+ StandardLib->RecordAssertion (
+ StandardLib,
+ Result,
+ gTCGMemoryOverwriteRequestTestFunctionAssertionGuid044,
+ L"MemoryOverwriteRequestControl - SetVariable() returns EFI_ACCESS_DENIED when Lock is Set with no key",
+ L"%a:%d:Status - %r",
+ __FILE__,
+ (UINTN)__LINE__,
+ Status
+ );
+
+ DataSize = sizeof(MemoryOverwriteRequestControlData);
+ Attributes = TCG_MOR_VARIABLE_ATTRIBUTES;
+
+ Status = gtRT->GetVariable (
+ L"MemoryOverwriteRequestControl", // VariableName
+ &gEfiMemoryOverwriteControlDataGuid, // VendorGuid
+ &Attributes, // Attributes
+ &DataSize, // DataSize
+ &MemoryOverwriteRequestControlData // Data
+ );
+
+ // verifying that the variable has not been modified with SetVar
+ if (MemoryOverwriteRequestControlDataCached == MemoryOverwriteRequestControlData) {
+ Result = EFI_TEST_ASSERTION_PASSED;
+ } else {
+ Result = EFI_TEST_ASSERTION_FAILED;
+ }
+
+ StandardLib->RecordAssertion (
+ StandardLib,
+ Result,
+ gTCGMemoryOverwriteRequestTestFunctionAssertionGuid045,
+ L"MemoryOverwriteRequestControl - SetVariable() value remains unchanged when Lock is Set with no key",
+ L"%a:%d:Status - %r",
+ __FILE__,
+ (UINTN)__LINE__,
+ Status
+ );
+
+ //
+ // When Locked with an 8 byte Key, SetVariable() with 8 byte key != key used to set
+ // the lock, in this case 0x11111111, must return EFI_ACCESS_DENIED and lock must
+ // be updated Locked without key (Data value = 0x01) to prevent dictonary attack
+ // The invalid key to be used to attempt unlock is = 0x22222222
+ //
+ DataSize = MOR_LOCK_WITH_KEY_SIZE;
+ Attributes = TCG_MOR_VARIABLE_ATTRIBUTES;
+ MemoryOverwriteControlLockKeyValue = MOR_LOCK_INVALID_TEST_KEY; //INVALID KEY != 0x11111111
+
+ Status = gtRT->SetVariable (
+ L"MemoryOverwriteRequestControlLock", // VariableName
+ &gEfiMemoryOverwriteRequestControlLockGuid, // VendorGuid
+ Attributes, // Attributes
+ DataSize, // DataSize
+ &MemoryOverwriteControlLockKeyValue // Data
+ );
+ if (Status == EFI_ACCESS_DENIED) {
+ Result = EFI_TEST_ASSERTION_PASSED;
+ } else {
+ Result = EFI_TEST_ASSERTION_FAILED;
+ }
+
+ StandardLib->RecordAssertion (
+ StandardLib,
+ Result,
+ gTCGMemoryOverwriteRequestTestFunctionAssertionGuid046,
+ L"MemoryOverwriteRequestControlLock - Unlocking Lock with Invalid key != 0x11111111 returns EFI_ACCESS_DENIED",
+ L"%a:%d:Status - %r",
+ __FILE__,
+ (UINTN)__LINE__,
+ Status
+ );
+
+ 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_LOCKED_WITHOUT_KEY)) {
+ Result = EFI_TEST_ASSERTION_FAILED;
+ } else {
+ Result = EFI_TEST_ASSERTION_PASSED;
+ }
+
+ StandardLib->RecordAssertion (
+ StandardLib,
+ Result,
+ gTCGMemoryOverwriteRequestTestFunctionAssertionGuid047,
+ L"MemoryOverwriteRequestControlLock - Lock State is now locked without key",
+ L"%a:%d:Status - %r",
+ __FILE__,
+ (UINTN)__LINE__,
+ Status
+ );
+
+ //
+ // Lock has been updated to Locked without key (Data value = 0x01) to prevent dictonary attack
+ // Now check to see if the Lock can still be unlocked with the corect Key from assertion 37
+ // The key to be used to attempt unlock is = 0x11111111
+ //
+ DataSize = MOR_LOCK_WITH_KEY_SIZE;
+ Attributes = TCG_MOR_VARIABLE_ATTRIBUTES;
+ MemoryOverwriteControlLockKeyValue = MOR_LOCK_TEST_KEY;
+
+ Status = gtRT->SetVariable (
+ L"MemoryOverwriteRequestControlLock", // VariableName
+ &gEfiMemoryOverwriteRequestControlLockGuid, // VendorGuid
+ Attributes, // Attributes
+ DataSize, // DataSize
+ &MemoryOverwriteControlLockKeyValue // Data
+ );
+ if (Status == EFI_ACCESS_DENIED) {
+ Result = EFI_TEST_ASSERTION_PASSED;
+ } else {
+ Result = EFI_TEST_ASSERTION_FAILED;
+ }
+
+ StandardLib->RecordAssertion (
+ StandardLib,
+ Result,
+ gTCGMemoryOverwriteRequestTestFunctionAssertionGuid048,
+ L"MemoryOverwriteRequestControlLock - Attempt to unlock Lock after dictionary attack mitigation returns EFI_ACCESS_DENIED",
+ L"%a:%d:Status - %r",
+ __FILE__,
+ (UINTN)__LINE__,
+ Status
+ );
+
+ 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_LOCKED_WITHOUT_KEY)) {
+ Result = EFI_TEST_ASSERTION_FAILED;
+ } else {
+ Result = EFI_TEST_ASSERTION_PASSED;
+ }
+
+ StandardLib->RecordAssertion (
+ StandardLib,
+ Result,
+ gTCGMemoryOverwriteRequestTestFunctionAssertionGuid049,
+ L"MemoryOverwriteRequestControlLock - Lock State is still locked without key",
+ L"%a:%d:Status - %r",
+ __FILE__,
+ (UINTN)__LINE__,
+ Status
+ );
+
+ return EFI_SUCCESS;
+}
--
2.34.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108954): https://edk2.groups.io/g/devel/message/108954
Mute This Topic: https://groups.io/mt/101504341/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
next prev parent reply other threads:[~2023-09-21 16:38 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-21 16:37 [edk2-devel] [PATCH v2 0/6] RESEND: TCG MemoryOverwriteRequest Tests Abhimanyu Singh
2023-09-21 16:37 ` [edk2-devel] [PATCH v2 1/6] uefi-sct/SctPkg: TCG Platform Reset Check Test Abhimanyu Singh
2023-09-21 16:37 ` [edk2-devel] [PATCH v2 2/6] uefi-sct/SctPkg: TCG MOR SetVariable Test Abhimanyu Singh
2023-09-21 19:03 ` Stuart Yoder
2023-09-21 16:37 ` [edk2-devel] [PATCH v2 3/6] uefi-sct/SctPkg: TCG MORLOCK " Abhimanyu Singh
2023-09-21 19:03 ` Stuart Yoder
2023-09-21 16:37 ` [edk2-devel] [PATCH v2 4/6] uefi-sct/SctPkg: TCG MORLOCK Unlocked State Test Abhimanyu Singh
2023-09-21 19:03 ` Stuart Yoder
2023-09-21 16:37 ` [edk2-devel] [PATCH v2 5/6] uefi-sct/SctPkg: TCG MORLOCK Locked No Key " Abhimanyu Singh
2023-09-21 19:03 ` Stuart Yoder
2023-09-21 16:37 ` Abhimanyu Singh [this message]
2023-09-21 19:03 ` [edk2-devel] [PATCH v2 6/6] uefi-sct/SctPkg: TCG MORLOCK Locked with " Stuart Yoder
2023-09-21 19:03 ` [edk2-devel] [PATCH v2 0/6] RESEND: TCG MemoryOverwriteRequest Tests Stuart Yoder
-- strict thread matches above, loose matches on Subject: below --
2023-08-23 2:09 [edk2-devel] [PATCH v2 0/6] " Abhimanyu Singh
2023-08-23 2:09 ` [edk2-devel] [PATCH v2 6/6] uefi-sct/SctPkg: TCG MORLOCK Locked with Key State Test Abhimanyu Singh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230921163748.275971-7-Abhi.Singh@arm.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox