public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Abhimanyu Singh" <Abhi.Singh@arm.com>
To: devel@edk2.groups.io
Subject: [edk2-devel] [PATCH v2 2/6] uefi-sct/SctPkg: TCG MOR SetVariable Test
Date: Thu, 21 Sep 2023 11:37:44 -0500	[thread overview]
Message-ID: <20230921163748.275971-3-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 MemoryOverwriteRequestControlSetVariable test cases
 -Add Assertions 5, 6, 7, and 8 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: I21ed8d6613c7b9d20560b8fa4a45632008d756f9
---
 uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/Guid.h                                    |  20 ++
 uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestMain.h     |   7 +
 uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/Guid.c                                    |   8 +
 uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/TCGMemoryOverwriteRequest/BlackBoxTest/TCGMemoryOverwriteRequestBBTestFunction.c | 202 ++++++++++++++++++++
 4 files changed, 237 insertions(+)

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 a3d87a3eb764..84175504579c 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
@@ -37,6 +37,18 @@ Abstract:
 #define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_004_GUID \
 { 0x002519c6, 0x859f, 0x4d25, {0xb1, 0x36, 0xb2, 0xef, 0x61, 0xe5, 0xd9, 0x6f }}
 
+#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_005_GUID \
+{ 0x13e97668, 0xe905, 0x452d, {0xa0, 0x72, 0x03, 0xde, 0xbf, 0x53, 0xdf, 0xa2 }}
+
+#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_006_GUID \
+{ 0x94811e97, 0x7513, 0x4099, {0xae, 0xb8, 0x5a, 0x7e, 0x7d, 0x50, 0xb4, 0x99 }}
+
+#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_007_GUID \
+{ 0x15378290, 0x17dd, 0x4cbf, {0x8e, 0x8f, 0xc2, 0x4b, 0xc9, 0x09, 0xb4, 0x14 }}
+
+#define EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_008_GUID \
+{ 0x5f0b42ef, 0x3cec, 0x46ad, {0xbc, 0x5b, 0xc3, 0x7a, 0x1d, 0x45, 0x41, 0x29 }}
+
 extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid001;
 
 extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid002;
@@ -44,3 +56,11 @@ extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid002;
 extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid003;
 
 extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid004;
+
+extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid005;
+
+extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid006;
+
+extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid007;
+
+extern EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid008;
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 45bd921ecca4..46c2c2faa388 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
@@ -85,6 +85,13 @@ TCGMemoryOverwriteRequestPlatformResetCheck (
   IN RESET_DATA                               *ResetData
   );
 
+EFI_STATUS
+TCGMemoryOverwriteRequestControlSetVariable (
+  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 59c798a710f1..07bc98b8d764 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
@@ -35,3 +35,11 @@ EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid002 = EFI_TEST_TCGMO
 EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid003 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_003_GUID;
 
 EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid004 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_004_GUID;
+
+EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid005 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_005_GUID;
+
+EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid006 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_006_GUID;
+
+EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid007 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_007_GUID;
+
+EFI_GUID gTCGMemoryOverwriteRequestTestFunctionAssertionGuid008 = EFI_TEST_TCGMORTESTFUNCTION_ASSERTION_008_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 82f9300dd296..40842f2b064e 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
@@ -37,6 +37,8 @@ Abstract:
 
 #define CONTROL_SET_VARIABLE_TEST   2
 
+#define LOCK_SET_VARIABLE_TEST      3
+
 
 /**
  *  Entry point for TCG Platform Reset Attack Mitigation MemoryOverwrite EFI Variables Function Test.
@@ -126,6 +128,15 @@ BBTestTCGMemoryOverwriteRequestFunctionTest (
       return Status;
     }
   }
+  if (ResetData->CheckpointStep == CONTROL_SET_VARIABLE_TEST) {
+    //
+    // Test Checkpoint CONTROL_SET_VARIABLE_TEST
+    //
+    Status = TCGMemoryOverwriteRequestControlSetVariable (StandardLib, RecoveryLib, ResetData); 
+    if(EFI_ERROR(Status)) {
+      return Status;
+    }
+  }
   //
   // After all Checkpoints have run
   //
@@ -408,3 +419,194 @@ MOR_BIT_CLEAR_ON_RESET:
 
   return EFI_SUCCESS;
 }
+
+
+/**
+ *  MemoryOverwriteRequestControl EFI variable SetVariable() requests with a single invalid parameter
+ *  @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
+TCGMemoryOverwriteRequestControlSetVariable (
+  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                                MemoryOverwriteRequestControlDataCached;
+  UINT32                               Attributes;
+
+  //
+  // Write reset record to initiate checkpoint LOCK_SET_VARIABLE_TEST after these assertions are complete
+  //
+  ResetData->Step = 0;
+  ResetData->CheckpointStep = LOCK_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;
+  }
+
+  //
+  //MOR SetVariable() with invalid DataSize == 0 returns EFI_INVALID_PARAMETER and value is unchanged
+  //using GetVariable() before and after SetVariable() to compare values of the data
+  //
+  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)) {
+    return Status;
+  }
+
+  // caching variable for later comparison with second GetVariable() value
+  // SetVar with changed value and invalid DataSize == 0
+  MemoryOverwriteRequestControlDataCached = MemoryOverwriteRequestControlData;
+
+  DataSize = 0;
+  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_INVALID_PARAMETER) {
+    Result = EFI_TEST_ASSERTION_PASSED;
+  } else {
+    Result = EFI_TEST_ASSERTION_FAILED;
+  }
+
+  StandardLib->RecordAssertion (
+                  StandardLib,
+                  Result,
+                  gTCGMemoryOverwriteRequestTestFunctionAssertionGuid005,
+                  L"MemoryOverwriteRequestControl - SetVariable() with DataSize == 0 returns EFI_INVALID_PARAMETER",
+                  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,
+                  gTCGMemoryOverwriteRequestTestFunctionAssertionGuid006,
+                  L"MemoryOverwriteRequestControl - SetVariable() with DataSize == 0 variable value remains unchanged",
+                  L"%a:%d:Status - %r",
+                  __FILE__,
+                  (UINTN)__LINE__,
+                  Status
+                  );
+
+  //
+  // MOR SetVariable() with invalid Attributes == NV + BS returns EFI_INVALID_PARAMETER and value is unchanged
+  // SetVar with set bit 0, DataSize = 1 and invalid attributes = NV + BS
+  //
+  DataSize = sizeof(MemoryOverwriteRequestControlData);
+  Attributes = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS;
+  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_INVALID_PARAMETER) {
+    Result = EFI_TEST_ASSERTION_PASSED;
+  } else {
+    Result = EFI_TEST_ASSERTION_FAILED;
+  }
+
+  StandardLib->RecordAssertion (
+                  StandardLib,
+                  Result,
+                  gTCGMemoryOverwriteRequestTestFunctionAssertionGuid007,
+                  L"MemoryOverwriteRequestControl - SetVariable() with Attributes == NV returns EFI_INVALID_PARAMETER",
+                  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,
+                  gTCGMemoryOverwriteRequestTestFunctionAssertionGuid008,
+                  L"MemoryOverwriteRequestControl - SetVariable() with Attributes == NV variable value remains unchanged",
+                  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 (#108951): https://edk2.groups.io/g/devel/message/108951
Mute This Topic: https://groups.io/mt/101504338/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



  parent reply	other threads:[~2023-09-21 16:37 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 ` Abhimanyu Singh [this message]
2023-09-21 19:03   ` [edk2-devel] [PATCH v2 2/6] uefi-sct/SctPkg: TCG MOR SetVariable Test 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 ` [edk2-devel] [PATCH v2 6/6] uefi-sct/SctPkg: TCG MORLOCK Locked with " Abhimanyu Singh
2023-09-21 19:03   ` 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 2/6] uefi-sct/SctPkg: TCG MOR SetVariable 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-3-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