summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell King (Oracle) <rmk+kernel@armlinux.org.uk>2022-04-21 16:09:57 +0100
committerRussell King (Oracle) <rmk+kernel@armlinux.org.uk>2024-01-08 12:32:58 +0000
commit4ff1bf11cef5f3a49084cbd94e8a1444665ba024 (patch)
tree3629fa58188f6b3ce0011ebffa43b4547ae70a9d
parent2dea5b4e9b3b039a996cfdcb2a05788cb557fe43 (diff)
arm64: text replication: add sanity checks
The kernel text and modules must be in separate L0 page table entries. Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
-rw-r--r--arch/arm64/mm/ktext.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/arch/arm64/mm/ktext.c b/arch/arm64/mm/ktext.c
index 3a8d37c9abc4..901f159c65e6 100644
--- a/arch/arm64/mm/ktext.c
+++ b/arch/arm64/mm/ktext.c
@@ -3,6 +3,27 @@
* Copyright (C) 2022, Oracle and/or its affiliates.
*/
+#include <linux/kernel.h>
+#include <linux/pgtable.h>
+
+#include <asm/ktext.h>
+#include <asm/memory.h>
+
void __init ktext_replication_init(void)
{
+ int kidx = pgd_index((phys_addr_t)KERNEL_START);
+
+ /*
+ * If we've messed up and the kernel shares a L0 entry with the
+ * module or vmalloc area, then don't even attempt to use text
+ * replication.
+ */
+ if (pgd_index(MODULES_VADDR) == kidx) {
+ pr_warn("Kernel is located in the same L0 index as modules - text replication disabled\n");
+ return;
+ }
+ if (pgd_index(VMALLOC_START) == kidx) {
+ pr_warn("Kernel is located in the same L0 index as vmalloc - text replication disabled\n");
+ return;
+ }
}