From: Ye Bin
ohos inclusion
category: feature
feature: ARM kaslr support
issue: #I3ZXZF
CVE: NA
-------------------------------------------------
Signed-off-by: Ye Bin
Reviewed-by: Jason Yan
Signed-off-by: yangerkun
Signed-off-by: Cui GaoSheng
Reviewed-by: Xiu Jianfeng
Signed-off-by: Chen Jun
Signed-off-by: Yu Changchun
---
arch/arm/include/asm/memory.h | 14 ++++++++++++++
arch/arm/kernel/head.S | 2 +-
arch/arm/kernel/setup.c | 30 ++++++++++++++++++++++++++++++
3 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
index 2f841cb65c30..a7a22bf5ca7e 100644
--- a/arch/arm/include/asm/memory.h
+++ b/arch/arm/include/asm/memory.h
@@ -167,6 +167,20 @@ extern unsigned long vectors_base;
#ifndef __ASSEMBLY__
+#ifdef CONFIG_RANDOMIZE_BASE
+extern unsigned long __kaslr_offset;
+
+static inline unsigned long kaslr_offset(void)
+{
+ return __kaslr_offset;
+}
+#else
+static inline unsigned long kaslr_offset(void)
+{
+ return 0;
+}
+#endif
+
/*
* Physical vs virtual RAM address space conversion. These are
* private definitions which should NOT be used outside memory.h
diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
index 26f3e9a0ffe9..b6b82387289b 100644
--- a/arch/arm/kernel/head.S
+++ b/arch/arm/kernel/head.S
@@ -105,7 +105,7 @@ ENTRY(stext)
.section ".bss", "aw", %nobits
.align 2
-__kaslr_offset:
+ENTRY(__kaslr_offset)
.long 0 @ will be wiped before entering C code
.previous
#endif
diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
index d32f7652a5bf..e37ebb7f1b0b 100644
--- a/arch/arm/kernel/setup.c
+++ b/arch/arm/kernel/setup.c
@@ -1338,3 +1338,33 @@ const struct seq_operations cpuinfo_op = {
.stop = c_stop,
.show = c_show
};
+
+/*
+ * Dump out kernel offset information on panic.
+ */
+static int dump_kernel_offset(struct notifier_block *self, unsigned long v,
+ void *p)
+{
+ const unsigned long offset = kaslr_offset();
+
+ if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && offset > 0) {
+ pr_emerg("Kernel Offset: 0x%lx from 0x%lx\n",
+ offset, PAGE_OFFSET);
+
+ } else {
+ pr_emerg("Kernel Offset: disabled\n");
+ }
+ return 0;
+}
+
+static struct notifier_block kernel_offset_notifier = {
+ .notifier_call = dump_kernel_offset
+};
+
+static int __init register_kernel_offset_dumper(void)
+{
+ atomic_notifier_chain_register(&panic_notifier_list,
+ &kernel_offset_notifier);
+ return 0;
+}
+__initcall(register_kernel_offset_dumper);
--
2.22.0