aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPali Rohár2021-07-23 11:14:21 +0200
committerStefan Roese2021-07-31 09:49:32 +0200
commit825a2ca023202f73a09660db7a49ac1109917ce8 (patch)
treebccace9fd8fb11ffe27079df26f825a266fe618f
parentb943eee915d79cbbaf7b4fc6c4c40dec4839380a (diff)
tools: kwboot: Check for v1 header size
Too small invalid headers may cause kwboot to crash. Check for header size of v1 images. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de> Reviewed-by: Chris Packham <judge.packham@gmail.com> Tested-by: Chris Packham <judge.packham@gmail.com>
-rw-r--r--tools/kwboot.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/tools/kwboot.c b/tools/kwboot.c
index c0ac4ce19e9..1d32c1b7ad2 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;