Skip to content

Commit

Permalink
Paging Audit: Update File Collection to Defer Free/Allocate Calls
Browse files Browse the repository at this point in the history
Description

While collecting platform paging and memory info, freeing and
allocating memory will potentially changed the memory
layout and corrupt the test results. Because allocating and
freeing memory only transitions memory type between
EfiConventionalMemory and EfiBootServicesMemory (which are required
to have the same memory protection policy), this nuance didn't matter
much. However, as the DXE core is updated to support more strict
protections on free memory, this nuance will matter.

This patch updates the data collection routines to calculate and
allocate all required memory before fetching the memory map and
collecting page table data.

- [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, ...
- [x] 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 and SBSA by running the paging audit with various
memory protection profiles.

Integration Instructions

N/A
  • Loading branch information
TaylorBeebe committed Mar 13, 2024
1 parent d20b96a commit 300cc77
Show file tree
Hide file tree
Showing 5 changed files with 1,053 additions and 551 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,21 +202,44 @@ CalculateMaximumSupportAddressBits (
/**
Dump platform specific handler. Created handler(s) need to be compliant with
Windows\PagingReportGenerator.py, i.e. TSEG.
@param[in] AllowAllocation If TRUE, then this function will allocate memory for the
database buffer if it is not large enough to hold the input
string. If FALSE, then this function will return an error
if the database buffer is not large enough to hold the input
string.
@param[out] StringLength The length of the string that was or would have been written
to the memory info database buffer.
@retval EFI_SUCCESS The platform specific info was successfully dumped to
the memory info database buffer.
@retval EFI_OUT_OF_RESOURCES The database buffer is not large enough to hold the
platform specific info and AllowAllocation is FALSE.
@retval EFI_NOT_STARTED The memory info database buffer has not been allocated.
@retval EFI_BUFFER_TOO_SMALL The database buffer is not large enough to hold the
platform specific info and AllowAllocation is FALSE.
@retval EFI_INVALID_PARAMETER StringLength is NULL.
**/
VOID
EFI_STATUS
EFIAPI
DumpProcessorSpecificHandlers (
VOID
IN BOOLEAN AllowAllocation,
OUT UINTN *StringLength
)
{
return;
return EFI_SUCCESS;
}

/**
Dumps platform info required to correctly parse the pages (architecture,
execution level, etc.)
@retval EFI_SUCCESS The platform info was successfully dumped to the associated
data file.
@retval EFI_ABORTED An error occurred while opening the SFS volume.
@retval Others The return value of CreateAndWriteFileSFS()
**/
VOID
EFI_STATUS
EFIAPI
DumpPlatforminfo (
VOID
Expand Down Expand Up @@ -254,5 +277,5 @@ DumpPlatforminfo (
(MemoryAttributeProtocol == NULL) ? "FALSE" : "TRUE"
);

WriteBufferToFile (L"PlatformInfo", TempString, StringIndex);
return WriteBufferToFile (L"PlatformInfo", TempString, StringIndex);
}
Loading

0 comments on commit 300cc77

Please sign in to comment.