Skip to content

Commit

Permalink
MIPS: boot: Fix unaligned access with CONFIG_MIPS_RAW_APPENDED_DTB
Browse files Browse the repository at this point in the history
commit 4d4f9c1 upstream.

The compressed payload is not necesarily 4-byte aligned, at least when
compiling with Clang. In that case, the 4-byte value appended to the
compressed payload that corresponds to the uncompressed kernel image
size must be read using get_unaligned_le32().

This fixes Clang-built kernels not booting on MIPS (tested on a Ingenic
JZ4770 board).

Fixes: b8f54f2 ("MIPS: ZBOOT: copy appended dtb to the end of the kernel")
Cc: <[email protected]> # v4.7
Signed-off-by: Paul Cercueil <[email protected]>
Reviewed-by: Nick Desaulniers <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Thomas Bogendoerfer <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
pcercuei authored and gregkh committed Jan 19, 2021
1 parent 974f196 commit 9e2413f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion arch/mips/boot/compressed/decompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <linux/libfdt.h>

#include <asm/addrspace.h>
#include <asm/unaligned.h>

/*
* These two variables specify the free mem region
Expand Down Expand Up @@ -117,7 +118,7 @@ void decompress_kernel(unsigned long boot_heap_start)
dtb_size = fdt_totalsize((void *)&__appended_dtb);

/* last four bytes is always image size in little endian */
image_size = le32_to_cpup((void *)&__image_end - 4);
image_size = get_unaligned_le32((void *)&__image_end - 4);

/* copy dtb to where the booted kernel will expect it */
memcpy((void *)VMLINUX_LOAD_ADDRESS_ULL + image_size,
Expand Down

0 comments on commit 9e2413f

Please sign in to comment.