edk2 icon indicating copy to clipboard operation
edk2 copied to clipboard

MdeModulePkg NonDiscoverablePciDeviceIo: MMIO Memory XP By Default

Open apop5 opened this issue 1 year ago • 4 comments

Description

When allocating memory for a non-discoverable PCI device's IO, the current core code removes the XP attribute, allowing code to execute from that region. This is a security vulnerability and unneeded. This change updates to mark the region as XP when allocating memory for the non-discoverable PCI device.

These allocations in this function are limited to EfiBootServicesData and EfiRuntimeServicesData, which we expect to be XP.

  • [ ] Breaking change?
    • Breaking change - Does this PR cause a break in build or boot behavior?
    • Examples: Does it add a new library class or move a module to a different repo.
  • [ ] Impacts security?
    • Security - Does this PR have a direct security impact?
    • Examples: Crypto algorithm change or buffer overflow fix.
  • [ ] Includes tests?
    • Tests - Does this PR include any explicit test code?
    • Examples: Unit tests or integration tests.

How This Was Tested

Tested on QEMU and a physical platform.

Integration Instructions

N/A

apop5 avatar Aug 02 '24 01:08 apop5

I agree this change is correct. Do you find any impact on the real platform?

lgao4 avatar Aug 04 '24 06:08 lgao4

I agree this change is correct. Do you find any impact on the real platform?

@os-d pointed out that this needs another changed, based on #5944 and the fix up in #5999.

On a real platform, there is no visible changes aside from the generated Paging Audit Report looking better because there are less regions with RWX.

apop5 avatar Aug 04 '24 14:08 apop5

To add to @apop5's statement, there is an impact on physical systems with this change, the MMIO allocated by this driver is not mapped executable any longer which fixes a security risk. Prior to this change, the MMIO regions allocated here would overwrite the attributes and make the region RWX.

os-d avatar Aug 04 '24 16:08 os-d

This should be ready.

apop5 avatar Aug 14 '24 20:08 apop5