For a compressed kernel_noload image, bootm_load_os() allocates a decompression buffer of ALIGN(image_len * 4, SZ_1M) and then passes CONFIG_SYS_BOOTM_LEN (typically 128 MiB on arm64) to image_decomp() as the output limit. The decompressors honour whatever limit they are given, so a kernel that decompresses to more than four times its compressed size runs past the end of the allocated buffer and silently corrupts adjacent memory.
A 4x compression ratio is at the edge of what modern compressors (zstd, xz) achieve on real kernels, and is trivially exceeded by crafted, highly compressible payloads, so this is reachable both accidentally and intentionally. The overflow can land on already-loaded boot artefacts (FDT, ramdisk, loadables), U-Boot's own data, or memory-mapped device registers; the existing post-decompression overlap check in bootm_load_os() only catches overlap with the FIT itself. Patch 1 plumbs the actual allocation size through to image_decomp() and handle_decomp_error() via a single decomp_len variable, so decompression stops at the buffer boundary and fails cleanly when the image is too large. The non-noload code path is unchanged and continues to use CONFIG_SYS_BOOTM_LEN. A clarifying note is printed when the failure is gated by the per-image buffer, so the generic "increase CONFIG_SYS_BOOTM_LEN" advice does not mislead. Patch 2 adds two sandbox py-tests against the per-image buffer: one that exceeds the buffer and must be rejected, and one that matches the buffer exactly and must succeed (guarding the boundary). Patch 3 raises the noload-decompression headroom from 4x to 8x. The 4x factor is at the edge of what zstd and xz achieve on real kernels, so well-compressed vendor kernels can fail to boot at runtime once the bound is enforced. 8x covers them comfortably while remaining bounded. The matching references in patch 2's regression tests are updated to the new bound in the same commit so every patch in the series is internally consistent. Tested on sandbox: both new tests pass; the existing test_fit_compressed_images_load (which covers the load-address path) and the other tests in test/py/tests/test_fit.py continue to pass. Changes in v2: - Patch 1: also print the per-image buffer size from bootm_load_os() when the failure is gated by the noload buffer, so handle_decomp_error()'s generic "increase CONFIG_SYS_BOOTM_LEN" advice does not mislead. - Patch 2: add a second sandbox test covering the buffer-limit boundary, in addition to the existing overflow test. - New patch 3: raise the noload-decompression headroom from 4x to 8x so well-compressed kernels do not have to bisect to find out why their board stopped booting; the same commit also updates the regression test references so each patch stays self-consistent. Aristo Chen (3): bootm: fix overflow of the noload kernel decompression buffer test/py: test kernel_noload decompression buffer overflow bootm: increase kernel_noload decompression headroom from 4x to 8x boot/bootm.c | 18 +++--- test/py/tests/test_fit.py | 126 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+), 7 deletions(-) -- 2.43.0

