arm64/efi: Clear PTE_WRITE when applying EFI_MEMORY_RO
PATCH 1/1 arm64/efi: Clear PTE_WRITE when applying EFI_MEMORY_RO
From: Ard Biesheuvel <[email protected]>
set_permissions() sets PTE_RDONLY for regions that the Memory Attributes Table describes as read-only, but leaves PTE_WRITE set. PTE_WRITE is the DBM bit, so when hardware dirty state management is enabled (TCR_EL1.HD), such a descriptor is writable-clean rather than read-only, and a write by the firmware will be permitted by the hardware (which marks the entry dirty) instead of faulting.
Clear PTE_WRITE as well, as pte_wrprotect() does.
--- arch/arm64/kernel/efi.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
arch/arm64/kernel/efi.c +7 -1
@@ -117,8 +117,14 @@ static int __init set_permissions(pte_t *ptep, unsigned long addr, void *data)const efi_memory_desc_t *md = spd->md;pte_t pte =__ptep_get (ptep); +/* +* Clear PTE_WRITE as well: it doubles as the DBM bit, and leaving it +* set would permit the hardware to make the mapping writable again +* when TCR_EL1.HD is set. +*/ if (md->attribute &EFI_MEMORY_RO ) - pte =set_pte_bit (pte,__pgprot (PTE_RDONLY )); + pte =set_pte_bit (clear_pte_bit (pte,__pgprot (PTE_WRITE )), +__pgprot (PTE_RDONLY ));if (md->attribute &EFI_MEMORY_XP ) pte =set_pte_bit (pte,__pgprot (PTE_PXN ));else if (system_supports_bti_kernel () && spd->has_bti)
Signature · 1 line
2.56.0.385.gd3acb90ef8-goog
Quoted 8 lines · Ard Biesheuvel
set_permissions()setsPTE_RDONLYfor regions that the Memory Attributes Table describes as read-only, but leavesPTE_WRITEset.PTE_WRITEis the DBM bit, so when hardware dirty state management is enabled (TCR_EL1.HD), such a descriptor is writable-clean rather than read-only, and a write by the firmware will be permitted by the hardware (which marks the entry dirty) instead of faulting.[...]
Applied to arm64 (for-next/efi), thanks!
[1/1] arm64/efi: Clear PTE_WRITE when applying EFI_MEMORY_RO
https://git.kernel.org/arm64/c/215d7b662273