Linux s390 Architecture development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Michal Wilczynski" <m.wilczynski@samsung.com>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nick Desaulniers" <ndesaulniers@google.com>,
	"Bill Wendling" <morbo@google.com>,
	"Justin Stitt" <justinstitt@google.com>,
	"Russell King" <linux@armlinux.org.uk>,
	"Thomas Bogendoerfer" <tsbogend@alpha.franken.de>,
	"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
	"Helge Deller" <deller@gmx.de>,
	"Heiko Carstens" <hca@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>,
	"Sven Schnelle" <svens@linux.ibm.com>,
	"Thomas Gleixner" <tglx@kernel.org>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Borislav Petkov" <bp@alien8.de>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	"Minchan Kim" <minchan@kernel.org>,
	"Sergey Senozhatsky" <senozhatsky@chromium.org>,
	"Jens Axboe" <axboe@kernel.dk>,
	"Andrew Morton" <akpm@linux-foundation.org>
Cc: linux-s390@vger.kernel.org,
	"Yann Collet" <yann.collet.73@gmail.com>,
	"Nick Terrell" <terrelln@meta.com>,
	"Gao Xiang" <xiang@kernel.org>, "Chao Yu" <chao@kernel.org>,
	"Jaegeuk Kim" <jaegeuk@kernel.org>,
	"Eric Biggers" <ebiggers@kernel.org>,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	"David Laight" <david.laight.linux@gmail.com>,
	Sungguk <sungguk.na@samsung.com>,
	"Jaehoon Chung" <jh80.chung@samsung.com>,
	"Marek Szyprowski" <m.szyprowski@samsung.com>,
	linux-crypto@vger.kernel.org
Subject: Re: [PATCH v2 01/15] lib/decompress_unlz4: use LZ4_decompress_safe_partial() before boot
Date: Fri, 06 Nov 2026 14:59:23 +0000	[thread overview]
Message-ID: <sashiko-outbox-201633@kernel.org> (raw)
In-Reply-To: <20261106-lz4-vendor-upstream-v2-1-ee04c3f0d7dc@samsung.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] lib/decompress_unlz4: unvalidated chunksize passed to decoder
  in unlz4()
- [Low] lib/decompress_unlz4: partial decode skips full-block checks in
  unlz4()
- [Low] lib/decompress_unlz4: unlz4() does not check out_len == 0 at
  stream end
--

commit 8a11d492456e8edabb6dad4a7ecb828134c99572
Author: Michal Wilczynski <m.wilczynski@samsung.com>

lib/decompress_unlz4: use LZ4_decompress_safe_partial() before boot

This commit replaces LZ4_decompress_fast() with
LZ4_decompress_safe_partial() in the pre-boot unlz4() path and checks that
each chunk produces the expected output size.

> diff --git a/lib/decompress_unlz4.c b/lib/decompress_unlz4.c
> index c0dbb3cea915e..dc20c22e08790 100644
> --- a/lib/decompress_unlz4.c
> +++ b/lib/decompress_unlz4.c
> @@ -151,14 +151,17 @@ STATIC inline int INIT unlz4(u8 *input, long in_len,
>  			}
>  		}
>  #ifdef PREBOOT
> -		if (out_len >= uncomp_chunksize) {
> +		if (out_len >= uncomp_chunksize)
>  			dest_len = uncomp_chunksize;
> -			out_len -= dest_len;
> -		} else
> +		else
>  			dest_len = out_len;
> +		out_len -= dest_len;
>  
> -		ret = LZ4_decompress_fast(inp, outp, dest_len);
> -		chunksize = ret;
> +		ret = LZ4_decompress_safe_partial(inp, outp, chunksize,
> +						  dest_len, dest_len);

[Severity: Medium]
Can a truncated or corrupted chunk header cause LZ4_decompress_safe_partial()
to read past the end of the input buffer?

Previously, LZ4_decompress_fast() ignored chunksize and overwrote it with the
consumed byte count before the !fill path checked size -= chunksize at the
bottom of the loop:

lib/decompress_unlz4.c:unlz4() {
	...
		if (!fill) {
			inp += 4;
			size -= 4;
		} else {
	...
		if (!fill) {
			size -= chunksize;

			if (size == 0)
				break;
			else if (size < 0) {
				error("data corrupted");
				goto exit_2;
			}
			inp += chunksize;
		}
}

Passing chunksize from get_unaligned_le32(inp) directly to
LZ4_decompress_safe_partial() before checking it against size lets the
decoder read past input + in_len when chunksize > size, or pass a negative
compressedSize when chunksize >= 0x80000000.

> +		/* A chunk once the image's stated size is reached is corrupt. */
> +		if (!dest_len || ret != (int)dest_len)
> +			ret = -1;

[Severity: Low]
Should this call LZ4_decompress_safe(inp, outp, chunksize, dest_len) instead
of LZ4_decompress_safe_partial()?

In LZ4_decompress_generic(), partial_decode mode clamps literal runs and
matches that would exceed dest_len and stops as soon as dest_len bytes are
written without verifying that all chunksize input bytes were consumed.  A
corrupted chunk that expands beyond dest_len or leaves trailing bytes inside
chunksize will still return dest_len and pass this check.

[Severity: Low]
Can a truncated image that ends on a chunk boundary still return success when
out_len has not reached zero?

This check rejects chunks that decode short or arrive after out_len reaches
zero, but if the input stream ends early between chunks (or has chunksize ==
0), the loop jumps to exit_3 and returns 0 with out_len > 0.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261106-lz4-vendor-upstream-v2-0-ee04c3f0d7dc@samsung.com?part=1

  reply	other threads:[~2026-11-06 14:59 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20261106144247eucas1p15bdd0704f32d1cb3b19f9d2296a0cbc3@eucas1p1.samsung.com>
2026-11-06 14:42 ` [PATCH v2 00/15] lib/lz4: stop forking upstream LZ4, vendor it instead Michal Wilczynski
2026-11-06 14:42   ` [PATCH v2 01/15] lib/decompress_unlz4: use LZ4_decompress_safe_partial() before boot Michal Wilczynski
2026-11-06 14:59     ` sashiko-bot [this message]
2026-11-06 14:42   ` [PATCH v2 02/15] lib/lz4: remove LZ4_decompress_fast() and its variants Michal Wilczynski
2026-11-06 14:47     ` sashiko-bot
2026-11-06 14:42   ` [PATCH v2 03/15] zram: lz4hc: reset the dictionary stream once, not per page Michal Wilczynski
2026-11-06 14:49     ` sashiko-bot
2026-11-10  5:31       ` Sergey Senozhatsky
2026-11-06 14:42   ` [PATCH v2 04/15] lib/lz4: import upstream LZ4 sources verbatim Michal Wilczynski
2026-11-06 14:48     ` sashiko-bot
2026-11-06 14:42   ` [PATCH v2 05/15] lib/lz4: backport upstream's -Wmissing-prototypes fix Michal Wilczynski
2026-11-06 14:46     ` sashiko-bot
2026-11-06 14:42   ` [PATCH v2 06/15] lib/lz4: backport upstream's aarch64 fast decode loop enablement Michal Wilczynski
2026-11-06 14:47     ` sashiko-bot
2026-11-06 14:42   ` [PATCH v2 07/15] lib/lz4: backport upstream's match length limit fix Michal Wilczynski
2026-11-06 14:50     ` sashiko-bot
2026-11-06 14:42   ` [PATCH v2 08/15] lib/lz4: add the build environment for the vendored sources Michal Wilczynski
2026-11-06 14:57     ` sashiko-bot
2026-11-06 14:42   ` [PATCH v2 09/15] arch: boot: put the LZ4 freestanding headers on the decompressor path Michal Wilczynski
2026-11-06 14:49     ` sashiko-bot
2026-11-06 14:42   ` [PATCH v2 10/15] lib/lz4: switch the compressor to the vendored sources Michal Wilczynski
2026-11-06 14:52     ` sashiko-bot
2026-11-10  5:36     ` Sergey Senozhatsky
2026-11-06 14:42   ` [PATCH v2 11/15] lib/lz4: switch the HC " Michal Wilczynski
2026-11-06 14:54     ` sashiko-bot
2026-11-06 14:42   ` [PATCH v2 12/15] lib/lz4: widen LZ4_DECOMPRESS_INPLACE_MARGIN for the fast decode loop Michal Wilczynski
2026-11-06 14:52     ` sashiko-bot
2026-11-11 22:02     ` Gao Xiang
2026-11-06 14:42   ` [PATCH v2 13/15] lib/lz4: switch the decompressor to the vendored sources Michal Wilczynski
2026-11-06 14:57     ` sashiko-bot
2026-11-10  5:39     ` Sergey Senozhatsky
2026-11-06 14:42   ` [PATCH v2 14/15] lib/lz4: replace lz4_kernel_api.h's prototypes with <linux/lz4.h> Michal Wilczynski
2026-11-06 14:51     ` sashiko-bot
2026-11-06 14:42   ` [PATCH v2 15/15] MAINTAINERS: add an entry for the LZ4 compression library Michal Wilczynski

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=sashiko-outbox-201633@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=agordeev@linux.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=borntraeger@linux.ibm.com \
    --cc=bp@alien8.de \
    --cc=chao@kernel.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=david.laight.linux@gmail.com \
    --cc=deller@gmx.de \
    --cc=ebiggers@kernel.org \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=hpa@zytor.com \
    --cc=jaegeuk@kernel.org \
    --cc=jh80.chung@samsung.com \
    --cc=justinstitt@google.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=m.szyprowski@samsung.com \
    --cc=m.wilczynski@samsung.com \
    --cc=minchan@kernel.org \
    --cc=mingo@redhat.com \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=senozhatsky@chromium.org \
    --cc=sungguk.na@samsung.com \
    --cc=svens@linux.ibm.com \
    --cc=terrelln@meta.com \
    --cc=tglx@kernel.org \
    --cc=tsbogend@alpha.franken.de \
    --cc=x86@kernel.org \
    --cc=xiang@kernel.org \
    --cc=yann.collet.73@gmail.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