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

[CI Check] ArmPkg: CpuDxe: Sync GCD Capabilities With Page Table Attributes #4311

Closed

Conversation

os-d
Copy link

@os-d os-d commented Apr 25, 2023

When ArmPkg's CpuDxe driver initializes, it attempts to sync the GCD with the page table. However, unlike when the UefiCpuPkg's CpuDxe initializes, the Arm version does not update the GCD capabilities with EFI_MEMORY_[RO|RP|XP] (this could also set the capabilities to be the existing page table attributes for this range, but the UefiCpuPkg CpuDxe sets the above attributes as they are software constructs, possible to set for any memory hardware).

As a result, when the GCD attributes are attempted to be set against the old GCD capabilities, attributes that are set in the page table can get lost because the new attributes are not in the old GCD capabilities (and yet they are already set in the page table) meaning that the attempted sync between the GCD and the page table was a failure and drivers querying one vs the other will see different state. This can lead to RWX memory regions even with the no-execute policy set, because core drivers (such as NonDiscoverablePciDeviceIo, to be fixed up in a later patchset) allocate pages, query the GCD attributes, attempt to set a new cache attribute and end up clearing the XP bit in the page table because the GCD attributes do not have XP set.

This patch follows the UefiCpuPkg pattern and adds EFI_MEMORY_[RO|RP|XP] to the GCD capabilities during CpuDxe initialization. This ensures that memory regions which already have these attributes set get them set in the GCD attributes, properly syncing between the GCD and the page table.

This mitigates the issue seen, however, additional investigations into setting the GCD attributes earlier and maintaining a better sync between the GCD and the page table are being done.

Feedback on this proposal is greatly appreciated, particularly any pitfalls or more architectural solutions to issues seen with syncing the GCD and the page table.

Cc: Leif Lindholm quic_llindhol@quicinc.com
Cc: Ard Biesheuvel ardb+tianocore@kernel.org
Cc: Sami Mujawar sami.mujawar@arm.com
Cc: Michael Kubacki mikuback@linux.microsoft.com
Cc: Sean Brogan sean.brogan@microsoft.com

When ArmPkg's CpuDxe driver initializes, it attempts to sync the
GCD with the page table. However, unlike when the UefiCpuPkg's
CpuDxe initializes, the Arm version does not update the GCD
capabilities with EFI_MEMORY_[RO|RP|XP] (this could also set
the capabilities to be the existing page table attributes for
this range, but the UefiCpuPkg CpuDxe sets the above attributes
as they are software constructs, possible to set for any memory
hardware).

As a result, when the GCD attributes are attempted to be set
against the old GCD capabilities, attributes that are set in the
page table can get lost because the new attributes are not in the
old GCD capabilities (and yet they are already set in the page
table) meaning that the attempted sync between the GCD and the
page table was a failure and drivers querying one vs the other
will see different state. This can lead to RWX memory regions
even with the no-execute policy set, because core drivers (such
as NonDiscoverablePciDeviceIo, to be fixed up in a later patchset)
allocate pages, query the GCD attributes, attempt to set a new
cache attribute and end up clearing the XP bit in the page table
because the GCD attributes do not have XP set.

This patch follows the UefiCpuPkg pattern and adds
EFI_MEMORY_[RO|RP|XP] to the GCD capabilities during CpuDxe
initialization. This ensures that memory regions which already have
these attributes set get them set in the GCD attributes, properly
syncing between the GCD and the page table.

This mitigates the issue seen, however, additional investigations
into setting the GCD attributes earlier and maintaining a better
sync between the GCD and the page table are being done.

Feedback on this proposal is greatly appreciated, particularly
any pitfalls or more architectural solutions to issues seen
with syncing the GCD and the page table.

Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Cc: Michael Kubacki <mikuback@linux.microsoft.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>

Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
@os-d os-d force-pushed the osde/sync_aarch64_gcd_capabilities_v1 branch from 6df64e9 to fcf0d9f Compare April 25, 2023 22:57
@os-d os-d closed this Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant