s390/decompressor: fix initrd corruption caused by bss clear

Reorder the operations in decompress_kernel() to ensure initrd is moved
to a safe location before the bss section is zeroed.

During decompression bss can overlap with the initrd and this can
corrupt the initrd contents depending on the size of the compressed
kernel (which affects where the initrd is placed by the bootloader) and
the size of the bss section of the decompressor.

Also use the correct initrd size when checking for overlaps with
parmblock.

Fixes: 06c0dd72ae ([S390] fix boot failures with compressed kernels)
Cc: stable@vger.kernel.org
Reviewed-by: Joy Latten <joy.latten@canonical.com>
Reviewed-by: Vineetha HariPai <vineetha.hari.pai@canonical.com>
Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
This commit is contained in:
Marcelo Henrique Cerri 2017-03-13 12:14:58 -03:00 committed by Martin Schwidefsky
parent 093b995e3b
commit d82c0d12c9

View File

@ -141,31 +141,34 @@ static void check_ipl_parmblock(void *start, unsigned long size)
unsigned long decompress_kernel(void) unsigned long decompress_kernel(void)
{ {
unsigned long output_addr; void *output, *kernel_end;
unsigned char *output;
output_addr = ((unsigned long) &_end + HEAP_SIZE + 4095UL) & -4096UL; output = (void *) ALIGN((unsigned long) &_end + HEAP_SIZE, PAGE_SIZE);
check_ipl_parmblock((void *) 0, output_addr + SZ__bss_start); kernel_end = output + SZ__bss_start;
memset(&_bss, 0, &_ebss - &_bss); check_ipl_parmblock((void *) 0, (unsigned long) kernel_end);
free_mem_ptr = (unsigned long)&_end;
free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
output = (unsigned char *) output_addr;
#ifdef CONFIG_BLK_DEV_INITRD #ifdef CONFIG_BLK_DEV_INITRD
/* /*
* Move the initrd right behind the end of the decompressed * Move the initrd right behind the end of the decompressed
* kernel image. * kernel image. This also prevents initrd corruption caused by
* bss clearing since kernel_end will always be located behind the
* current bss section..
*/ */
if (INITRD_START && INITRD_SIZE && if (INITRD_START && INITRD_SIZE && kernel_end > (void *) INITRD_START) {
INITRD_START < (unsigned long) output + SZ__bss_start) { check_ipl_parmblock(kernel_end, INITRD_SIZE);
check_ipl_parmblock(output + SZ__bss_start, memmove(kernel_end, (void *) INITRD_START, INITRD_SIZE);
INITRD_START + INITRD_SIZE); INITRD_START = (unsigned long) kernel_end;
memmove(output + SZ__bss_start,
(void *) INITRD_START, INITRD_SIZE);
INITRD_START = (unsigned long) output + SZ__bss_start;
} }
#endif #endif
/*
* Clear bss section. free_mem_ptr and free_mem_end_ptr need to be
* initialized afterwards since they reside in bss.
*/
memset(&_bss, 0, &_ebss - &_bss);
free_mem_ptr = (unsigned long) &_end;
free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
puts("Uncompressing Linux... "); puts("Uncompressing Linux... ");
__decompress(input_data, input_len, NULL, NULL, output, 0, NULL, error); __decompress(input_data, input_len, NULL, NULL, output, 0, NULL, error);
puts("Ok, booting the kernel.\n"); puts("Ok, booting the kernel.\n");