UefiTestingPkg: Fix memory info database dump - #925
Merged
makubacki merged 1 commit intoJul 24, 2026
Conversation
Fixes: microsoft#924 Memory info is stored in `mMemoryInfoDatabaseBuffer`. The code first calculates how large of a buffer is needed. A "dry run" is performed to compute that. It calls each dump handler with `AllowAllocation=FALSE`, to get the size of the data that would be written. However, the call to `LoadedImageTableDump()` during this phase, seets `AllowAllocation=TRUE`. `mMemoryInfoDatabaseOffset` is still `NULL`, then `AppendMemoryInfoDatabase()` sees that and allocates a buffer. Now, `mMemoryInfoDatabaseSize` is advanced. Other dump handlers after write to the buffer now that it exists. Eventually, `DumpPagingInfo()` allocates the real (intended) buffer. Because of what happened earlier, the "accidental" buffer is leaked and `mMemoryInfoDatabaseSize` is non-zero which causes `mMemoryInfoDatabaseBuffer[mMemoryInfoDatabaseSize]` to write past the beginning of the buffer: ```c // Copy the new string to the end of the buffer and update the size. if (!EFI_ERROR (Status)) { CopyMem (&mMemoryInfoDatabaseBuffer[mMemoryInfoDatabaseSize], DatabaseString, NewStringSize); mMemoryInfoDatabaseSize = NewDatabaseSize; } ``` This change sets `AllowAllocation=FALSE` in that call and resets `mMemoryInfoDatabaseSize` to zero before the real allocation as a precaution. Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Contributor
✅ QEMU Validation PassedSource Dependencies
Results
Workflow run: https://github.com/microsoft/mu_plus/actions/runs/30105774308 This comment was automatically generated by the Mu QEMU PR Validation workflow. |
apop5
approved these changes
Jul 24, 2026
os-d
approved these changes
Jul 24, 2026
os-d
approved these changes
Jul 24, 2026
kuqin12
approved these changes
Jul 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes: #924
Memory info is stored in
mMemoryInfoDatabaseBuffer. The code first calculates how large of a buffer is needed. A "dry run" is performed to compute that. It calls each dump handler withAllowAllocation=FALSE, to get the size of the data that would be written.However, the call to
LoadedImageTableDump()during this phase, setsAllowAllocation=TRUE.mMemoryInfoDatabaseOffsetis stillNULL, thenAppendMemoryInfoDatabase()sees that and allocates a buffer.Now,
mMemoryInfoDatabaseSizeis advanced. Other dump handlers after write to the buffer now that it exists.Eventually,
DumpPagingInfo()allocates the real (intended) buffer. Because of what happened earlier, the "accidental" buffer is leaked andmMemoryInfoDatabaseSizeis non-zero which causesmMemoryInfoDatabaseBuffer[mMemoryInfoDatabaseSize]to write past the beginning of the buffer:This change sets
AllowAllocation=FALSEin that call and resetsmMemoryInfoDatabaseSizeto zero before the real allocation as a precaution.How This Was Tested
Before - Reproduce the problem:
After - Verify the problem no longer exists:
Integration Instructions