diff mbox series

[u-boot-marvell,v2,1/9] arm: mvebu: Check that kwbimage offset and blocksize are valid

Message ID 20211126143738.23830-2-kabel@kernel.org
State Superseded
Delegated to: Stefan Roese
Headers show
Series More verifications for kwbimage in SPL | expand

Commit Message

Marek Behún Nov. 26, 2021, 2:37 p.m. UTC
From: Pali Rohár <pali@kernel.org>

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>
---
Changes since v1:
- updated error messages as requested by Stefan
---
 arch/arm/mach-mvebu/spl.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/arch/arm/mach-mvebu/spl.c b/arch/arm/mach-mvebu/spl.c
index 73c4b9af3e..a6ed4367dd 100644
--- a/arch/arm/mach-mvebu/spl.c
+++ b/arch/arm/mach-mvebu/spl.c
@@ -163,6 +163,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 (%u) in kwbimage\n",
+		       spl_image->offset);
+		return -EINVAL;
+	}
+
+	if (mhdr->blocksize <= 4 || mhdr->blocksize % 4 != 0) {
+		printf("ERROR: Wrong blocksize (%u) in kwbimage\n",
+		       mhdr->blocksize);
+		return -EINVAL;
+	}
+
 	spl_image->size = mhdr->blocksize;
 	spl_image->entry_point = mhdr->execaddr;
 	spl_image->load_addr = mhdr->destaddr;