[PATCH 2/4] tools: kwbimage: Verify size of v0 image header

Pali Rohár pali at kernel.org
Wed Aug 11 10:14:15 CEST 2021


Check that extended image header size is not larger than file size.

Signed-off-by: Pali Rohár <pali at kernel.org>
---
 tools/kwbimage.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 80aae8a6b619..84c41210e39e 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -1682,6 +1682,9 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size,
 		if (mhdr->ext & 0x1) {
 			struct ext_hdr_v0 *ext_hdr;
 
+			if (header_size + sizeof(*ext_hdr) > image_size)
+				return -FDT_ERR_BADSTRUCTURE;
+
 			ext_hdr = (struct ext_hdr_v0 *)
 				(ptr + sizeof(struct main_hdr_v0));
 			checksum = image_checksum8(ext_hdr,
-- 
2.20.1



More information about the U-Boot mailing list