kexec jump: check code size in control page
Subsystems (3)
PATCH 3/8 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.
--- arch/x86/kernel/machine_kexec_32.c | 2 +- arch/x86/kernel/relocate_kernel_32.S | 10 +++++++--- arch/x86/kernel/vmlinux_32.lds.S | 2 ++ arch/x86/kernel/vmlinux_check_32.lds.S | 7 +++++++ include/asm-x86/kexec.h | 4 ++++ 5 files changed, 21 insertions(+), 4 deletions(-)
arch/x86/kernel/machine_kexec_32.c +1 -1
@@ -138,7 +138,7 @@ void machine_kexec(struct kimage *image) } 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; page_list[PA_CONTROL_PAGE ] =__pa (control_page);
arch/x86/kernel/relocate_kernel_32.S +7 -3
@@ -20,10 +20,11 @@ #define PAGE_ATTR (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_DIRTY) #define PAE_PGD_ATTR (_PAGE_PRESENT) -/* control_page + PAGE_SIZE/2 ~ control_page + PAGE_SIZE * 3/4 are - * used to save some data for jumping back +/* control_page + KEXEC_CONTROL_CODE_MAX_SIZE + * ~ control_page + PAGE_SIZE * 3/4 are used to save some data for + * jumping back */ -#define DATA(offset) (PAGE_SIZE/2+(offset)) +#define DATA(offset) (KEXEC_CONTROL_CODE_MAX_SIZE+(offset)) /* Minimal CPU state */ #define ESP DATA(0x0)
@@ -376,3 +377,6 @@ swap_pages: popl %ebx popl %ebp ret + + .globl kexec_control_code_size +.set kexec_control_code_size, . - relocate_kernel
include/asm-x86/kexec.h +4 -0
@@ -41,6 +41,10 @@# define PAGES_NR 17#endif +#ifdef CONFIG_X86_32 +# define KEXEC_CONTROL_CODE_MAX_SIZE 2048 +#endif +#ifndef __ASSEMBLY__#include <linux/string.h>
arch/x86/kernel/vmlinux_32.lds.S +2 -0
@@ -209,3 +209,5 @@ SECTIONS DWARF_DEBUG } + +#include "vmlinux_check_32.lds.S"
arch/x86/kernel/vmlinux_check_32.lds.S new file +7 -0
@@ -0,0 +1,7 @@ +/* + * Link time checks + */ + +#include <asm/kexec.h> + +ASSERT(kexec_control_code_size <= KEXEC_CONTROL_CODE_MAX_SIZE, "kexec control code size is too big")
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 30 lines · Huang Ying
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.Signed-off-by Huang Ying <[email protected]>--- arch/x86/kernel/machine_kexec_32.c | 2 +- arch/x86/kernel/relocate_kernel_32.S | 10 +++++++--- arch/x86/kernel/vmlinux_32.lds.S | 2 ++ arch/x86/kernel/vmlinux_check_32.lds.S | 7 +++++++ include/asm-x86/kexec.h | 4 ++++ 5 files changed, 21 insertions(+), 4 deletions(-)arch/x86/kernel/machine_kexec_32.c +1
-1@@ -138,7 +138,7 @@ void machine_kexec(struct kimage *image) } 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; page_list[PA_CONTROL_PAGE ] =__pa (control_page);
arch/x86/kernel/relocate_kernel_32.S line 26
Quoted 9 lines
arch/x86/kernel/relocate_kernel_32.S +3
-2@@ -20,10 +20,11 @@ #define PAGE_ATTR (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_DIRTY) #define PAE_PGD_ATTR (_PAGE_PRESENT) -/* control_page + PAGE_SIZE/2 ~ control_page + PAGE_SIZE * 3/4 are - * used to save some data for jumping back +/* control_page + KEXEC_CONTROL_CODE_MAX_SIZE + * ~ control_page + PAGE_SIZE * 3/4 are used to save some data for + * jumping back */
Hi Huang,
Above comment is not very clear. Can you please elaborate it. I thought that PAGE_SIZE/2 is used for control code and rest half is shared between kjump data and stack. What is PAGE_SIZE *3/4?
Quoted 36 lines
arch/x86/kernel/relocate_kernel_32.S +4
-1-#define DATA(offset) (PAGE_SIZE/2+(offset)) +#define DATA(offset) (KEXEC_CONTROL_CODE_MAX_SIZE+(offset)) /* Minimal CPU state */ #define ESP DATA(0x0)@@ -376,3 +377,6 @@ swap_pages: popl %ebx popl %ebp ret + + .globl kexec_control_code_size +.set kexec_control_code_size, . - relocate_kernelinclude/asm-x86/kexec.h +4
-0@@ -41,6 +41,10 @@# define PAGES_NR 17#endif +#ifdef CONFIG_X86_32 +# define KEXEC_CONTROL_CODE_MAX_SIZE 2048 +#endif +#ifndef __ASSEMBLY__#include <linux/string.h> arch/x86/kernel/vmlinux_32.lds.S +2
-0@@ -209,3 +209,5 @@ SECTIONS DWARF_DEBUG } + +#include "vmlinux_check_32.lds.S"
arch/x86/kernel/vmlinux_check_32.lds.S line 7
Quoted 7 lines
arch/x86/kernel/vmlinux_check_32.lds.S new file +7
-0@@ -0,0 +1,7 @@ +/* + * Link time checks + */ + +#include <asm/kexec.h> + +ASSERT(kexec_control_code_size <= KEXEC_CONTROL_CODE_MAX_SIZE, "kexec control code size is too big")
Will it make sense to move it into vmlinux_32.lds.S itself? Creating a separate file for a single check seems superfluous.
Thanks
Vivek
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Hi, Vivek,
On Fri, 2008-08-08 at 10:09 -0400, Vivek Goyal wrote:
[...]
Quoted 15 lines
arch/x86/kernel/relocate_kernel_32.S line 26
Quoted 12 lines
arch/x86/kernel/relocate_kernel_32.S +3
-2@@ -20,10 +20,11 @@ #define PAGE_ATTR (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_DIRTY) #define PAE_PGD_ATTR (_PAGE_PRESENT) -/* control_page + PAGE_SIZE/2 ~ control_page + PAGE_SIZE * 3/4 are - * used to save some data for jumping back +/* control_page + KEXEC_CONTROL_CODE_MAX_SIZE + * ~ control_page + PAGE_SIZE * 3/4 are used to save some data for + * jumping back */Hi Huang,
Quoted 3 lines
Above comment is not very clear. Can you please elaborate it. I thought that PAGE_SIZE/2 is used for control code and rest half is shared between kjump data and stack. What is
PAGE_SIZE*3/4?
Yes. Rest half is shared between kjump data and stack. I will change it.
Quoted 11 lines
arch/x86/kernel/relocate_kernel_32.S line 7
Quoted 9 lines
arch/x86/kernel/relocate_kernel_32.S +8
-0+++ b/arch/x86/kernel/vmlinux_check_32.lds.S@@ -0,0 +1,7 @@ +/* + * Link time checks + */ + +#include <asm/kexec.h> + +ASSERT(kexec_control_code_size <= KEXEC_CONTROL_CODE_MAX_SIZE,"kexec control code size is too big")
Quoted 3 lines
Will it make sense to move it into
vmlinux_32.lds.Sitself? Creating a separate
file for a single check seems superfluous.
I hope other ones can use it. But for now, put it in vmlinux_32.lds.S is better. I will change it.
Best Regards,
HUang Ying
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec