aboutsummaryrefslogtreecommitdiff
path: root/tools/kwboot.c
diff options
context:
space:
mode:
authorPali Rohár <pali@kernel.org>2023-01-08 13:42:07 +0100
committerStefan Roese <sr@denx.de>2023-03-01 06:39:17 +0100
commit53ee6ec82744666719f2c9954a013c4397b77be9 (patch)
tree7ab1ec29c00e077447e19c7aed0cc82cbcaa778e /tools/kwboot.c
parent7665ed2fa04e0726e142e13bcd77b738e912357f (diff)
downloadu-boot-53ee6ec82744666719f2c9954a013c4397b77be9.zip
u-boot-53ee6ec82744666719f2c9954a013c4397b77be9.tar.gz
u-boot-53ee6ec82744666719f2c9954a013c4397b77be9.tar.bz2
tools: kwboot: Validate optional kwbimage v1 headers
Before starting parsing of kwbimage, first validate that all optional v1 headers and correct. This prevents kwboot crashes on invalid input. Signed-off-by: Pali Rohár <pali@kernel.org>
Diffstat (limited to 'tools/kwboot.c')
-rw-r--r--tools/kwboot.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/tools/kwboot.c b/tools/kwboot.c
index da84086..c8c7a8d 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -1939,6 +1939,7 @@ static int
kwboot_img_patch(void *img, size_t *size, int baudrate)
{
struct main_hdr_v1 *hdr;
+ struct opt_hdr_v1 *ohdr;
uint32_t srcaddr;
uint8_t csum;
size_t hdrsz;
@@ -1990,6 +1991,13 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)
*size < le32_to_cpu(hdr->srcaddr) + le32_to_cpu(hdr->blocksize))
goto err;
+ for_each_opt_hdr_v1 (ohdr, hdr) {
+ if (!opt_hdr_v1_valid_size(ohdr, (const uint8_t *)hdr + hdrsz)) {
+ fprintf(stderr, "Invalid optional image header\n");
+ goto err;
+ }
+ }
+
/*
* The 32-bit data checksum is optional for UART image. If it is not
* present (checksum detected as invalid) then grow data part of the