aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/boot
diff options
context:
space:
mode:
authorYinghai Lu <yinghai@kernel.org>2016-04-28 20:09:07 -0400
committerIngo Molnar <mingo@kernel.org>2016-04-29 05:03:30 -0400
commit4d2d542482205d3df1a0852751f5b004cc6390cc (patch)
treece5aca3461a76427d62413c1a07484da6f9772f1 /arch/x86/boot
parent67b6662559f7f77bcbd3ac67d09aaac11785f3c1 (diff)
x86/KASLR: Clean up unused code from old 'run_size' and rename it to 'kernel_total_size'
Since 'run_size' is now calculated in misc.c, the old script and associated argument passing is no longer needed. This patch removes them, and renames 'run_size' to the more descriptive 'kernel_total_size'. Signed-off-by: Yinghai Lu <yinghai@kernel.org> Signed-off-by: Baoquan He <bhe@redhat.com> [ Rewrote the changelog, renamed 'run_size' to 'kernel_total_size' ] Signed-off-by: Kees Cook <keescook@chromium.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Andy Lutomirski <luto@kernel.org> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Dave Young <dyoung@redhat.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Josh Triplett <josh@joshtriplett.org> Cc: Junjie Mao <eternal.n08@gmail.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Vivek Goyal <vgoyal@redhat.com> Cc: lasse.collin@tukaani.org Link: http://lkml.kernel.org/r/1461888548-32439-6-git-send-email-keescook@chromium.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'arch/x86/boot')
-rw-r--r--arch/x86/boot/compressed/Makefile4
-rw-r--r--arch/x86/boot/compressed/head_32.S3
-rw-r--r--arch/x86/boot/compressed/head_64.S3
-rw-r--r--arch/x86/boot/compressed/misc.c11
-rw-r--r--arch/x86/boot/compressed/mkpiggy.c10
5 files changed, 8 insertions, 23 deletions
diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
index 45997805adad..adef26d22224 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -121,10 +121,8 @@ suffix-$(CONFIG_KERNEL_XZ) := xz
121suffix-$(CONFIG_KERNEL_LZO) := lzo 121suffix-$(CONFIG_KERNEL_LZO) := lzo
122suffix-$(CONFIG_KERNEL_LZ4) := lz4 122suffix-$(CONFIG_KERNEL_LZ4) := lz4
123 123
124RUN_SIZE = $(shell $(OBJDUMP) -h vmlinux | \
125 $(CONFIG_SHELL) $(srctree)/arch/x86/tools/calc_run_size.sh)
126quiet_cmd_mkpiggy = MKPIGGY $@ 124quiet_cmd_mkpiggy = MKPIGGY $@
127 cmd_mkpiggy = $(obj)/mkpiggy $< $(RUN_SIZE) > $@ || ( rm -f $@ ; false ) 125 cmd_mkpiggy = $(obj)/mkpiggy $< > $@ || ( rm -f $@ ; false )
128 126
129targets += piggy.S 127targets += piggy.S
130$(obj)/piggy.S: $(obj)/vmlinux.bin.$(suffix-y) $(obj)/mkpiggy FORCE 128$(obj)/piggy.S: $(obj)/vmlinux.bin.$(suffix-y) $(obj)/mkpiggy FORCE
diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
index 8a95e2f845aa..1038524270e7 100644
--- a/arch/x86/boot/compressed/head_32.S
+++ b/arch/x86/boot/compressed/head_32.S
@@ -238,7 +238,6 @@ relocated:
238 * Do the extraction, and jump to the new kernel.. 238 * Do the extraction, and jump to the new kernel..
239 */ 239 */
240 /* push arguments for extract_kernel: */ 240 /* push arguments for extract_kernel: */
241 pushl $z_run_size /* size of kernel with .bss and .brk */
242 pushl $z_output_len /* decompressed length, end of relocs */ 241 pushl $z_output_len /* decompressed length, end of relocs */
243 242
244 movl BP_init_size(%esi), %eax 243 movl BP_init_size(%esi), %eax
@@ -254,7 +253,7 @@ relocated:
254 pushl %eax /* heap area */ 253 pushl %eax /* heap area */
255 pushl %esi /* real mode pointer */ 254 pushl %esi /* real mode pointer */
256 call extract_kernel /* returns kernel location in %eax */ 255 call extract_kernel /* returns kernel location in %eax */
257 addl $28, %esp 256 addl $24, %esp
258 257
259/* 258/*
260 * Jump to the extracted kernel. 259 * Jump to the extracted kernel.
diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
index 09cdc0c3ee7e..7c047002950c 100644
--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -415,8 +415,6 @@ relocated:
415 * Do the extraction, and jump to the new kernel.. 415 * Do the extraction, and jump to the new kernel..
416 */ 416 */
417 pushq %rsi /* Save the real mode argument */ 417 pushq %rsi /* Save the real mode argument */
418 movq $z_run_size, %r9 /* size of kernel with .bss and .brk */
419 pushq %r9
420 movq %rsi, %rdi /* real mode address */ 418 movq %rsi, %rdi /* real mode address */
421 leaq boot_heap(%rip), %rsi /* malloc area for uncompression */ 419 leaq boot_heap(%rip), %rsi /* malloc area for uncompression */
422 leaq input_data(%rip), %rdx /* input_data */ 420 leaq input_data(%rip), %rdx /* input_data */
@@ -424,7 +422,6 @@ relocated:
424 movq %rbp, %r8 /* output target address */ 422 movq %rbp, %r8 /* output target address */
425 movq $z_output_len, %r9 /* decompressed length, end of relocs */ 423 movq $z_output_len, %r9 /* decompressed length, end of relocs */
426 call extract_kernel /* returns kernel location in %rax */ 424 call extract_kernel /* returns kernel location in %rax */
427 popq %r9
428 popq %rsi 425 popq %rsi
429 426
430/* 427/*
diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
index cda93d16ad4d..bee6238e7cfc 100644
--- a/arch/x86/boot/compressed/misc.c
+++ b/arch/x86/boot/compressed/misc.c
@@ -340,9 +340,9 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap,
340 unsigned char *input_data, 340 unsigned char *input_data,
341 unsigned long input_len, 341 unsigned long input_len,
342 unsigned char *output, 342 unsigned char *output,
343 unsigned long output_len, 343 unsigned long output_len)
344 unsigned long run_size)
345{ 344{
345 const unsigned long kernel_total_size = VO__end - VO__text;
346 unsigned char *output_orig = output; 346 unsigned char *output_orig = output;
347 347
348 /* Retain x86 boot parameters pointer passed from startup_32/64. */ 348 /* Retain x86 boot parameters pointer passed from startup_32/64. */
@@ -364,8 +364,6 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap,
364 lines = boot_params->screen_info.orig_video_lines; 364 lines = boot_params->screen_info.orig_video_lines;
365 cols = boot_params->screen_info.orig_video_cols; 365 cols = boot_params->screen_info.orig_video_cols;
366 366
367 run_size = VO__end - VO__text;
368
369 console_init(); 367 console_init();
370 debug_putstr("early console in extract_kernel\n"); 368 debug_putstr("early console in extract_kernel\n");
371 369
@@ -377,7 +375,7 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap,
377 debug_putaddr(input_len); 375 debug_putaddr(input_len);
378 debug_putaddr(output); 376 debug_putaddr(output);
379 debug_putaddr(output_len); 377 debug_putaddr(output_len);
380 debug_putaddr(run_size); 378 debug_putaddr(kernel_total_size);
381 379
382 /* 380 /*
383 * The memory hole needed for the kernel is the larger of either 381 * The memory hole needed for the kernel is the larger of either
@@ -385,8 +383,7 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap,
385 * entire decompressed kernel plus .bss and .brk sections. 383 * entire decompressed kernel plus .bss and .brk sections.
386 */ 384 */
387 output = choose_random_location(input_data, input_len, output, 385 output = choose_random_location(input_data, input_len, output,
388 output_len > run_size ? output_len 386 max(output_len, kernel_total_size));
389 : run_size);
390 387
391 /* Validate memory location choices. */ 388 /* Validate memory location choices. */
392 if ((unsigned long)output & (MIN_KERNEL_ALIGN - 1)) 389 if ((unsigned long)output & (MIN_KERNEL_ALIGN - 1))
diff --git a/arch/x86/boot/compressed/mkpiggy.c b/arch/x86/boot/compressed/mkpiggy.c
index f095ed9e7d3c..72bad2c8debe 100644
--- a/arch/x86/boot/compressed/mkpiggy.c
+++ b/arch/x86/boot/compressed/mkpiggy.c
@@ -34,13 +34,11 @@ int main(int argc, char *argv[])
34{ 34{
35 uint32_t olen; 35 uint32_t olen;
36 long ilen; 36 long ilen;
37 unsigned long run_size;
38 FILE *f = NULL; 37 FILE *f = NULL;
39 int retval = 1; 38 int retval = 1;
40 39
41 if (argc < 3) { 40 if (argc < 2) {
42 fprintf(stderr, "Usage: %s compressed_file run_size\n", 41 fprintf(stderr, "Usage: %s compressed_file\n", argv[0]);
43 argv[0]);
44 goto bail; 42 goto bail;
45 } 43 }
46 44
@@ -65,15 +63,11 @@ int main(int argc, char *argv[])
65 ilen = ftell(f); 63 ilen = ftell(f);
66 olen = get_unaligned_le32(&olen); 64 olen = get_unaligned_le32(&olen);
67 65
68 run_size = atoi(argv[2]);
69
70 printf(".section \".rodata..compressed\",\"a\",@progbits\n"); 66 printf(".section \".rodata..compressed\",\"a\",@progbits\n");
71 printf(".globl z_input_len\n"); 67 printf(".globl z_input_len\n");
72 printf("z_input_len = %lu\n", ilen); 68 printf("z_input_len = %lu\n", ilen);
73 printf(".globl z_output_len\n"); 69 printf(".globl z_output_len\n");
74 printf("z_output_len = %lu\n", (unsigned long)olen); 70 printf("z_output_len = %lu\n", (unsigned long)olen);
75 printf(".globl z_run_size\n");
76 printf("z_run_size = %lu\n", run_size);
77 71
78 printf(".globl input_data, input_data_end\n"); 72 printf(".globl input_data, input_data_end\n");
79 printf("input_data:\n"); 73 printf("input_data:\n");