arm: mach-keystone: Use appended original image size in image processing
PATCH 1/1 arm: mach-keystone: Use appended original image size in image processing
When an image is signed/encrypted on K2 devices the image may get padded to meet alignment requirements for the signature/encryption type. The original size is appended as 4 bytes little-endian to the end of the final image.
Normally the trailing extra bytes are ignored and so restoring the exact original size is not important. In the case of initrd the original size is important as the kernel uses it to look for additional filesystem data and can do the wrong thing when the size is not correct.
Read off the original size and report it back from the image post processing stage.
--- arch/arm/mach-keystone/mon.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
arch/arm/mach-keystone/mon.c +6 -2
@@ -105,6 +105,7 @@ void board_fit_image_post_process(void **p_image, size_t *p_size) {int result =0 ;void *image = *p_image; +uint8_t *size_image = image + (*p_size -4 );if (strncmp (image +KS2_HS_SEC_TAG_OFFSET ,"KEYS" ,4 )) {printf ("No signature found in image!\n" );
@@ -120,9 +121,12 @@ void board_fit_image_post_process(void **p_image, size_t *p_size)/* * Overwrite the image headers after authentication * and decryption. Update size to reflect removal -* of header. +* of header and restore original file size. */ - *p_size -=KS2_HS_SEC_HEADER_LEN ; + *p_size = *(size_image+0 ) <<0 | + *(size_image+1 ) <<8 | + *(size_image+2 ) <<16 | + *(size_image+3 ) <<24 ;memcpy (image, image +KS2_HS_SEC_HEADER_LEN , *p_size);/*
Signature · 1 line
2.17.1
PATCH 1/1 arm: mach-keystone: Use appended original image size in image processing
Quoted 33 lines · Andrew F. Davis
When an image is signed/encrypted on K2 devices the image may get padded to meet alignment requirements for the signature/encryption type. The original size is appended as 4 bytes little-endian to the end of the final image.
Normally the trailing extra bytes are ignored and so restoring the exact original size is not important. In the case of initrd the original size is important as the kernel uses it to look for additional filesystem data and can do the wrong thing when the size is not correct.
Read off the original size and report it back from the image post processing stage.
Signed-off-by Andrew F. Davis <[email protected]>--- arch/arm/mach-keystone/mon.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)arch/arm/mach-keystone/mon.c +1
-0@@ -105,6 +105,7 @@ void board_fit_image_post_process(void **p_image, size_t *p_size) {int result =0 ;void *image = *p_image; +uint8_t *size_image = image + (*p_size -4 );if (strncmp (image +KS2_HS_SEC_TAG_OFFSET ,"KEYS" ,4 )) {printf ("No signature found in image!\n" );@@ -120,9 +121,12 @@ void board_fit_image_post_process(void **p_image, size_t *p_size)/*
arch/arm/mach-keystone/mon.c void board_fit_image_post_process(void **p_image, size_t *p_size) · line 129
Quoted 10 lines
arch/arm/mach-keystone/mon.c +5
-2* Overwrite the image headers after authentication * and decryption. Update size to reflect removal -* of header. +* of header and restore original file size. */ - *p_size -=KS2_HS_SEC_HEADER_LEN ; + *p_size = *(size_image+0 ) <<0 | + *(size_image+1 ) <<8 | + *(size_image+2 ) <<16 | + *(size_image+3 ) <<24 ;
Instead use get_unaligned_le32(size)?
Thanks and regards,
Lokesh
Quoted 4 lines
arch/arm/mach-keystone/mon.c +0
-0memcpy (image, image +KS2_HS_SEC_HEADER_LEN , *p_size);/*