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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41A55C05027 for ; Thu, 9 Feb 2023 11:29:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231397AbjBIL32 (ORCPT ); Thu, 9 Feb 2023 06:29:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231388AbjBIL2X (ORCPT ); Thu, 9 Feb 2023 06:28:23 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 501626ADD0; Thu, 9 Feb 2023 03:21:12 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 839E9CE246E; Thu, 9 Feb 2023 11:20:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2FD2C433EF; Thu, 9 Feb 2023 11:19:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675941597; bh=wPOAHH7kPtHNJZ7UF+2yhWXL7e/2Pv2JX/TDaRVF0PA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FiPsq8hIjxi3FvPpE17sJixqTN3Q0JsjKHCoFqR3vovv4sFV3WKUJ9HcZrLNpQIWD MBhW7YuzKCK/eraKFrSB0+nMQ3E5w0EqBVZMOj2msM8vg1LPgp8J6v7rliT9i04z2v ivwuSNrz3yLMAkPDwtat8zIY8XNJEZkJSCwOL6XmUCgzlqeIJkvqWu2pubCRqjZCxW HMILcpM/7r5/EsZHOOG4NmNDEhccjmLTVypdWpu4OGTLb8zO6FnIoukVoNMctopwDQ 2cg1a9h4AoiB3V3D4wgS1kwzs7xUzLOuYI1FehyWKmdafmMLwIFkJtG/JgogcH9IG6 f6JVSk6siw6hQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Vasily Gorbik , Alexander Egorenkov , Heiko Carstens , Sasha Levin , agordeev@linux.ibm.com, terrelln@fb.com, linux-s390@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 09/10] s390/decompressor: specify __decompress() buf len to avoid overflow Date: Thu, 9 Feb 2023 06:19:18 -0500 Message-Id: <20230209111921.1893095-9-sashal@kernel.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230209111921.1893095-1-sashal@kernel.org> References: <20230209111921.1893095-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vasily Gorbik [ Upstream commit 7ab41c2c08a32132ba8c14624910e2fe8ce4ba4b ] Historically calls to __decompress() didn't specify "out_len" parameter on many architectures including s390, expecting that no writes beyond uncompressed kernel image are performed. This has changed since commit 2aa14b1ab2c4 ("zstd: import usptream v1.5.2") which includes zstd library commit 6a7ede3dfccb ("Reduce size of dctx by reutilizing dst buffer (#2751)"). Now zstd decompression code might store literal buffer in the unwritten portion of the destination buffer. Since "out_len" is not set, it is considered to be unlimited and hence free to use for optimization needs. On s390 this might corrupt initrd or ipl report which are often placed right after the decompressor buffer. Luckily the size of uncompressed kernel image is already known to the decompressor, so to avoid the problem simply specify it in the "out_len" parameter. Link: https://github.com/facebook/zstd/commit/6a7ede3dfccb Signed-off-by: Vasily Gorbik Tested-by: Alexander Egorenkov Link: https://lore.kernel.org/r/patch-1.thread-41c676.git-41c676c2d153.your-ad-here.call-01675030179-ext-9637@work.hours Signed-off-by: Heiko Carstens Signed-off-by: Sasha Levin --- arch/s390/boot/compressed/decompressor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/s390/boot/compressed/decompressor.c b/arch/s390/boot/compressed/decompressor.c index 45046630c56ac..c42ab33bd4524 100644 --- a/arch/s390/boot/compressed/decompressor.c +++ b/arch/s390/boot/compressed/decompressor.c @@ -80,6 +80,6 @@ void *decompress_kernel(void) void *output = (void *)decompress_offset; __decompress(_compressed_start, _compressed_end - _compressed_start, - NULL, NULL, output, 0, NULL, error); + NULL, NULL, output, vmlinux.image_size, NULL, error); return output; } -- 2.39.0