[PATCH 1/1] lib: validate in-memory LZ4 chunk length
From: Zhiling Zou
Date: Sat Sep 12 2026 - 09:47:42 EST
unlz4() reads the compressed chunk length from an in-memory initrd and
passes it to LZ4_decompress_safe(). It only checks the chunk length
against the allocation size when the input is filled by a callback.
Reject an in-memory chunk that extends past the remaining input before
calling the LZ4 decoder. This prevents malformed initrds from making
the decoder read past the mapped archive.
Fixes: e76e1fdfa8f8 ("lib: add support for LZ4-compressed kernel")
Cc: stable@xxxxxxxxxxxxxxx
Reported-by: VEGA <vega@xxxxxxxxxx>
Assisted-by: LLM
Signed-off-by: Zhiling Zou <zhilinz@xxxxxxxxxx>
---
lib/decompress_unlz4.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/lib/decompress_unlz4.c b/lib/decompress_unlz4.c
index c0dbb3cea915e..86e9aaec04f6d 100644
--- a/lib/decompress_unlz4.c
+++ b/lib/decompress_unlz4.c
@@ -139,6 +139,10 @@ STATIC inline int INIT unlz4(u8 *input, long in_len,
if (!fill) {
inp += 4;
size -= 4;
+ if (chunksize > size) {
+ error("data corrupted");
+ goto exit_2;
+ }
} else {
if (chunksize > LZ4_compressBound(uncomp_chunksize)) {
error("chunk length is longer than allocated");
--
2.43.0