From e4ca465d9175e7b9210bc2c75e5be3e75f89ca37 Mon Sep 17 00:00:00 2001 From: Taylor Beebe <31827475+TaylorBeebe@users.noreply.github.com> Date: Tue, 28 Nov 2023 09:44:39 -0800 Subject: [PATCH] Add Unaccepted Memory Type to Memory Protection Test App (#371) ## Description EDK2 added EfiUnacceptedMemoryType to the memory type list. This update adds this memory type to the memory protection test app and skips it because it is not allocatable. - [x] Impacts functionality? - **Functionality** - Does the change ultimately impact how firmware functions? - Examples: Add a new library, publish a new PPI, update an algorithm, ... - [ ] Impacts security? - **Security** - Does the change have a direct security impact on an application, flow, or firmware? - Examples: Crypto algorithm change, buffer overflow fix, parameter validation improvement, ... - [ ] Breaking change? - **Breaking change** - Will anyone consuming this change experience a break in build or boot behavior? - Examples: Add a new library class, move a module to a different repo, call a function in a new library class in a pre-existing module, ... - [ ] Includes tests? - **Tests** - Does the change include any explicit test code? - Examples: Unit tests, integration tests, robot tests, ... - [ ] Includes documentation? - **Documentation** - Does the change contain explicit documentation additions outside direct code modifications (and comments)? - Examples: Update readme file, add feature readme file, link to documentation on an a separate Web page, ... ## How This Was Tested Tested on Q35 ## Integration Instructions N/A --- .../App/MemoryProtectionTestApp.c | 19 ++++++++++++++----- .../MemoryProtectionTestCommon.h | 4 +++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/UefiTestingPkg/FunctionalSystemTests/MemoryProtectionTest/App/MemoryProtectionTestApp.c b/UefiTestingPkg/FunctionalSystemTests/MemoryProtectionTest/App/MemoryProtectionTestApp.c index 28cb9fa6c1..f96edd7e0b 100644 --- a/UefiTestingPkg/FunctionalSystemTests/MemoryProtectionTest/App/MemoryProtectionTestApp.c +++ b/UefiTestingPkg/FunctionalSystemTests/MemoryProtectionTest/App/MemoryProtectionTestApp.c @@ -117,6 +117,8 @@ GetDxeMemoryTypeSettingFromBitfield ( return HeapGuardMemoryType.Fields.EfiPalCode; case EfiPersistentMemory: return HeapGuardMemoryType.Fields.EfiPersistentMemory; + case EfiUnacceptedMemoryType: + return HeapGuardMemoryType.Fields.EfiUnacceptedMemoryType; default: return FALSE; } @@ -169,6 +171,8 @@ GetMmMemoryTypeSettingFromBitfield ( return HeapGuardMemoryType.Fields.EfiPalCode; case EfiPersistentMemory: return HeapGuardMemoryType.Fields.EfiPersistentMemory; + case EfiUnacceptedMemoryType: + return HeapGuardMemoryType.Fields.EfiUnacceptedMemoryType; default: return FALSE; } @@ -704,7 +708,8 @@ UefiNxProtectionPreReq ( // Skip memory types which cannot be allocated if ((MemoryProtectionContext.TargetMemoryType == EfiConventionalMemory) || - (MemoryProtectionContext.TargetMemoryType == EfiPersistentMemory)) + (MemoryProtectionContext.TargetMemoryType == EfiPersistentMemory) || + (MemoryProtectionContext.TargetMemoryType == EfiUnacceptedMemoryType)) { UT_LOG_WARNING ("Skipping test of memory type %a -- memory type cannot be allocated", MEMORY_TYPES[MemoryProtectionContext.TargetMemoryType]); return UNIT_TEST_SKIPPED; @@ -747,7 +752,8 @@ UefiPageGuardPreReq ( // Skip memory types which cannot be allocated if ((MemoryProtectionContext.TargetMemoryType == EfiConventionalMemory) || - (MemoryProtectionContext.TargetMemoryType == EfiPersistentMemory)) + (MemoryProtectionContext.TargetMemoryType == EfiPersistentMemory) || + (MemoryProtectionContext.TargetMemoryType == EfiUnacceptedMemoryType)) { UT_LOG_WARNING ("Skipping test of memory type %a -- memory type cannot be allocated", MEMORY_TYPES[MemoryProtectionContext.TargetMemoryType]); return UNIT_TEST_SKIPPED; @@ -784,7 +790,8 @@ UefiPoolGuardPreReq ( // Skip memory types which cannot be allocated if ((MemoryProtectionContext.TargetMemoryType == EfiConventionalMemory) || - (MemoryProtectionContext.TargetMemoryType == EfiPersistentMemory)) + (MemoryProtectionContext.TargetMemoryType == EfiPersistentMemory) || + (MemoryProtectionContext.TargetMemoryType == EfiUnacceptedMemoryType)) { UT_LOG_WARNING ("Skipping test of memory type %a -- memory type cannot be allocated", MEMORY_TYPES[MemoryProtectionContext.TargetMemoryType]); return UNIT_TEST_SKIPPED; @@ -865,7 +872,8 @@ SmmPageGuardPreReq ( // Skip memory types which cannot be allocated if ((MemoryProtectionContext.TargetMemoryType == EfiConventionalMemory) || - (MemoryProtectionContext.TargetMemoryType == EfiPersistentMemory)) + (MemoryProtectionContext.TargetMemoryType == EfiPersistentMemory) || + (MemoryProtectionContext.TargetMemoryType == EfiUnacceptedMemoryType)) { UT_LOG_WARNING ("Skipping test of memory type %a -- memory type cannot be allocated", MEMORY_TYPES[MemoryProtectionContext.TargetMemoryType]); return UNIT_TEST_SKIPPED; @@ -902,7 +910,8 @@ SmmPoolGuardPreReq ( // Skip memory types which cannot be allocated if ((MemoryProtectionContext.TargetMemoryType == EfiConventionalMemory) || - (MemoryProtectionContext.TargetMemoryType == EfiPersistentMemory)) + (MemoryProtectionContext.TargetMemoryType == EfiPersistentMemory) || + (MemoryProtectionContext.TargetMemoryType == EfiUnacceptedMemoryType)) { UT_LOG_WARNING ("Skipping test of memory type %a -- memory type cannot be allocated", MEMORY_TYPES[MemoryProtectionContext.TargetMemoryType]); return UNIT_TEST_SKIPPED; diff --git a/UefiTestingPkg/FunctionalSystemTests/MemoryProtectionTest/MemoryProtectionTestCommon.h b/UefiTestingPkg/FunctionalSystemTests/MemoryProtectionTest/MemoryProtectionTestCommon.h index e797b413df..d2249bb1fa 100644 --- a/UefiTestingPkg/FunctionalSystemTests/MemoryProtectionTest/MemoryProtectionTestCommon.h +++ b/UefiTestingPkg/FunctionalSystemTests/MemoryProtectionTest/MemoryProtectionTestCommon.h @@ -16,9 +16,11 @@ CHAR8 *MEMORY_TYPES[] = { "ReservedMemoryType", "LoaderCode", "LoaderData", "BootServicesCode", "BootServicesData", "RuntimeServicesCode", "RuntimeServicesData", "ConventionalMemory", "UnusableMemory", "ACPIReclaimMemory", "ACPIMemoryNVS", "MemoryMappedIO", - "MemoryMappedIOPortSpace", "PalCode", "PersistentMemory" + "MemoryMappedIOPortSpace", "PalCode", "PersistentMemory", "EfiUnacceptedMemoryType" }; +STATIC_ASSERT (EfiMaxMemoryType == ARRAY_SIZE (MEMORY_TYPES), "MEMORY_TYPES array size does not match EfiMaxMemoryType"); + //// // Reset: Test will be run by violating the memory protection policy with the expectation that the system // will reboot each time. The test will take roughly 45 minutes to run with a strict protection policy.