arm: mvebu: Check that kwbimage offset and blocksize are valid
authorPali Rohár <pali@kernel.org>
Fri, 14 Jan 2022 13:31:37 +0000 (14:31 +0100)
committerStefan Roese <sr@denx.de>
Thu, 20 Jan 2022 10:35:29 +0000 (11:35 +0100)
There are certain restrictions for kwbimage offset and blocksize.
Validate them.

Signed-off-by: Pali Rohár <pali@kernel.org>
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
arch/arm/mach-mvebu/spl.c

index aada83f..47b64c1 100644 (file)
@@ -162,6 +162,18 @@ int spl_parse_board_header(struct spl_image_info *spl_image,
                spl_image->offset *= 512;
 #endif
 
+       if (spl_image->offset % 4 != 0) {
+               printf("ERROR: Wrong srcaddr (0x%08x) in kwbimage\n",
+                      spl_image->offset);
+               return -EINVAL;
+       }
+
+       if (mhdr->blocksize <= 4 || mhdr->blocksize % 4 != 0) {
+               printf("ERROR: Wrong blocksize (0x%08x) in kwbimage\n",
+                      mhdr->blocksize);
+               return -EINVAL;
+       }
+
        spl_image->size = mhdr->blocksize;
        spl_image->entry_point = mhdr->execaddr;
        spl_image->load_addr = mhdr->destaddr;