diff mbox series

[u-boot,1/2] tools: default_image: Verify header size

Message ID 20230129164411.9795-1-pali@kernel.org
State Accepted
Commit 3f837b06b76d06189055a0fcdaee4d31c7758d9e
Delegated to: Tom Rini
Headers show
Series [u-boot,1/2] tools: default_image: Verify header size | expand

Commit Message

Pali Rohár Jan. 29, 2023, 4:44 p.m. UTC
Before reading image header, verify that image size is at least size of
the image header.

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

Comments

Simon Glass Jan. 30, 2023, 3:50 p.m. UTC | #1
On Sun, 29 Jan 2023 at 09:44, Pali Rohár <pali@kernel.org> wrote:
>
> Before reading image header, verify that image size is at least size of
> the image header.
>
> Signed-off-by: Pali Rohár <pali@kernel.org>
> ---
>  tools/default_image.c | 6 ++++++
>  1 file changed, 6 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>
Tom Rini Feb. 7, 2023, 4:52 p.m. UTC | #2
On Sun, Jan 29, 2023 at 05:44:10PM +0100, Pali Rohár wrote:

> Before reading image header, verify that image size is at least size of
> the image header.
> 
> Signed-off-by: Pali Rohár <pali@kernel.org>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/tools/default_image.c b/tools/default_image.c
index 4a067e65862e..4aa9a33241cb 100644
--- a/tools/default_image.c
+++ b/tools/default_image.c
@@ -49,6 +49,12 @@  static int image_verify_header(unsigned char *ptr, int image_size,
 	struct legacy_img_hdr header;
 	struct legacy_img_hdr *hdr = &header;
 
+	if (image_size < sizeof(struct legacy_img_hdr)) {
+		debug("%s: Bad image size: \"%s\" is no valid image\n",
+		      params->cmdname, params->imagefile);
+		return -FDT_ERR_BADSTRUCTURE;
+	}
+
 	/*
 	 * create copy of header so that we can blank out the
 	 * checksum field for checking - this can't be done