diff mbox series

tools: kwbimage: Fix checksum calculation for v1 images

Message ID 20211225195019.1509965-1-delroth@gmail.com
State Accepted
Commit 9203c73895ab410f7a57f56ec26201253a1f008b
Delegated to: Stefan Roese
Headers show
Series tools: kwbimage: Fix checksum calculation for v1 images | expand

Commit Message

Pierre Bourdon Dec. 25, 2021, 7:50 p.m. UTC
Recent changes caused fields in the image main header to be modified
after the header checksum had already been computed. Move the checksum
computation to once again be the last operation performed on the header.

Fixes: 2b0980c24027 ("tools: kwbimage: Fill the real header size into the main header")

Signed-off-by: Pierre Bourdon <delroth@gmail.com>
---
 tools/kwbimage.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Pali Rohár Dec. 25, 2021, 7:59 p.m. UTC | #1
On Saturday 25 December 2021 20:50:19 Pierre Bourdon wrote:
> Recent changes caused fields in the image main header to be modified
> after the header checksum had already been computed. Move the checksum
> computation to once again be the last operation performed on the header.
> 
> Fixes: 2b0980c24027 ("tools: kwbimage: Fill the real header size into the main header")
> 
> Signed-off-by: Pierre Bourdon <delroth@gmail.com>

Thanks!

Reviewed-by: Pali Rohár <pali@kernel.org>


Stefan and Tom, could you please include this fixup patch into master
branch for upcoming release? During development we broke kwbimage /
mkimage generator and I think it is something which we should have fixed
in upcoming release (if it is not too late now...).

> ---
>  tools/kwbimage.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/kwbimage.c b/tools/kwbimage.c
> index 875f636c7a..0951d7861c 100644
> --- a/tools/kwbimage.c
> +++ b/tools/kwbimage.c
> @@ -1398,9 +1398,6 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,
>  					       headersz, image, secure_hdr))
>  		return NULL;
>  
> -	/* Calculate and set the header checksum */
> -	main_hdr->checksum = image_checksum8(main_hdr, headersz);
> -
>  	*imagesz = headersz;
>  
>  	/* Fill the real header size without padding into the main header */
> @@ -1410,6 +1407,9 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,
>  	main_hdr->headersz_lsb = cpu_to_le16(headersz & 0xFFFF);
>  	main_hdr->headersz_msb = (headersz & 0xFFFF0000) >> 16;
>  
> +	/* Calculate and set the header checksum */
> +	main_hdr->checksum = image_checksum8(main_hdr, headersz);
> +
>  	return image;
>  }
>  
> -- 
> 2.34.0
>
Stefan Roese Jan. 5, 2022, 3:30 p.m. UTC | #2
On 12/25/21 20:50, Pierre Bourdon wrote:
> Recent changes caused fields in the image main header to be modified
> after the header checksum had already been computed. Move the checksum
> computation to once again be the last operation performed on the header.
> 
> Fixes: 2b0980c24027 ("tools: kwbimage: Fill the real header size into the main header")
> 
> Signed-off-by: Pierre Bourdon <delroth@gmail.com>

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

Thanks,
Stefan

> ---
>   tools/kwbimage.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/kwbimage.c b/tools/kwbimage.c
> index 875f636c7a..0951d7861c 100644
> --- a/tools/kwbimage.c
> +++ b/tools/kwbimage.c
> @@ -1398,9 +1398,6 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,
>   					       headersz, image, secure_hdr))
>   		return NULL;
>   
> -	/* Calculate and set the header checksum */
> -	main_hdr->checksum = image_checksum8(main_hdr, headersz);
> -
>   	*imagesz = headersz;
>   
>   	/* Fill the real header size without padding into the main header */
> @@ -1410,6 +1407,9 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,
>   	main_hdr->headersz_lsb = cpu_to_le16(headersz & 0xFFFF);
>   	main_hdr->headersz_msb = (headersz & 0xFFFF0000) >> 16;
>   
> +	/* Calculate and set the header checksum */
> +	main_hdr->checksum = image_checksum8(main_hdr, headersz);
> +
>   	return image;
>   }
>   
> 

Viele Grüße,
Stefan Roese
Stefan Roese Jan. 5, 2022, 5:27 p.m. UTC | #3
On 1/5/22 16:30, Stefan Roese wrote:
> On 12/25/21 20:50, Pierre Bourdon wrote:
>> Recent changes caused fields in the image main header to be modified
>> after the header checksum had already been computed. Move the checksum
>> computation to once again be the last operation performed on the header.
>>
>> Fixes: 2b0980c24027 ("tools: kwbimage: Fill the real header size into 
>> the main header")
>>
>> Signed-off-by: Pierre Bourdon <delroth@gmail.com>
> 
> Reviewed-by: Stefan Roese <sr@denx.de>

Applied to u-boot-marvell/master

Thanks,
Stefan

> Thanks,
> Stefan
> 
>> ---
>>   tools/kwbimage.c | 6 +++---
>>   1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/tools/kwbimage.c b/tools/kwbimage.c
>> index 875f636c7a..0951d7861c 100644
>> --- a/tools/kwbimage.c
>> +++ b/tools/kwbimage.c
>> @@ -1398,9 +1398,6 @@ static void *image_create_v1(size_t *imagesz, 
>> struct image_tool_params *params,
>>                              headersz, image, secure_hdr))
>>           return NULL;
>> -    /* Calculate and set the header checksum */
>> -    main_hdr->checksum = image_checksum8(main_hdr, headersz);
>> -
>>       *imagesz = headersz;
>>       /* Fill the real header size without padding into the main 
>> header */
>> @@ -1410,6 +1407,9 @@ static void *image_create_v1(size_t *imagesz, 
>> struct image_tool_params *params,
>>       main_hdr->headersz_lsb = cpu_to_le16(headersz & 0xFFFF);
>>       main_hdr->headersz_msb = (headersz & 0xFFFF0000) >> 16;
>> +    /* Calculate and set the header checksum */
>> +    main_hdr->checksum = image_checksum8(main_hdr, headersz);
>> +
>>       return image;
>>   }
>>
> 
> Viele Grüße,
> Stefan Roese
> 

Viele Grüße,
Stefan Roese
diff mbox series

Patch

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 875f636c7a..0951d7861c 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -1398,9 +1398,6 @@  static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,
 					       headersz, image, secure_hdr))
 		return NULL;
 
-	/* Calculate and set the header checksum */
-	main_hdr->checksum = image_checksum8(main_hdr, headersz);
-
 	*imagesz = headersz;
 
 	/* Fill the real header size without padding into the main header */
@@ -1410,6 +1407,9 @@  static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,
 	main_hdr->headersz_lsb = cpu_to_le16(headersz & 0xFFFF);
 	main_hdr->headersz_msb = (headersz & 0xFFFF0000) >> 16;
 
+	/* Calculate and set the header checksum */
+	main_hdr->checksum = image_checksum8(main_hdr, headersz);
+
 	return image;
 }