]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
tools: kwboot: Check for v1 header size
authorPali Rohár <pali@kernel.org>
Fri, 23 Jul 2021 09:14:21 +0000 (11:14 +0200)
committerStefan Roese <sr@denx.de>
Sat, 31 Jul 2021 07:49:32 +0000 (09:49 +0200)
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>
tools/kwboot.c

index c0ac4ce19e9c396a55cccbaa70337ceb3a7b0bb6..1d32c1b7ad2b814fda5652128bc302a54155e4cb 100644 (file)
@@ -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;