From 825a2ca023202f73a09660db7a49ac1109917ce8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pali=20Roh=C3=A1r?= Date: Fri, 23 Jul 2021 11:14:21 +0200 Subject: [PATCH] tools: kwboot: Check for v1 header size MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Too small invalid headers may cause kwboot to crash. Check for header size of v1 images. Signed-off-by: Pali Rohár Reviewed-by: Marek Behún Reviewed-by: Stefan Roese Reviewed-by: Chris Packham Tested-by: Chris Packham --- tools/kwboot.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/kwboot.c b/tools/kwboot.c index c0ac4ce19e..1d32c1b7ad 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -645,6 +645,11 @@ kwboot_img_patch_hdr(void *img, size_t size) else hdrsz = KWBHEADER_V1_SIZE(hdr); + if (size < hdrsz) { + errno = EINVAL; + goto out; + } + csum = kwboot_img_csum8(hdr, hdrsz) - hdr->checksum; if (csum != hdr->checksum) { errno = EINVAL; -- 2.39.5