summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell King (Oracle) <rmk+kernel@armlinux.org.uk>2022-05-27 13:27:19 +0100
committerRussell King (Oracle) <rmk+kernel@armlinux.org.uk>2023-10-30 12:56:16 +0000
commitacc97daf225267c7a6123f845cf36f24ec5a49f3 (patch)
tree7709b370511663eeaf74f1c89949b2f2da4f39f7
parent0b0a9f1236df10a6e4539872da60ad7932904201 (diff)
arm64: text replication: verify kernel textktext
Verify that the replicated kernel image for the non-boot nodes matches the boot kernel image, and report differences found. This ensures that the non-boot modes are running an identical copy of the kernel. Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
-rw-r--r--arch/arm64/mm/ktext.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/arch/arm64/mm/ktext.c b/arch/arm64/mm/ktext.c
index d29497c37da9..d9d7c0bb064d 100644
--- a/arch/arm64/mm/ktext.c
+++ b/arch/arm64/mm/ktext.c
@@ -124,6 +124,43 @@ void ktext_replication_patch_alternative(__le32 *src, int nr_inst)
}
}
+static int __init ktext_replication_check(void)
+{
+ size_t size = _etext - _stext;
+ int nid;
+
+ preempt_disable();
+ pr_info("CPU%u: Checking ktext replication\n", smp_processor_id());
+
+ for_each_node(nid) {
+ if (!kernel_texts[nid])
+ continue;
+
+ if (memcmp(_stext, kernel_texts[nid], size)) {
+ u32 *st, *kt;
+ size_t i, n;
+
+ pr_err("NID%u: kernel text disagreement\n", nid);
+
+ st = (u32 *)_stext;
+ kt = kernel_texts[nid];
+ for (i = n = 0; i < size / 4; i ++) {
+ if (st[i] != kt[i]) {
+ pr_err("Offset 0x%zx: 0x%08x != 0x%08x\n",
+ i * 4, st[i], kt[i]);
+ if (n++ > 8)
+ break;
+ }
+ }
+ }
+ }
+ preempt_enable();
+
+ return 0;
+}
+late_initcall(ktext_replication_check);
+
+
static bool ktext_enabled = IS_ENABLED(CONFIG_REPLICATE_KTEXT_DEFAULT);
static int __init parse_ktext(char *str)