public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [RFC PATCH 00/10] Add PPI to manage PEI phase memory attributes
@ 2023-05-25 14:30 Ard Biesheuvel
  2023-05-25 14:30 ` [RFC PATCH 01/10] ArmPkg/ArmMmuLib: Extend API to manage memory permissions better Ard Biesheuvel
                   ` (10 more replies)
  0 siblings, 11 replies; 31+ messages in thread
From: Ard Biesheuvel @ 2023-05-25 14:30 UTC (permalink / raw)
  To: devel
  Cc: Ard Biesheuvel, Ray Ni, Jiewen Yao, Gerd Hoffmann, Taylor Beebe,
	Oliver Smith-Denny, Dandan Bi, Liming Gao, Kinney, Michael D,
	Leif Lindholm, Sunil V L, Andrei Warkentin

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4468

This is a proof-of-concept RFC that implements a PEI phase PPI to manage
memory permission attributes, and wires it up to the PEI image loader so
that shadowed PEIMs as well as the DXE core are remapped with the
appropriate, restricted memory permission attributes before execution.

This means that neither shadowed PEIMs nor the DXE core will ever
execute with writable code regions. It also removes the need on the part
of PEI for memory to be mapped with both writable and executable
permissions by default out of reset. Similar work still needs to be done
to address the early DXE phase (before the CPU arch protocol becomes
available), but once that is out of the way as well, platforms should be
able to map all memory non-executable from the beginning.

This by itself is a major improvement in terms of robustness. It is also
a prerequisite for enabling the WXN MMU control on AArch64, which makes
all writable memory mappings non-executable regardless of the non-exec
page table attribute.

Patches #1 to #4 are prepatory work.
Patch #5 proposes the memory attribute PPI protocol interface.
Patch #6 implements it for ARM and AARCH64.
Patch #7 wires it up into the PEI image loader.
Patches #8 to #10 update the DxeIpl to use this PPI on ARM/AARCH64 for
mapping the stack NX.
instead of an explicit reference to ArmMmuLib. Other architectures
(except IA32/X64) will seamlessly inherit this once they implement the
PPI as well.

Cc: Ray Ni <ray.ni@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Taylor Beebe <t@taylorbeebe.com>
Cc: Oliver Smith-Denny <osd@smith-denny.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: "Kinney, Michael D" <michael.d.kinney@intel.com>
Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Cc: Sunil V L <sunilvl@ventanamicro.com> 
Cc: Andrei Warkentin <andrei.warkentin@intel.com> 

Ard Biesheuvel (10):
  ArmPkg/ArmMmuLib: Extend API to manage memory permissions better
  ArmPkg/CpuDxe: Simplify memory attributes protocol implementation
  ArmPkg/CpuPei: Drop bogus DEPEX on PEI permanent memory
  OvmfPkg/RiscVVirt: Remove unimplemented NxForStack configuration
  MdeModulePkg: Define memory attribute PPI
  ArmPkg/CpuPei: Implement the memory attributes PPI
  MdeModulePkg/PeiCore: Apply restricted permissions in image loader
  MdeModulePkg/DxeIpl: Merge EBC, RISCV64 and LOONGARCH code
  MdeModulePkg/DxeIpl: Use memory attribute PPI to remap the stack NX
  MdeModulePkg/DxeIpl ARM AARCH64: Switch to generic handoff code

 ArmPkg/Drivers/CpuDxe/CpuMmuCommon.c                             |   2 +-
 ArmPkg/Drivers/CpuDxe/MemoryAttribute.c                          |  50 +-----
 ArmPkg/Drivers/CpuPei/CpuPei.c                                   |  78 +++++++++-
 ArmPkg/Drivers/CpuPei/CpuPei.inf                                 |   7 +-
 ArmPkg/Include/Library/ArmMmuLib.h                               |  36 ++++-
 ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c                 |  52 ++++++-
 ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibUpdate.c                   |  88 +++++++++--
 ArmPkg/Library/OpteeLib/Optee.c                                  |   2 +-
 MdeModulePkg/Core/DxeIplPeim/Arm/DxeLoadFunc.c                   |  71 ---------
 MdeModulePkg/Core/DxeIplPeim/{Ebc/DxeLoadFunc.c => DxeHandoff.c} |  31 +++-
 MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf                          |  24 +--
 MdeModulePkg/Core/DxeIplPeim/LoongArch64/DxeLoadFunc.c           |  63 --------
 MdeModulePkg/Core/DxeIplPeim/RiscV64/DxeLoadFunc.c               |  75 ---------
 MdeModulePkg/Core/Pei/Image/Image.c                              | 160 ++++++++++++++++++++
 MdeModulePkg/Core/Pei/PeiMain.h                                  |   6 +
 MdeModulePkg/Core/Pei/PeiMain.inf                                |   1 +
 MdeModulePkg/Include/Ppi/MemoryAttribute.h                       |  78 ++++++++++
 MdeModulePkg/MdeModulePkg.dec                                    |   3 +
 OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc                              |   6 -
 19 files changed, 523 insertions(+), 310 deletions(-)
 delete mode 100644 MdeModulePkg/Core/DxeIplPeim/Arm/DxeLoadFunc.c
 rename MdeModulePkg/Core/DxeIplPeim/{Ebc/DxeLoadFunc.c => DxeHandoff.c} (62%)
 delete mode 100644 MdeModulePkg/Core/DxeIplPeim/LoongArch64/DxeLoadFunc.c
 delete mode 100644 MdeModulePkg/Core/DxeIplPeim/RiscV64/DxeLoadFunc.c
 create mode 100644 MdeModulePkg/Include/Ppi/MemoryAttribute.h

-- 
2.39.2


^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2023-05-31 21:01 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-25 14:30 [RFC PATCH 00/10] Add PPI to manage PEI phase memory attributes Ard Biesheuvel
2023-05-25 14:30 ` [RFC PATCH 01/10] ArmPkg/ArmMmuLib: Extend API to manage memory permissions better Ard Biesheuvel
2023-05-25 14:30 ` [RFC PATCH 02/10] ArmPkg/CpuDxe: Simplify memory attributes protocol implementation Ard Biesheuvel
2023-05-25 14:30 ` [RFC PATCH 03/10] ArmPkg/CpuPei: Drop bogus DEPEX on PEI permanent memory Ard Biesheuvel
2023-05-25 14:30 ` [RFC PATCH 04/10] OvmfPkg/RiscVVirt: Remove unimplemented NxForStack configuration Ard Biesheuvel
2023-05-29 12:50   ` Sunil V L
2023-05-25 14:30 ` [RFC PATCH 05/10] MdeModulePkg: Define memory attribute PPI Ard Biesheuvel
2023-05-30  7:15   ` Ni, Ray
2023-05-30  7:32     ` Ard Biesheuvel
2023-05-31  7:33       ` Ni, Ray
2023-05-31  7:53         ` Ard Biesheuvel
2023-05-31  8:56           ` [edk2-devel] " Ni, Ray
2023-05-31  9:24             ` Ard Biesheuvel
2023-05-25 14:30 ` [RFC PATCH 06/10] ArmPkg/CpuPei: Implement the memory attributes PPI Ard Biesheuvel
2023-05-25 14:30 ` [RFC PATCH 07/10] MdeModulePkg/PeiCore: Apply restricted permissions in image loader Ard Biesheuvel
2023-05-25 17:21   ` [edk2-devel] " Oliver Smith-Denny
2023-05-25 21:29     ` Ard Biesheuvel
2023-05-30 16:51       ` Oliver Smith-Denny
2023-05-30 20:51         ` Ard Biesheuvel
2023-05-25 14:30 ` [RFC PATCH 08/10] MdeModulePkg/DxeIpl: Merge EBC, RISCV64 and LOONGARCH code Ard Biesheuvel
2023-05-25 14:30 ` [RFC PATCH 09/10] MdeModulePkg/DxeIpl: Use memory attribute PPI to remap the stack NX Ard Biesheuvel
2023-05-30  7:19   ` Ni, Ray
2023-05-30 10:25     ` duntan
2023-05-30 12:51       ` Ard Biesheuvel
2023-05-31  7:22         ` Gerd Hoffmann
2023-05-31  1:29       ` Ni, Ray
2023-05-31 19:03         ` [edk2-devel] " Lendacky, Thomas
2023-05-31 21:01           ` Ard Biesheuvel
2023-05-25 14:30 ` [RFC PATCH 10/10] MdeModulePkg/DxeIpl ARM AARCH64: Switch to generic handoff code Ard Biesheuvel
2023-05-25 17:20 ` [edk2-devel] [RFC PATCH 00/10] Add PPI to manage PEI phase memory attributes Oliver Smith-Denny
2023-05-25 21:43   ` Ard Biesheuvel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox