From: "Jonathan Neuschäfer" <j.neuschaefer@gmx.net>
To: linux-arm-kernel@lists.infradead.org
Cc: "Russell King" <linux@armlinux.org.uk>,
"Nick Terrell" <terrelln@fb.com>, "Arnd Bergmann" <arnd@arndb.de>,
"Tony Lindgren" <tony@atomide.com>,
"Geert Uytterhoeven" <geert+renesas@glider.be>,
"Linus Walleij" <linus.walleij@linaro.org>,
"Sebastian Reichel" <sebastian.reichel@collabora.com>,
"Nick Hawkins" <nick.hawkins@hpe.com>,
"Christophe Leroy" <christophe.leroy@csgroup.eu>,
"Jonathan Neuschäfer" <j.neuschaefer@gmx.net>,
"Florian Fainelli" <f.fainelli@gmail.com>,
"Nick Desaulniers" <ndesaulniers@google.com>,
"Xin Li" <xin3.li@intel.com>,
"Seung-Woo Kim" <sw0312.kim@samsung.com>,
"Paul Bolle" <pebolle@tiscali.nl>,
"Bart Van Assche" <bvanassche@acm.org>,
linux-kernel@vger.kernel.org,
"Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
Subject: [PATCH 1/3] ARM: compressed: Pass the actual output length to the decompressor
Date: Wed, 12 Apr 2023 23:21:24 +0200 [thread overview]
Message-ID: <20230412212126.3966502-2-j.neuschaefer@gmx.net> (raw)
In-Reply-To: <20230412212126.3966502-1-j.neuschaefer@gmx.net>
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@gmx.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
next prev parent reply other threads:[~2023-04-12 21:22 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-12 21:21 [PATCH 0/3] ARM ZSTD boot compression Jonathan Neuschäfer
2023-04-12 21:21 ` Jonathan Neuschäfer [this message]
2023-04-12 21:42 ` [PATCH 1/3] ARM: compressed: Pass the actual output length to the decompressor Linus Walleij
2023-04-12 21:48 ` Florian Fainelli
2023-04-13 5:20 ` Tony Lindgren
2023-04-15 1:52 ` Jonathan Neuschäfer
2023-04-12 21:21 ` [PATCH 2/3] ARM: compressed: Bump MALLOC_SIZE to 128 KiB Jonathan Neuschäfer
2023-04-12 21:43 ` Linus Walleij
2023-04-12 21:48 ` Florian Fainelli
2023-05-02 8:39 ` Russell King (Oracle)
2023-04-12 21:21 ` [PATCH 3/3] ARM: compressed: Enable ZSTD compression Jonathan Neuschäfer
2023-04-12 21:45 ` Linus Walleij
2023-04-12 21:49 ` Florian Fainelli
2023-04-12 21:33 ` [PATCH 0/3] ARM ZSTD boot compression Arnd Bergmann
2023-04-13 11:13 ` Arnd Bergmann
2023-04-15 2:00 ` Jonathan Neuschäfer
2023-10-12 22:33 ` Nick Terrell
2023-10-13 1:27 ` J. Neuschäfer
2023-10-20 18:53 ` Nick Terrell
2023-04-14 22:50 ` Jonathan Neuschäfer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230412212126.3966502-2-j.neuschaefer@gmx.net \
--to=j.neuschaefer@gmx.net \
--cc=arnd@arndb.de \
--cc=bvanassche@acm.org \
--cc=christophe.leroy@csgroup.eu \
--cc=f.fainelli@gmail.com \
--cc=geert+renesas@glider.be \
--cc=linus.walleij@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=ndesaulniers@google.com \
--cc=nick.hawkins@hpe.com \
--cc=pebolle@tiscali.nl \
--cc=rmk+kernel@armlinux.org.uk \
--cc=sebastian.reichel@collabora.com \
--cc=sw0312.kim@samsung.com \
--cc=terrelln@fb.com \
--cc=tony@atomide.com \
--cc=xin3.li@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®