All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] arm64/efi: Clear PTE_WRITE when applying EFI_MEMORY_RO
@ 2026-10-09 15:16 Ard Biesheuvel
  2026-10-12 16:43 ` Catalin Marinas
  0 siblings, 1 reply; 2+ messages in thread
From: Ard Biesheuvel @ 2026-10-09 15:16 UTC (permalink / raw)
  To: linux-efi
  Cc: linux-arm-kernel, mark.rutland, will, catalin.marinas,
	Ard Biesheuvel

From: Ard Biesheuvel <ardb@kernel.org>

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.

Cc: <stable@vger.kernel.org>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 arch/arm64/kernel/efi.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c
index 0ec90fd1754e..6f34aef3d04e 100644
--- a/arch/arm64/kernel/efi.c
+++ b/arch/arm64/kernel/efi.c
@@ -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)
-- 
2.56.0.385.gd3acb90ef8-goog


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

* Re: [PATCH] arm64/efi: Clear PTE_WRITE when applying EFI_MEMORY_RO
  2026-10-09 15:16 [PATCH] arm64/efi: Clear PTE_WRITE when applying EFI_MEMORY_RO Ard Biesheuvel
@ 2026-10-12 16:43 ` Catalin Marinas
  0 siblings, 0 replies; 2+ messages in thread
From: Catalin Marinas @ 2026-10-12 16:43 UTC (permalink / raw)
  To: linux-efi, Ard Biesheuvel
  Cc: Will Deacon, linux-arm-kernel, mark.rutland, Ard Biesheuvel

On Fri, 09 Oct 2026 17:16:01 +0200, Ard Biesheuvel wrote:
> 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.
> 
> [...]

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


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

end of thread, other threads:[~2026-10-12 16:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-09 15:16 [PATCH] arm64/efi: Clear PTE_WRITE when applying EFI_MEMORY_RO Ard Biesheuvel
2026-10-12 16:43 ` Catalin Marinas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.