[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230412212126.3966502-2-j.neuschaefer@gmx.net>
Date: Wed, 12 Apr 2023 23:21:24 +0200
From: Jonathan Neuschäfer <j.neuschaefer@....net>
To: linux-arm-kernel@...ts.infradead.org
Cc: Russell King <linux@...linux.org.uk>,
Nick Terrell <terrelln@...com>, Arnd Bergmann <arnd@...db.de>,
Tony Lindgren <tony@...mide.com>,
Geert Uytterhoeven <geert+renesas@...der.be>,
Linus Walleij <linus.walleij@...aro.org>,
Sebastian Reichel <sebastian.reichel@...labora.com>,
Nick Hawkins <nick.hawkins@....com>,
Christophe Leroy <christophe.leroy@...roup.eu>,
Jonathan Neuschäfer <j.neuschaefer@....net>,
Florian Fainelli <f.fainelli@...il.com>,
Nick Desaulniers <ndesaulniers@...gle.com>,
Xin Li <xin3.li@...el.com>,
Seung-Woo Kim <sw0312.kim@...sung.com>,
Paul Bolle <pebolle@...cali.nl>,
Bart Van Assche <bvanassche@....org>,
linux-kernel@...r.kernel.org,
"Russell King (Oracle)" <rmk+kernel@...linux.org.uk>
Subject: [PATCH 1/3] ARM: compressed: Pass the actual output length to the decompressor
ZSTD writes outside of the space that is necessary for the uncompressed
data, when it is told it has unlimited output length. To fix this, pass
the actual output length (the length of the uncompressed kernel) to the
decompressor.
The uncompressed length is already stored as a little endian 32-bit
constant before the input_data_end symbol.
Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@....net>
---
arch/arm/boot/compressed/decompress.c | 4 ++--
arch/arm/boot/compressed/misc.c | 12 ++++++++++--
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/arch/arm/boot/compressed/decompress.c b/arch/arm/boot/compressed/decompress.c
index 74255e8198314..3d098b84ee391 100644
--- a/arch/arm/boot/compressed/decompress.c
+++ b/arch/arm/boot/compressed/decompress.c
@@ -59,7 +59,7 @@ extern char * strchrnul(const char *, int);
#include "../../../../lib/decompress_unlz4.c"
#endif
-int do_decompress(u8 *input, int len, u8 *output, void (*error)(char *x))
+int do_decompress(u8 *input, int len, u8 *output, int outlen, void (*error)(char *x))
{
- return __decompress(input, len, NULL, NULL, output, 0, NULL, error);
+ return __decompress(input, len, NULL, NULL, output, outlen, NULL, error);
}
diff --git a/arch/arm/boot/compressed/misc.c b/arch/arm/boot/compressed/misc.c
index abfed1aa2baa8..8402b29bccc82 100644
--- a/arch/arm/boot/compressed/misc.c
+++ b/arch/arm/boot/compressed/misc.c
@@ -22,6 +22,7 @@ unsigned int __machine_arch_type;
#include <linux/compiler.h> /* for inline */
#include <linux/types.h>
#include <linux/linkage.h>
+#include <asm/unaligned.h>
#include "misc.h"
#ifdef CONFIG_ARCH_EP93XX
#include "misc-ep93xx.h"
@@ -131,17 +132,24 @@ asmlinkage void __div0(void)
error("Attempting division by 0!");
}
-extern int do_decompress(u8 *input, int len, u8 *output, void (*error)(char *x));
+extern int do_decompress(u8 *input, int len, u8 *output, int outlen,
+ void (*error)(char *x));
+static u32 get_inflated_image_size(void)
+{
+ return get_unaligned_le32(input_data_end - 4);
+}
void
decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p,
unsigned long free_mem_ptr_end_p,
int arch_id)
{
+ unsigned long output_data_len;
int ret;
output_data = (unsigned char *)output_start;
+ output_data_len = get_inflated_image_size();
free_mem_ptr = free_mem_ptr_p;
free_mem_end_ptr = free_mem_ptr_end_p;
__machine_arch_type = arch_id;
@@ -153,7 +161,7 @@ decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p,
putstr("Uncompressing Linux...");
ret = do_decompress(input_data, input_data_end - input_data,
- output_data, error);
+ output_data, output_data_len, error);
if (ret)
error("decompressor returned an error");
else
--
2.39.2
Powered by blists - more mailing lists