[RFC PATCH v2 2/3] arm64/mm: make pages read-only in the linear map
Xueyuan Chen
xueyuan.chen21 at gmail.com
Tue Jun 9 07:38:00 PDT 2026
Implement arch_make_pages_readonly() for arm64. Make the corresponding
linear-map range read-only so unexpected writes fault instead of
corrupting shared contents.
Respect can_set_direct_map() before touching the linear map. If arm64
cannot safely update the linear map at page granularity, leave the mapping
unchanged.
Co-developed-by: Lance Yang <lance.yang at linux.dev>
Signed-off-by: Lance Yang <lance.yang at linux.dev>
Signed-off-by: Xueyuan Chen <xueyuan.chen21 at gmail.com>
---
arch/arm64/mm/pageattr.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c
index ce035e1b4eaf..da97ec7d5195 100644
--- a/arch/arm64/mm/pageattr.c
+++ b/arch/arm64/mm/pageattr.c
@@ -3,6 +3,7 @@
* Copyright (c) 2014, The Linux Foundation. All rights reserved.
*/
#include <linux/kernel.h>
+#include <linux/init.h>
#include <linux/mm.h>
#include <linux/module.h>
#include <linux/mem_encrypt.h>
@@ -147,6 +148,18 @@ static int __change_memory_common(unsigned long start, unsigned long size,
return ret;
}
+bool arch_make_pages_readonly(struct page *page, int nr_pages)
+{
+ unsigned long addr = (unsigned long)page_address(page);
+
+ if (!can_set_direct_map())
+ return false;
+
+ return !__change_memory_common(addr, PAGE_SIZE * nr_pages,
+ __pgprot(PTE_RDONLY),
+ __pgprot(PTE_WRITE));
+}
+
static int change_memory_common(unsigned long addr, int numpages,
pgprot_t set_mask, pgprot_t clear_mask)
{
--
2.47.3
More information about the linux-arm-kernel
mailing list