aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Kosina <jkosina@suse.cz>2015-04-27 07:17:19 -0400
committerJiri Kosina <jkosina@suse.cz>2015-04-29 10:51:33 -0400
commit4545c89880138b30a868159bc1b209867b8a5f32 (patch)
tree92b5085e5fbecc8946199f976ade079e7e320064
parent9497d7380b9c450830190c75aa43b25c278bb1f9 (diff)
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: Borislav Petkov <bp@suse.de> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r--arch/x86/include/asm/setup.h6
-rw-r--r--arch/x86/kernel/machine_kexec_64.c3
-rw-r--r--arch/x86/kernel/setup.c2
3 files changed, 9 insertions, 2 deletions
diff --git a/arch/x86/include/asm/setup.h b/arch/x86/include/asm/setup.h
index f69e06b283fb..785ac2f27271 100644
--- a/arch/x86/include/asm/setup.h
+++ b/arch/x86/include/asm/setup.h
@@ -65,12 +65,18 @@ static inline void x86_ce4100_early_setup(void) { }
65 * This is set up by the setup-routine at boot-time 65 * This is set up by the setup-routine at boot-time
66 */ 66 */
67extern struct boot_params boot_params; 67extern struct boot_params boot_params;
68extern char _text[];
68 69
69static inline bool kaslr_enabled(void) 70static inline bool kaslr_enabled(void)
70{ 71{
71 return !!(boot_params.hdr.loadflags & KASLR_FLAG); 72 return !!(boot_params.hdr.loadflags & KASLR_FLAG);
72} 73}
73 74
75static inline unsigned long kaslr_offset(void)
76{
77 return (unsigned long)&_text - __START_KERNEL;
78}
79
74/* 80/*
75 * Do NOT EVER look at the BIOS memory size location. 81 * Do NOT EVER look at the BIOS memory size location.
76 * It does not work on many machines. 82 * It does not work on many machines.
diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c
index 415480d3ea84..e1029633f664 100644
--- a/arch/x86/kernel/machine_kexec_64.c
+++ b/arch/x86/kernel/machine_kexec_64.c
@@ -25,6 +25,7 @@
25#include <asm/io_apic.h> 25#include <asm/io_apic.h>
26#include <asm/debugreg.h> 26#include <asm/debugreg.h>
27#include <asm/kexec-bzimage64.h> 27#include <asm/kexec-bzimage64.h>
28#include <asm/setup.h>
28 29
29#ifdef CONFIG_KEXEC_FILE 30#ifdef CONFIG_KEXEC_FILE
30static struct kexec_file_ops *kexec_file_loaders[] = { 31static struct kexec_file_ops *kexec_file_loaders[] = {
@@ -334,7 +335,7 @@ void arch_crash_save_vmcoreinfo(void)
334 VMCOREINFO_LENGTH(node_data, MAX_NUMNODES); 335 VMCOREINFO_LENGTH(node_data, MAX_NUMNODES);
335#endif 336#endif
336 vmcoreinfo_append_str("KERNELOFFSET=%lx\n", 337 vmcoreinfo_append_str("KERNELOFFSET=%lx\n",
337 (unsigned long)&_text - __START_KERNEL); 338 kaslr_offset());
338} 339}
339 340
340/* arch-dependent functionality related to kexec file-based syscall */ 341/* arch-dependent functionality related to kexec file-based syscall */
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index d74ac33290ae..5056d3cfe266 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -834,7 +834,7 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
834{ 834{
835 if (kaslr_enabled()) { 835 if (kaslr_enabled()) {
836 pr_emerg("Kernel Offset: 0x%lx from 0x%lx (relocation range: 0x%lx-0x%lx)\n", 836 pr_emerg("Kernel Offset: 0x%lx from 0x%lx (relocation range: 0x%lx-0x%lx)\n",
837 (unsigned long)&_text - __START_KERNEL, 837 kaslr_offset(),
838 __START_KERNEL, 838 __START_KERNEL,
839 __START_KERNEL_map, 839 __START_KERNEL_map,
840 MODULES_VADDR-1); 840 MODULES_VADDR-1);