Commit 4545c898 authored by Jiri Kosina's avatar Jiri Kosina

x86: introduce kaslr_offset()

Offset that has been chosen for kaslr during kernel decompression can be
easily computed as a difference between _text and __START_KERNEL. We are
already making use of this in dump_kernel_offset() notifier and in
arch_crash_save_vmcoreinfo().

Introduce kaslr_offset() that makes this computation instead of hard-coding
it, so that other kernel code (such as live patching) can make use of it.
Also convert existing users to make use of it.

This patch is equivalent transofrmation without any effects on the resulting
code:

	$ diff -u vmlinux.old.asm vmlinux.new.asm
	--- vmlinux.old.asm     2015-04-28 17:55:19.520983368 +0200
	+++ vmlinux.new.asm     2015-04-28 17:55:24.141206072 +0200
	@@ -1,5 +1,5 @@

	-vmlinux.old:     file format elf64-x86-64
	+vmlinux.new:     file format elf64-x86-64

	Disassembly of section .text:
	$
Acked-by: default avatarBorislav Petkov <bp@suse.de>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent 9497d738
...@@ -65,12 +65,18 @@ static inline void x86_ce4100_early_setup(void) { } ...@@ -65,12 +65,18 @@ static inline void x86_ce4100_early_setup(void) { }
* This is set up by the setup-routine at boot-time * This is set up by the setup-routine at boot-time
*/ */
extern struct boot_params boot_params; extern struct boot_params boot_params;
extern char _text[];
static inline bool kaslr_enabled(void) static inline bool kaslr_enabled(void)
{ {
return !!(boot_params.hdr.loadflags & KASLR_FLAG); return !!(boot_params.hdr.loadflags & KASLR_FLAG);
} }
static inline unsigned long kaslr_offset(void)
{
return (unsigned long)&_text - __START_KERNEL;
}
/* /*
* Do NOT EVER look at the BIOS memory size location. * Do NOT EVER look at the BIOS memory size location.
* It does not work on many machines. * It does not work on many machines.
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <asm/io_apic.h> #include <asm/io_apic.h>
#include <asm/debugreg.h> #include <asm/debugreg.h>
#include <asm/kexec-bzimage64.h> #include <asm/kexec-bzimage64.h>
#include <asm/setup.h>
#ifdef CONFIG_KEXEC_FILE #ifdef CONFIG_KEXEC_FILE
static struct kexec_file_ops *kexec_file_loaders[] = { static struct kexec_file_ops *kexec_file_loaders[] = {
...@@ -334,7 +335,7 @@ void arch_crash_save_vmcoreinfo(void) ...@@ -334,7 +335,7 @@ void arch_crash_save_vmcoreinfo(void)
VMCOREINFO_LENGTH(node_data, MAX_NUMNODES); VMCOREINFO_LENGTH(node_data, MAX_NUMNODES);
#endif #endif
vmcoreinfo_append_str("KERNELOFFSET=%lx\n", vmcoreinfo_append_str("KERNELOFFSET=%lx\n",
(unsigned long)&_text - __START_KERNEL); kaslr_offset());
} }
/* arch-dependent functionality related to kexec file-based syscall */ /* arch-dependent functionality related to kexec file-based syscall */
......
...@@ -834,7 +834,7 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p) ...@@ -834,7 +834,7 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
{ {
if (kaslr_enabled()) { if (kaslr_enabled()) {
pr_emerg("Kernel Offset: 0x%lx from 0x%lx (relocation range: 0x%lx-0x%lx)\n", pr_emerg("Kernel Offset: 0x%lx from 0x%lx (relocation range: 0x%lx-0x%lx)\n",
(unsigned long)&_text - __START_KERNEL, kaslr_offset(),
__START_KERNEL, __START_KERNEL,
__START_KERNEL_map, __START_KERNEL_map,
MODULES_VADDR-1); MODULES_VADDR-1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment