diff mbox series

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

Message ID 20211111155953.31526-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. 11, 2021, 3:59 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>
---
 arch/arm/mach-mvebu/spl.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Stefan Roese Nov. 15, 2021, 8:52 a.m. UTC | #1
On 11/11/21 16:59, Marek Behún wrote:
> 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>

Some nitpicking comments below...

Other than this:

Reviewed-by: Stefan Roese <sr@denx.de>

> ---
>   arch/arm/mach-mvebu/spl.c | 10 ++++++++++
>   1 file changed, 10 insertions(+)
> 
> diff --git a/arch/arm/mach-mvebu/spl.c b/arch/arm/mach-mvebu/spl.c
> index 73c4b9af3e..71994e44f1 100644
> --- a/arch/arm/mach-mvebu/spl.c
> +++ b/arch/arm/mach-mvebu/spl.c
> @@ -163,6 +163,16 @@ 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 in kwbimage\n");
> +		return -EINVAL;
> +	}
> +
> +	if (mhdr->blocksize <= 4 || mhdr->blocksize % 4 != 0) {
> +		printf("ERROR: Wrong blocksize in kwbimage\n");
> +		return -EINVAL;
> +	}

It might make sense to print the incorrect srcaddr and / or blocksize
in the error case, as this might help the user with solving the problem.

Thanks,
Stefan

> +
>   	spl_image->size = mhdr->blocksize;
>   	spl_image->entry_point = mhdr->execaddr;
>   	spl_image->load_addr = mhdr->destaddr;
> 

Viele Grüße,
Stefan Roese
diff mbox series

Patch

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