Skip to contentSkip to conversation

arm: imx: fix signature_block_hdr struct fields order

PATCH Superseded Javier Viguera 3 participants 5 messages Mar 26, 2024 – Apr 4, 2024 Arm i.MX and Layerscape

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm: imx: fix signature_block_hdr struct fields order

According to the documentation (for example AN13994), for AHAB-enabled devices the format of the signature block is:

  +--------------+--------------+--------------+-------------+
  | Tag          | Length - msb | Length - lsb | Version     |
  +--------------+--------------+--------------+-------------+
  | SRK Table offset            | Certificate offset         |
  +-----------------------------+----------------------------+
  | Blob offset                 | Signature offset           |
  +-----------------------------+----------------------------+
---
 include/imx_container.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/imx_container.h +2 -2
index 54cd684e35d5..691c764b3e5b 100644
@@ -50,10 +50,10 @@ struct signature_block_hdr {
 	u8 length_lsb;
 	u8 length_msb;
 	u8 tag;
-	u16 srk_table_offset;
 	u16 cert_offset;
-	u16 blob_offset;
+	u16 srk_table_offset;
 	u16 signature_offset;
+	u16 blob_offset;
 	u32 reserved;
 } __packed;
 
reviewer
#1 lore raw

Hi Javier,

Quoted 11 lines · Javier Viguera

According to the documentation (for example AN13994), for AHAB-enabled devices the format of the signature block is:

  +--------------+--------------+--------------+-------------+
  | Tag          | Length - msb | Length - lsb | Version     |
  +--------------+--------------+--------------+-------------+
  | SRK Table offset            | Certificate offset         |
  +-----------------------------+----------------------------+
  | Blob offset                 | Signature offset           |
  +-----------------------------+----------------------------+

Could you elaborate more about this and share more details?

Have you seen a run-time error or did you catch it by code inspection?

Please clarify.

Thanks

#2 lore raw

Hi Fabio,

First, sorry for the delay. I was out of the office (Easter).

-----Original Message-----
From: Fabio Estevam <[email protected]>
Could you elaborate more about this and share more details? Have you seen a run-time error or did you catch it by code inspection?

The struct has the fields in the wrong order according to other documentation from NXP (see for example the AN13994 - Encrypted Boot on AHAB-enabled devices).

In the current upstream u-boot code there is NO runtime error, as those fields are not being used. Only ' get_container_sizeon arch/arm/mach-imx/image-container.c` defines a variable of that type. But then it only uses the "length_lsb" and "length_msb" fiels, which are at the beginning of the struct and thus in the correct position.

On the other hand, we were hit by this problem in some bootloader encryption related code we do in our (as of Digi) BSP. We get the blob offset from the signature block header to read the data encryption key blob and due to the wrong order this patch fixes, we were getting a wrong position of the DEK blob.

Hope this clears it up a bit.

--
Javier Viguera
Software Engineer at Digi International.

reviewer
#3 lore raw

Hi Javier,

Quoted 7 lines · Javier

The struct has the fields in the wrong order according to other documentation from NXP (see for example the AN13994 - Encrypted Boot on AHAB-enabled devices).

In the current upstream u-boot code there is NO runtime error, as those fields are not being used. Only ' get_container_sizeon arch/arm/mach-imx/image-container.c` defines a variable of that type. But then it only uses the "length_lsb" and "length_msb" fiels, which are at the beginning of the struct and thus in the correct position.

On the other hand, we were hit by this problem in some bootloader encryption related code we do in our (as of Digi) BSP. We get the blob offset from the signature block header to read the data encryption key blob and due to the wrong order this patch fixes, we were getting a wrong position of the DEK blob.

Hope this clears it up a bit.

Thanks for the clarification.

Please put all this explanation into the commit log and send a v2.

Thanks

#4 lore raw
In reply to Javier Viguera

+Ye

Quoted 35 lines

Subject: [PATCH] arm: imx: fix signature_block_hdr struct fields order

According to the documentation (for example AN13994), for AHAB-enabled devices the format of the signature block is:

  +--------------+--------------+--------------+-------------+
  | Tag          | Length - msb | Length - lsb | Version     |
  +--------------+--------------+--------------+-------------+
  | SRK Table offset            | Certificate offset         |
  +-----------------------------+----------------------------+
  | Blob offset                 | Signature offset           |
  +-----------------------------+----------------------------+
---
 include/imx_container.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/imx_container.h index renamed from include/imx_container.h +0 -0

54cd684e35d5..691c764b3e5b 100644

include/imx_container.h +2 -2
@@ -50,10 +50,10 @@ struct signature_block_hdr {
 	u8 length_lsb;
 	u8 length_msb;
 	u8 tag;
-	u16 srk_table_offset;
 	u16 cert_offset;
-	u16 blob_offset;
+	u16 srk_table_offset;
 	u16 signature_offset;
+	u16 blob_offset;
 	u32 reserved;
 } __packed;