Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix buffer overflow when merging guard pages in MergeMemoryMap #126

Merged
merged 4 commits into from
Nov 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,17 @@ MergeMemoryMap (
NewMemoryMapEntry = MemoryMap;
MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap + *MemoryMapSize);
while ((UINTN)MemoryMapEntry < (UINTN)MemoryMapEnd) {
CopyMem (NewMemoryMapEntry, MemoryMapEntry, sizeof (EFI_MEMORY_DESCRIPTOR));
CopyMem (NewMemoryMapEntry, MemoryMapEntry, DescriptorSize); // MU_CHANGE Use size parameter for consistency.
NextMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
cfernald marked this conversation as resolved.
Show resolved Hide resolved

do {
MergeGuardPages (NewMemoryMapEntry, NextMemoryMapEntry->PhysicalStart);
// MU_CHANGE START Fix overflow in the MergeGuardPages call.
if ((UINTN)NextMemoryMapEntry < (UINTN)MemoryMapEnd) {
MergeGuardPages (NewMemoryMapEntry, NextMemoryMapEntry->PhysicalStart);
}

// MU_CHANGE END

MemoryBlockLength = (UINT64)(EfiPagesToSize (NewMemoryMapEntry->NumberOfPages));
if (((UINTN)NextMemoryMapEntry < (UINTN)MemoryMapEnd) &&
(NewMemoryMapEntry->Type == NextMemoryMapEntry->Type) &&
Expand Down