Commit 4d2d5424 authored by Yinghai Lu's avatar Yinghai Lu Committed by Ingo Molnar
Browse files

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: default avatarYinghai Lu <yinghai@kernel.org>
Signed-off-by: default avatarBaoquan He <bhe@redhat.com>
[ Rewrote the changelog, renamed 'run_size' to 'kernel_total_size' ]
Signed-off-by: default avatarKees 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: default avatarIngo Molnar <mingo@kernel.org>
parent 67b66625
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -121,10 +121,8 @@ suffix-$(CONFIG_KERNEL_XZ) := xz
suffix-$(CONFIG_KERNEL_LZO) 	:= lzo
suffix-$(CONFIG_KERNEL_LZ4) 	:= lz4

RUN_SIZE = $(shell $(OBJDUMP) -h vmlinux | \
	     $(CONFIG_SHELL) $(srctree)/arch/x86/tools/calc_run_size.sh)
quiet_cmd_mkpiggy = MKPIGGY $@
      cmd_mkpiggy = $(obj)/mkpiggy $< $(RUN_SIZE) > $@ || ( rm -f $@ ; false )
      cmd_mkpiggy = $(obj)/mkpiggy $< > $@ || ( rm -f $@ ; false )

targets += piggy.S
$(obj)/piggy.S: $(obj)/vmlinux.bin.$(suffix-y) $(obj)/mkpiggy FORCE
+1 −2
Original line number Diff line number Diff line
@@ -238,7 +238,6 @@ relocated:
 * Do the extraction, and jump to the new kernel..
 */
				/* push arguments for extract_kernel: */
	pushl	$z_run_size	/* size of kernel with .bss and .brk */
	pushl	$z_output_len	/* decompressed length, end of relocs */

	movl    BP_init_size(%esi), %eax
@@ -254,7 +253,7 @@ relocated:
	pushl	%eax		/* heap area */
	pushl	%esi		/* real mode pointer */
	call	extract_kernel	/* returns kernel location in %eax */
	addl	$28, %esp
	addl	$24, %esp

/*
 * Jump to the extracted kernel.
+0 −3
Original line number Diff line number Diff line
@@ -415,8 +415,6 @@ relocated:
 * Do the extraction, and jump to the new kernel..
 */
	pushq	%rsi			/* Save the real mode argument */
	movq	$z_run_size, %r9	/* size of kernel with .bss and .brk */
	pushq	%r9
	movq	%rsi, %rdi		/* real mode address */
	leaq	boot_heap(%rip), %rsi	/* malloc area for uncompression */
	leaq	input_data(%rip), %rdx  /* input_data */
@@ -424,7 +422,6 @@ relocated:
	movq	%rbp, %r8		/* output target address */
	movq	$z_output_len, %r9	/* decompressed length, end of relocs */
	call	extract_kernel		/* returns kernel location in %rax */
	popq	%r9
	popq	%rsi

/*
+4 −7
Original line number Diff line number Diff line
@@ -340,9 +340,9 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap,
				  unsigned char *input_data,
				  unsigned long input_len,
				  unsigned char *output,
				  unsigned long output_len,
				  unsigned long run_size)
				  unsigned long output_len)
{
	const unsigned long kernel_total_size = VO__end - VO__text;
	unsigned char *output_orig = output;

	/* Retain x86 boot parameters pointer passed from startup_32/64. */
@@ -364,8 +364,6 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap,
	lines = boot_params->screen_info.orig_video_lines;
	cols = boot_params->screen_info.orig_video_cols;

	run_size = VO__end - VO__text;

	console_init();
	debug_putstr("early console in extract_kernel\n");

@@ -377,7 +375,7 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap,
	debug_putaddr(input_len);
	debug_putaddr(output);
	debug_putaddr(output_len);
	debug_putaddr(run_size);
	debug_putaddr(kernel_total_size);

	/*
	 * 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,
	 * entire decompressed kernel plus .bss and .brk sections.
	 */
	output = choose_random_location(input_data, input_len, output,
					output_len > run_size ? output_len
							      : run_size);
					max(output_len, kernel_total_size));

	/* Validate memory location choices. */
	if ((unsigned long)output & (MIN_KERNEL_ALIGN - 1))
+2 −8
Original line number Diff line number Diff line
@@ -34,13 +34,11 @@ int main(int argc, char *argv[])
{
	uint32_t olen;
	long ilen;
	unsigned long run_size;
	FILE *f = NULL;
	int retval = 1;

	if (argc < 3) {
		fprintf(stderr, "Usage: %s compressed_file run_size\n",
				argv[0]);
	if (argc < 2) {
		fprintf(stderr, "Usage: %s compressed_file\n", argv[0]);
		goto bail;
	}

@@ -65,15 +63,11 @@ int main(int argc, char *argv[])
	ilen = ftell(f);
	olen = get_unaligned_le32(&olen);

	run_size = atoi(argv[2]);

	printf(".section \".rodata..compressed\",\"a\",@progbits\n");
	printf(".globl z_input_len\n");
	printf("z_input_len = %lu\n", ilen);
	printf(".globl z_output_len\n");
	printf("z_output_len = %lu\n", (unsigned long)olen);
	printf(".globl z_run_size\n");
	printf("z_run_size = %lu\n", run_size);

	printf(".globl input_data, input_data_end\n");
	printf("input_data:\n");
Loading