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

[REBASE && FF] Update Paging Audit File Collection to Defer Free/Allocate Calls, Fix SMM Parsing #450

Merged

Conversation

TaylorBeebe
Copy link
Contributor

@TaylorBeebe TaylorBeebe commented Mar 12, 2024

Description

  1. Remove the Collection of Page Directories: Table entries were being collected but are not used in the paging audit. While they could be used to check heritable attributes, the PDE entries would need to be split by level which makes determining heritability difficult. Instead, FlatPageTableLib can be used in the future to check heritability.
  2. Paging Audit: Update File Collection to Defer Free/Allocate Calls: While collecting platform paging and memory info, freeing and allocating memory will potentially change 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.
  3. FIx SMM Paging Audit: The SMM paging audit needed to be updated to match the improvements made to the DXE audit. This PR reformats the SMM HTML template, updates the HTML template so the memory range object strings match the template naming, fixes the parsing of GDT and IDT entries, adds the platform info data collection

How This Was Tested

Tested on Q35 and SBSA by running the paging audit with various memory protection profiles. The SMM audit was tested on an SMM-enabled Surface platform.

Integration Instructions

N/A

@TaylorBeebe TaylorBeebe changed the title [REBASE && FF] [REBASE && FF] Update Paging Audit File Collection to Defer Free/Allocate Calls Mar 12, 2024
@TaylorBeebe TaylorBeebe force-pushed the paging_audit_driver_updates branch 4 times, most recently from 0a5ff1b to a8b59c2 Compare March 13, 2024 19:28
@codecov-commenter
Copy link

codecov-commenter commented Mar 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 12.11%. Comparing base (f44e20d) to head (a8b59c2).
Report is 1 commits behind head on release/202311.

Additional details and impacted files
@@               Coverage Diff               @@
##           release/202311     #450   +/-   ##
===============================================
  Coverage           12.11%   12.11%           
===============================================
  Files                 110      110           
  Lines               19024    19024           
  Branches             1735     1735           
===============================================
  Hits                 2305     2305           
  Misses              16687    16687           
  Partials               32       32           
Flag Coverage Δ
HidPkg 2.80% <ø> (ø)
MfciPkg 38.51% <ø> (ø)
MsCorePkg 1.43% <ø> (ø)
MsWheaPkg 7.13% <ø> (ø)
XmlSupportPkg 25.30% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TaylorBeebe TaylorBeebe force-pushed the paging_audit_driver_updates branch from a8b59c2 to 300cc77 Compare March 13, 2024 21:28
@TaylorBeebe TaylorBeebe changed the title [REBASE && FF] Update Paging Audit File Collection to Defer Free/Allocate Calls [REBASE && FF] Update Paging Audit File Collection to Defer Free/Allocate Calls, Fix SMM Parsing Mar 18, 2024
@TaylorBeebe TaylorBeebe force-pushed the paging_audit_driver_updates branch from 300cc77 to faf6cd8 Compare March 18, 2024 21:19
@github-actions github-actions bot added the language:python Pull requests that update Python code label Mar 18, 2024
Table entries were being collected but are not used
in the paging audit. While they could be used to
check heritable attributes, the PDE entries would
need to be split by level which makes determining
heritabiliy difficult. Instead, FlatPageTableLib
can be used in the future to check heritability.

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

Integration Instructions

N/A
Description

Instead of having the globals in the driver and the app, move them
to the common file.

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

Integration Instructions

N/A
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
When parsing the x86 page table entries, the physical address
bits value collected is used to mask the page bytes. However,
this is unnecessary and incorrect as currently written.

The physical address bits value should be left shifted by 12 bits
to isolate the physical address bits. Even if we do this, the
masking is unnecessary because the physical address bits are
masked when reading the page table bytes.

- [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.

Tested on an SMM-enabled Surface device.

Integration Instructions

N/A
The SMM paging audit needed to be updated to match the improvements
made to the DXE audit.

This change:

1. Reformats the SMM HTML template
2. Fixes the parsing of GDT and IDT entries
3. Adds the platform info data collection

- [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.

Tested on an SMM-enabled Surface device.

Integration Instructions

N/A
@TaylorBeebe TaylorBeebe force-pushed the paging_audit_driver_updates branch from faf6cd8 to c6617fb Compare March 18, 2024 21:20
@TaylorBeebe TaylorBeebe merged commit cd5daf0 into microsoft:release/202311 Mar 19, 2024
31 checks passed
@TaylorBeebe TaylorBeebe deleted the paging_audit_driver_updates branch March 19, 2024 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language:python Pull requests that update Python code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants