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

[CHERRY-PICK] [REBASE & FF] Revert Mu Commit in Favor of edk2 Commit #281

Merged
merged 2 commits into from
Oct 1, 2024

Conversation

os-d
Copy link
Contributor

@os-d os-d commented Aug 31, 2024

Description

This reverts a Mu commit that has been upstreamed in favor of the corresponding edk2 commit.

  • Impacts functionality?
  • Impacts security?
  • Breaking change?
  • Includes tests?
  • Includes documentation?

How This Was Tested

N/A.

Integration Instructions

N/A.

@os-d os-d requested review from makubacki, kuqin12 and apop5 August 31, 2024 17:38
@github-actions github-actions bot added the impact:non-functional Does not have a functional impact label Aug 31, 2024
os-d added 2 commits October 1, 2024 14:37
This reverts commit fb49fe6, as it has
been upstreamed to edk2 as 662272e.
On AARCH64 systems, the GCD is not fully synced with the page table. On
x86 systems, the GCD is synced by adding `EFI_MEMORY_RO`,
`EFI_MEMORY_RP`, and `EFI_MEMORY_XP` to the current capabilities of the
GCD, then the page table attributes are set on the GCD attributes.

However, on AARCH64, the GCD capabilities do not get updated, instead
only the attributes from the page table are masked by the existing GCD
capabilities, which means that any new page table attribute which are
already set are dropped and the GCD does not reflect the state of the
system. This has been seen to cause issues where memory in the page
table that was marked `EFI_MEMORY_XP` had an additional attribute set
using the GCD capabilities, which did not include `EFI_MEMORY_XP`, this
caused the page table to be updated to lose `EFI_MEMORY_XP`, which is a
potential security issue.

The existing behavior on AARCH64 systems is an implementation error, it
assumes one of two things:
- The page table attributes must be a subset of the GCD capabilities
- The GCD does not need to have its capabilities synced to what the page
table attributes are

The first is incorrect as important attributes such as `EFI_MEMORY_XP`
do not get applied to the GCD capabilities by default and therefore must
be synced back. This comment from ArmPkg's CpuDxe driver helps explain:

```c
  // The GCD implementation maintains its own copy of the state of memory
  // space attributes.  GCD needs to know what the initial memory space
  // attributes are.  The CPU Arch. Protocol does not provide a
  // GetMemoryAttributes function for GCD to get this so we must resort to
  // calling GCD (as if we were a client) to update its copy of the
  // attributes.  This is bad architecture and should be replaced with a
  // way for GCD to query the CPU Arch. driver of the existing memory
  // space attributes instead.
```

However, this comment misses that updating the capabilities is critical
to updating the attributes.

The second is incorrect because significant pieces of core code
reference the GCD attributes instead of the page table attributes. For
example, NonDiscoverablePciDeviceDxe uses the GCD capabilities and
attributes when interacting with a non-discoverable PCI device. When the
GCD is not synced to the page table, we get the errors and security
concerns listed above.

Signed-off-by: Oliver Smith-Denny <[email protected]>
@os-d os-d enabled auto-merge (rebase) October 1, 2024 21:37
@os-d os-d merged commit 0890650 into release/202405 Oct 1, 2024
9 checks passed
@os-d os-d deleted the 2405_cps_gcd branch October 1, 2024 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impact:non-functional Does not have a functional impact
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants