Commit d29736d3 authored by Ye Bin's avatar Ye Bin Committed by Felix Fu
Browse files

arm32: kaslr: print kaslr offset when kernel panic

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I8KNA9


CVE: NA

-------------------------------------------------

Signed-off-by: default avatarYe Bin <yebin10@huawei.com>
Signed-off-by: default avatarCui GaoSheng <cuigaosheng1@huawei.com>

Conflicts:
    Merge OLK-5.10 fix patch f59d4739

Signed-off-by: default avatarFelix Fu <fuzhen5@huawei.com>
parent 365a456a
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -171,6 +171,20 @@ extern unsigned long vectors_base;
extern u64 kernel_sec_start;
extern u64 kernel_sec_end;

#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
+3 −3
Original line number Diff line number Diff line
@@ -119,11 +119,11 @@ ENTRY(stext)
#ifdef CONFIG_RANDOMIZE_BASE
	str_l	r3, __kaslr_offset, r9	@ offset in r3 if entered via kaslr ep

	.section ".bss", "aw", %nobits
	.pushsection .data		@ data in bss will be cleared
	.align	2
__kaslr_offset:
ENTRY(__kaslr_offset)
	.long	0			@ will be wiped before entering C code
	.previous
	.popsection
#endif

#ifdef CONFIG_ARM_VIRT_EXT
+31 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@
#include <asm/memblock.h>
#include <asm/virt.h>
#include <asm/kasan.h>
#include <linux/panic_notifier.h>

#include "atags.h"

@@ -1359,3 +1360,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);