Commit fb45daa6 authored by Huang Ying's avatar Huang Ying Committed by Linus Torvalds

kexec jump: check code size in control page

Kexec/Kexec-jump require code size in control page is less than
PAGE_SIZE/2.  This patch add link-time checking for this.

ASSERT() of ld link script is used as the link-time checking mechanism.

[akpm@linux-foundation.org: build fix]
Signed-off-by: default avatarHuang Ying <ying.huang@intel.com>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Acked-by: default avatarVivek Goyal <vgoyal@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 163f6876
...@@ -138,7 +138,7 @@ void machine_kexec(struct kimage *image) ...@@ -138,7 +138,7 @@ void machine_kexec(struct kimage *image)
} }
control_page = page_address(image->control_code_page); control_page = page_address(image->control_code_page);
memcpy(control_page, relocate_kernel, PAGE_SIZE/2); memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
relocate_kernel_ptr = control_page; relocate_kernel_ptr = control_page;
page_list[PA_CONTROL_PAGE] = __pa(control_page); page_list[PA_CONTROL_PAGE] = __pa(control_page);
......
...@@ -20,10 +20,11 @@ ...@@ -20,10 +20,11 @@
#define PAGE_ATTR (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_DIRTY) #define PAGE_ATTR (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_DIRTY)
#define PAE_PGD_ATTR (_PAGE_PRESENT) #define PAE_PGD_ATTR (_PAGE_PRESENT)
/* control_page + PAGE_SIZE/2 ~ control_page + PAGE_SIZE * 3/4 are /* control_page + KEXEC_CONTROL_CODE_MAX_SIZE
* used to save some data for jumping back * ~ control_page + PAGE_SIZE are used as data storage and stack for
* jumping back
*/ */
#define DATA(offset) (PAGE_SIZE/2+(offset)) #define DATA(offset) (KEXEC_CONTROL_CODE_MAX_SIZE+(offset))
/* Minimal CPU state */ /* Minimal CPU state */
#define ESP DATA(0x0) #define ESP DATA(0x0)
...@@ -376,3 +377,6 @@ swap_pages: ...@@ -376,3 +377,6 @@ swap_pages:
popl %ebx popl %ebx
popl %ebp popl %ebp
ret ret
.globl kexec_control_code_size
.set kexec_control_code_size, . - relocate_kernel
...@@ -209,3 +209,11 @@ SECTIONS ...@@ -209,3 +209,11 @@ SECTIONS
DWARF_DEBUG DWARF_DEBUG
} }
#ifdef CONFIG_KEXEC
/* Link time checks */
#include <asm/kexec.h>
ASSERT(kexec_control_code_size <= KEXEC_CONTROL_CODE_MAX_SIZE,
"kexec control code size is too big")
#endif
...@@ -41,6 +41,10 @@ ...@@ -41,6 +41,10 @@
# define PAGES_NR 17 # define PAGES_NR 17
#endif #endif
#ifdef CONFIG_X86_32
# define KEXEC_CONTROL_CODE_MAX_SIZE 2048
#endif
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
#include <linux/string.h> #include <linux/string.h>
......
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