Skip to content

Commit

Permalink
Return if Allocation Fails When Manipulating Guarded Memory Map
Browse files Browse the repository at this point in the history
Description

This PR updates a set of ASSERTs checking if memory was successfully
allocated to branch if the allocation failed in addition to ASSERTing.

- [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 by booting Q35 to shell

Integration Instructions

N/A
  • Loading branch information
TaylorBeebe authored and os-d committed Jun 28, 2024
1 parent 87454f8 commit 7de570c
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions MdeModulePkg/Core/Dxe/Mem/HeapGuard.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,14 @@ FindGuardedMemoryMap (
&MapMemory,
FALSE
);
ASSERT_EFI_ERROR (Status);
ASSERT (MapMemory != 0);
// MU_CHANGE START: Check if memory was successfully allocated
if (EFI_ERROR (Status) || (MapMemory == 0)) {
ASSERT_EFI_ERROR (Status);
ASSERT (MapMemory != 0);
return 0;
}

// MU_CHANGE END
// MU_CHANGE START: Apply Protection policy to the allocated memory
ApplyMemoryProtectionPolicy (
EfiConventionalMemory,
Expand Down Expand Up @@ -291,8 +297,14 @@ FindGuardedMemoryMap (
&MapMemory,
FALSE
);
ASSERT_EFI_ERROR (Status);
ASSERT (MapMemory != 0);
// MU_CHANGE START: Check if memory was successfully allocated
if (EFI_ERROR (Status) || (MapMemory == 0)) {
ASSERT_EFI_ERROR (Status);
ASSERT (MapMemory != 0);
return 0;
}

// MU_CHANGE END
// MU_CHANGE START: Apply Protection policy to the allocated memory
ApplyMemoryProtectionPolicy (
EfiConventionalMemory,
Expand Down

0 comments on commit 7de570c

Please sign in to comment.