Reporting Issues
Bug 3326 - Enforce W^X design principles
Summary: Enforce W^X design principles
Status: UNCONFIRMED
Alias: None
Product: Tianocore Feature Requests
Classification: Unclassified
Component: Code (show other bugs)
Version: Current
Hardware: All All
: Lowest normal
Assignee: Marvin Häuser
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-04-12 10:42 UTC by Marvin Häuser
Modified: 2021-12-08 03:12 UTC (History)
6 users (show)

See Also:
EDK II Code First industry standard specifications: ---
Branch URL:
Release(s) the issue is observed: EDK II Master
The OS the target platform is running: ---
Package: N/A
Release(s) the issues must be fixed: EDK II Master
Tianocore documents:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marvin Häuser 2021-04-12 10:42:15 UTC
If feasible as to time and effort, I would like to introduce W^X execution to EDK II DXE. Even if this cannot happen short-term, the design should be embraced anyway to increase code security and reliability. The W^X principle allows for tighter memory permissions and more effective guarding of memory, for both debug and production.

Data should be copied to *Code memory if and only if it's instructions that can be directly executed by the host CPU, and any other data in the regions should either be 0 (common default) or an architecture-specific value to ensure safe execution even when the padding is executed (e.g. 0xCC for x86 architectures, which is INT3). Similarly, a page should be executable if and only if it currently contains "live code" that fits the previous description.

This most notably disallows storing data together with code on the same page, which unfortunately is common practice right now[1][2] (not comprehensive).

[1] https://github.com/tianocore/edk2/blob/2072c22a0d63c780b0cc6377f6d4ffb116ad6144/UefiCpuPkg/Library/MpInitLib/MpLib.c#L1200-L1203

[2] https://github.com/tianocore/edk2/blob/2072c22a0d63c780b0cc6377f6d4ffb116ad6144/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchInterruptDefs.h#L37
Comment 1 gaoliming 2021-04-13 21:55:13 UTC
Marvin, you can continue to provide the proposal.
Comment 2 gaoliming 2021-12-07 21:50:07 UTC
Marvin: current edk2 has enabled the protection for runtime and smm modules. This protection can also be applied for DXE module.
Comment 3 Marvin Häuser 2021-12-08 03:12:40 UTC
The problem is not the protection infrastructure, but data separation - please refer to [1] and [2] as suiting but non-comprehensive examples. Only once all these issues have been fixed, protection can be reliably enabled. It will then also need PCD toggles to loosen the policies for third-party code (OpROMs and boot loaders), to not unintentionally break compatibility.