From patchwork Wed Apr 12 21:21:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?J=2E_Neusch=C3=A4fer?= X-Patchwork-Id: 13209535 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 10359C77B6C for ; Wed, 12 Apr 2023 21:23:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Es/55uAaliSmcewPCQnnxnt2I4z/T8hBfchFQ+uGC20=; b=I9PXK3IiZWIM8P /awuEFKe7ZhGFkDdNcBDjVeeyEOXybx4kfxFnOEXxr4omkZnajZvzgnAkQxPoY54HfLrGOAH8A6vP AB5wHuSLatcb8fsnHzWED6gjHFi9/dVPSNDhCPdv2RQ/dQBiUlE06B5a0mzmoaltpei3C9NCNGFsm +/YuzYA+kIFNBBPjwW9fTR1aUq8RkWtK6QU2Gf8wCea6GjNhq6oYWE6oYcM8CzJksQit7OAwSzLoN JdbOql3nOQILLaY4Qp5PyJom2xkVL+5YQ/kWemuRd8FrfWq9df4c8Ydcr59uEnuWyB8zl/LaT41tx 5ZXFs6xBUxI/Gvruko8A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pmhvN-004NcO-2z; Wed, 12 Apr 2023 21:22:41 +0000 Received: from mout.gmx.net ([212.227.15.19]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pmhvF-004NZS-1Y for linux-arm-kernel@lists.infradead.org; Wed, 12 Apr 2023 21:22:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=s31663417; t=1681334514; i=j.neuschaefer@gmx.net; bh=w4sCM12T3GwE9Idp4Z+5KQM9o6BWvMigt3zMC505xKw=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=EIthzBk7V9dTwGCevl2ID2eaBvJ99830DWe/E4B+7cEm17DwtfvhtH6sal9eMXI4P pbTzg+2Ukbp+YMO9gNMkrbrpkUx40LvdQ/C1rJsDUMPothsoLVLrJEE/4YCZRqw5Nw vc0jF19Y1J/resZculEGxxkm3tynBsAQGbqW85MVQtQie0FXETsYLUgLUhR6LpiOEI CPaTksxxq5e8MyO8jb1wb/81I1wj8ChMRpPH7o16uScDohkBuP17RaioouhQWNnR2B hG1Y76JCgA0fdU+pvE711NPZZahOJgV5S6OGywqviolcfVoA+j7sSTHBbJ60QPdb8E YSYTUnGOmeyYA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from probook ([185.66.193.41]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N4QsO-1qTERQ26K6-011Ohg; Wed, 12 Apr 2023 23:21:54 +0200 From: =?utf-8?q?Jonathan_Neusch=C3=A4fer?= To: linux-arm-kernel@lists.infradead.org Cc: Russell King , Nick Terrell , Arnd Bergmann , Tony Lindgren , Geert Uytterhoeven , Linus Walleij , Sebastian Reichel , Nick Hawkins , Christophe Leroy , =?utf-8?q?Jonathan_Neusch?= =?utf-8?q?=C3=A4fer?= , Florian Fainelli , Nick Desaulniers , Xin Li , Seung-Woo Kim , Paul Bolle , Bart Van Assche , linux-kernel@vger.kernel.org, "Russell King (Oracle)" Subject: [PATCH 1/3] ARM: compressed: Pass the actual output length to the decompressor Date: Wed, 12 Apr 2023 23:21:24 +0200 Message-Id: <20230412212126.3966502-2-j.neuschaefer@gmx.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230412212126.3966502-1-j.neuschaefer@gmx.net> References: <20230412212126.3966502-1-j.neuschaefer@gmx.net> MIME-Version: 1.0 X-Provags-ID: V03:K1:asTkI05mit0v6ML4tVuKmImFEuUsK0Fu2edpCC39+pLZg2GbPEp uz6X4ZfRT20DLhLPUl8stqEq3qsocNzWidlj25tSp8ODUYV8E61NLSs9J2c01K8hlt2sdnU 4eLQbQQmZxMqVRPCi2Ngsw55OhjDQbP4MkfpuGDNQgKVJ4vIs98dvmU1022PSQkJ8VjBKJl cm/3GJ/kQSIr4KYl47XQQ== UI-OutboundReport: notjunk:1;M01:P0:wYI1qy9oxMg=;ZVVUPgqmOo4gpzWIhJbrqdHAqdl N/GLP6C6/VhJGvwN/crPZrSQBl8auweY4IQwlsQeyi5qyOCoWzQrSaDquJfz55LP19Gppap3t wQObz41pOU4bLa6Y8cM9EBOrXquszDEKVaVgRj9GKRnftxUuIZh8ZQtpVd5bwHPZrTMC+KwmC wLmUVxzfg29ft2ErEWZACAYnztBqaYr5OkLudtrTyBRfc/ZqhBJkeucHwKA8GehJmrrmIikNq IJG2bv5jvss8+W8HYYjUlEAG/g1nSKi9lsQhGXXgECDzgwAU9Hv4KCbEIWG71L252b2BG64nf h0y9IxXFHTLJYRN6AFpDxP9DqPtaMAdmF0i5LnsUw21I/arDhvspGVpVpLr7XHSUc7KMqO3BK 4EbzfaFLHvm09ep3TfdNS1tV2WSj3VZ06UNkBI7EwOHzrWw86tBf0ebxyRI1BPXnfT7aYU+8Z Ce3wO+HJcOrMhhIpkz9eZdKOw8i3mDgTMe1cYVtlGyIA6vZ9W2Vo8178qismrg/v25MAejjxt oD+IEAeHOrGMp1/LhCad1/wybR/BG5fsHh5yhgNoSQeu5iuxoWYwXcGpoC5TZSMRYRsxLpdNT y96LkkEmGQ5H9DaX6Rp/f5ODudF614GI9aJH/vWYFcfVpnhdiY+Jo6BAY3Syeu2aSJo8kmv5f 2Ab6Z1bWpZYl33Ons8+F7v3B2ZT+4l8HxyDTnC2NhiYJVpDYqQCSlvy9V44cCkUfsfZUBlHIS TXeR/p5qQbkv2OwasfFVrbbswyhpDtgXH6camhneX7UAKkHx6A0o6gJtcLmhOBGxnH1i3dBvv MEGuUBs8b7AOfR/iMogtMFY5I47xjUIMoJCib7Y2S/hTtwAal7syElPOb58tuoVns9Hu3+QJx UuEVsGJUYFA2G3SXzk3WaHq057WuDBTvfAdFoxQZjG9XttxcWVKDLwH60H9VLbJEPYU53H02i ijJvIQ== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230412_142233_822101_C6F018CB X-CRM114-Status: GOOD ( 14.51 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Reviewed-by: Linus Walleij Reviewed-by: Florian Fainelli Reviewed-by: Tony Lindgren --- arch/arm/boot/compressed/decompress.c | 4 ++-- arch/arm/boot/compressed/misc.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) -- 2.39.2 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 /* for inline */ #include #include +#include #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