Skip to content

Commit 4d409ca

Browse files
keestsbogend
authored andcommitted
MIPS: boot/compressed: Use array reference for image bounds
As done with other image addresses in other architectures, use an explicit flexible array instead of "address of char", which can trip bounds checking done by the compiler. Found when building with -Warray-bounds: In file included from ./include/linux/byteorder/little_endian.h:5, from ./arch/mips/include/uapi/asm/byteorder.h:15, from ./arch/mips/include/asm/bitops.h:21, from ./include/linux/bitops.h:33, from ./include/linux/kernel.h:22, from arch/mips/boot/compressed/decompress.c:13: arch/mips/boot/compressed/decompress.c: In function 'decompress_kernel': ./include/asm-generic/unaligned.h:14:8: warning: array subscript -1 is outside array bounds of 'unsigned char[1]' [-Warray-bounds] 14 | __pptr->x; \ | ~~~~~~^~~ ./include/uapi/linux/byteorder/little_endian.h:35:51: note: in definition of macro '__le32_to_cpu' 35 | #define __le32_to_cpu(x) ((__force __u32)(__le32)(x)) | ^ ./include/asm-generic/unaligned.h:32:21: note: in expansion of macro '__get_unaligned_t' 32 | return le32_to_cpu(__get_unaligned_t(__le32, p)); | ^~~~~~~~~~~~~~~~~ arch/mips/boot/compressed/decompress.c:29:37: note: while referencing '__image_end' 29 | extern unsigned char __image_begin, __image_end; | ^~~~~~~~~~~ Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de> Cc: Randy Dunlap <rdunlap@infradead.org> Cc: linux-mips@vger.kernel.org Signed-off-by: Kees Cook <keescook@chromium.org> Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org> Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
1 parent 4528668 commit 4d409ca

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

arch/mips/boot/compressed/decompress.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ unsigned long free_mem_ptr;
2626
unsigned long free_mem_end_ptr;
2727

2828
/* The linker tells us where the image is. */
29-
extern unsigned char __image_begin, __image_end;
29+
extern unsigned char __image_begin[], __image_end[];
3030

3131
/* debug interfaces */
3232
#ifdef CONFIG_DEBUG_ZBOOT
@@ -91,9 +91,9 @@ void decompress_kernel(unsigned long boot_heap_start)
9191
{
9292
unsigned long zimage_start, zimage_size;
9393

94-
zimage_start = (unsigned long)(&__image_begin);
95-
zimage_size = (unsigned long)(&__image_end) -
96-
(unsigned long)(&__image_begin);
94+
zimage_start = (unsigned long)(__image_begin);
95+
zimage_size = (unsigned long)(__image_end) -
96+
(unsigned long)(__image_begin);
9797

9898
puts("zimage at: ");
9999
puthex(zimage_start);
@@ -121,7 +121,7 @@ void decompress_kernel(unsigned long boot_heap_start)
121121
dtb_size = fdt_totalsize((void *)&__appended_dtb);
122122

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

126126
/* The device tree's address must be properly aligned */
127127
image_size = ALIGN(image_size, STRUCT_ALIGNMENT);

0 commit comments

Comments
 (0)