Secure boot imx6 Invalid IVT structure

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Secure boot imx6 Invalid IVT structure

3,170 Views
rakesh3
Contributor V

Hi team, 

I am getting the below error after signing the kernel image vmlinux_signed.bin ,

U-Boot > hab_auth_img 0x12000000 0x00933348
hab fuse not enabled

Authenticate image from DDR location 0x12000000...
bad magic magic=0x0 length=0xa000 version=0xe1
bad length magic=0x0 length=0xa000 version=0xe1
bad version magic=0x0 length=0xa000 version=0xe1
Error: Invalid IVT structure

Allowed IVT structure:
IVT HDR = 0x4X2000D1
IVT ENTRY = 0xXXXXXXXX
IVT RSV1 = 0x0
IVT DCD = 0x0
IVT BOOT_DATA = 0xXXXXXXXX
IVT SELF = 0xXXXXXXXX
IVT CSF = 0xXXXXXXXX
IVT RSV2 = 0x0
MX6 HORIZON U-Boot >

i have followed the below link to sign the kernel image.

mx6_mx7_secure_boot.txt - doc/imx/habv4/guides/mx6_mx7_secure_boot.txt - U-boot source code (v2021.1...

below is my csf file content.

[Authenticate Data]
# Key slot index used to authenticate the image data
 Verification index = 2
 # Authenticate Start Address, Offset, Length and file
 # Blocks = 0x877ff400 0x00000000 0x0009ec00 "u-boot-dtb.imx"

 Blocks = 0x12000000 0x0 0x00933368 "vmlinuz-pad-ivt.bin"

Please help me to find the issue, any input would be appriciated.

Regards,

Rk

Labels (5)
Tags (1)
0 Kudos
Reply
14 Replies

3,143 Views
Dhruvit
NXP TechSupport
NXP TechSupport

Hi @rakesh3 

I hope you are doing well.
 
Please make sure that you have correctly loaded kernel zimage to load the address.
 
Please try padding the zimage to the next 4kB boundary.
Please refer to 3.1 Padding the image in /doc/imx/habv4/guides/mx6_mx7_secure_boot.txt
 
One can refer to the mentioned document for hab authentication.
 
Thanks & Regards,
Dhruvit Vasavada
0 Kudos
Reply

3,140 Views
rakesh3
Contributor V

Hi Druvit,

thanks for response.

Yes, i have added now the 0x1000 padded bytes at end of zImage and didn't get any hab error events.

Blocks = 0x12000000 0x0 0x00933368 "vmlinuz-pad-ivt.bin"

0x00933368 = size_of_pad_ivt_img.

Used hab_auth_img <load_address> <signed_img_size> <ivt_offset>

signed_img_size = padded_img+ivt+csf .

U-Boot > hab_auth_img 0x12000000 0x009342a8 0x00933348
hab fuse not enabled

Authenticate image from DDR location 0x12000000...

Secure boot disabled

HAB Configuration: 0xf0, HAB State: 0x66

 

--------- HAB Event 1 -----------------
event data:
        0xdb 0x00 0x24 0x42 0x69 0x30 0xe1 0x1d
        0x00 0x04 0x00 0x02 0x40 0x00 0x36 0x06
        0x55 0x55 0x00 0x03 0x00 0x00 0x00 0x00
        0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
        0x00 0x00 0x00 0x01

STS = HAB_WARNING (0x69)
RSN = HAB_ENG_FAIL (0x30)
CTX = HAB_CTX_ENTRY (0xE1)
ENG = HAB_ENG_CAAM (0x1D)

I have signed dtb and initrd img also, and checked all hab status of all images, But i am getting above warning in all hab but not getting any error.

1) How to get rid of this warning ?

2) While botting i am still getting the 

Authenticate image from DDR location 0x12000000... bad magic magic=0x0 length=0xa000 version=0xe1 bad length magic=0x0 length=0xa000 version=0xe1 bad version magic=0x0 length=0xa000 version=0xe1 Error: Invalid IVT structure Allowed IVT structure: IVT HDR = 0x4X2000D1

Using u-boot (2021) kernel(5.10).

Please help me here on this issue/warning.

 

Regards,

Rakesh

 

Tags (3)
0 Kudos
Reply

3,123 Views
Dhruvit
NXP TechSupport
NXP TechSupport

Hi @rakesh3,

I hope you are doing well.

HAB Event warning could be generated due to incorrect implementation of drng self-test in boot ROM.

Please refer to MLK-20950 Run RNG self test for impacted i.MX chips. 

While botting I am still getting the

Authenticate image from DDR location 0x12000000... bad magic magic=0x0 length=0xa000 version=0xe1 bad length magic=0x0 length=0xa000 version=0xe1 bad version magic=0x0 length=0xa000 version=0xe1 Error: Invalid IVT structure Allowed IVT structure: IVT HDR = 0x4X2000D1

[Ans]: This could be due to not signing kernel image and dtb image correctly.

Please make sure that you have used the correct zImage_pad_ivt.bin size in CSF after padding.
and followed the correct steps as mentioned in High Assurance Boot (HAB)

Thanks & Regards,
Dhruvit Vasavada

0 Kudos
Reply

3,115 Views
rakesh3
Contributor V

Hi Druvit,

thanks for reply,

Let me explain , how i am calculating and using the kernel image.

> hexdump -C vmlinuz-5.10.158-cip22+mel2 | tail -n 1
0x00932348

above is the size of my kernel and i have padded to this image(0x1000) and make it 

hexdump -C vmlinuz-pad.bin | tail -n 1
0x00933348

below is my genIVT.pl 

#! /usr/bin/perl -w
use strict;
open(my $out, '>:raw', 'ivt.bin') or die "Unable to open: $!";
print $out pack("V", 0x412000D1); # Signature
print $out pack("V", 0x12000000); # Load Address (*load_address)
print $out pack("V", 0x0); # Reserved
print $out pack("V", 0x0); # DCD pointer
print $out pack("V", 0x0); # Boot Data
print $out pack("V", 0x12933348); # Self Pointer (*ivt)
print $out pack("V", 0x12933368); # CSF Pointer (*csf)
print $out pack("V", 0x0); # Reserved
close($out);

ivt = load_address + size_of_padded_img (0x12000000 + 0x00933348)

CSF = ivt+offset (0x20) = (0x12933348 + 0x20) 

appended the vmlinuz-pad.bin to ivt.bin.

below is the content of my vmlinuz-pad-ivt.bin .

> hexdump -C vmlinuz-pad-ivt..bin 

00932340 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00933340 00 00 00 00 00 00 00 00 d1 00 20 41 00 00 00 12 |.......... A....|
00933350 00 00 00 00 00 00 00 00 00 00 00 00 48 33 93 12 |............H3..|
00933360 68 33 93 12 00 00 00 00 |h3......|
00933368

As we can see the content contain the IVT structure at 0x00933348 and size of vmlinuz-pad-ivt.bin is 0x00933368. 

SO in csf file i have mention Authentication Data as below.

[Authenticate Data]
# Key slot index used to authenticate the image data
Verification index = 2
# Authenticate Start Address, Offset, Length and file

Blocks = 0x12000000 0x0 0x00933368 "vmlinuz-pad-ivt.bin"

followed as below.

Block = <load_address> <offset> <size_of_img(size_of img+pad_ivt)>

and checking the hab_auth_img as below.

loaded the img like 

u-boot>load mmc 3:1 0x12000000 /boot/vmlinuz-pad-ivt-signed.bin

U-Boot > hab_auth_img 0x12000000 009342a8 00933348
hab fuse not enabled

Authenticate image from DDR location 0x12000000...

Secure boot disabled

HAB Configuration: 0xf0, HAB State: 0x66

--------- HAB Event 1 -----------------
event data:
        0xdb 0x00 0x24 0x42 0x69 0x30 0xe1 0x1d
        0x00 0x04 0x00 0x02 0x40 0x00 0x36 0x06
        0x55 0x55 0x00 0x03 0x00 0x00 0x00 0x00
        0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
        0x00 0x00 0x00 0x01

STS = HAB_WARNING (0x69)
RSN = HAB_ENG_FAIL (0x30)
CTX = HAB_CTX_ENTRY (0xE1)
ENG = HAB_ENG_CAAM (0x1D)

No, error but just warning on checking the hab status of kernel img.

Please suggest, if i am wrong anywhere in my followings steps. After loading the kernel image when using 

u-boot > boot 

its again showing the same Invalid IVT structure. Is the kernel image is not loading correctly ot any issue .Please suggest on this .

1) Please point out any mistake here.

2) how to run RNG self test ?

 

Regards,

Rk

0 Kudos
Reply

3,099 Views
Dhruvit
NXP TechSupport
NXP TechSupport

Hi @rakesh3,

I hope you are doing well.

It seems that the Kernel image is not padded correctly, As 0x00933348 does not look to be the next 0x1000 boundary.

In this case, the vmlinuz size is 0x00932348, So the next 0x1000 boundary is 0x00933000.

The correct command to sign the image would be as below.

$ objcopy -I binary -O binary --pad-to 0x933000 --gap-fill=0x00 \
   vmlinuz-5.10.158-cip22+mel2 vmlinuz-pad.bin

 

Thanks & Regards,
Dhruvit Vasavada

 

0 Kudos
Reply

3,044 Views
rakesh3
Contributor V

Thanks Dhruvit for pointing out the padding mistake here.

I have to signed the dtb and initrd.img also, So do we have to pad these images also or without padding bytes we can include these images in the blocks  ?

As below 
Blocks = 0x12000000 0x0 0x00933020 "vmlinuz-new-pad-ivt.bin"
Blocks = 0x18000000 0x0 0x0000d318 "imx6q.dtb"
Blocks = 0x13000000 0x0 0x004989c8 "initrd-img.bin"

2) Can we use  csf_additional_image.txt but created this csf.bin file with what image we can append this csf.bin file. ? ( with vmlinuz file ?) 

Or we can individually create the csf.bin for dtb and initramfs also ?

 

Regards,

Rk

0 Kudos
Reply

3,024 Views
Dhruvit
NXP TechSupport
NXP TechSupport

Hi @rakesh3,

I hope you are doing well.

dtb and initrd.img should not require padding.

Can we use  csf_additional_image.txt but created this csf.bin file with what image we can append this csf.bin file. ? ( with vmlinuz file ?)

[Ans]:  Yes, One can refer to csf_additional_image.txt.

             csf.bin is appended to the kernel image. ( e.g. zImage) 

Please make sure that uboot defconfig contains CONFIG_RNG_SELF_TEST=y.

Thanks & Regards,
Dhruvit Vasavada

0 Kudos
Reply

3,010 Views
rakesh3
Contributor V

Thanks Dhruvit for suggestion.

 

i already have enabled below config 

CONFIG_RNG_SELF_TEST=y

and have this patch also in my uboot code 

https://source.codeaurora.org/external/imx/uboot-imx/commit/drivers/crypto/fsl?h=lf_v2021.04&id=578c...

 

But still getting below warning.

--------- HAB Event 1 -----------------
event data:
        0xdb 0x00 0x24 0x42 0x69 0x30 0xe1 0x1d
        0x00 0x04 0x00 0x02 0x40 0x00 0x36 0x06
        0x55 0x55 0x00 0x03 0x00 0x00 0x00 0x00
        0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
        0x00 0x00 0x00 0x01

 

STS = HAB_WARNING (0x69)
RSN = HAB_ENG_FAIL (0x30)
CTX = HAB_CTX_ENTRY (0xE1)
ENG = HAB_ENG_CAAM (0x1D

How to get rid of this warning any suggestion ? 

How to perform rng_self_test and remove this last warning also?

 

Regards,

Rk

0 Kudos
Reply

3,004 Views
Dhruvit
NXP TechSupport
NXP TechSupport

Hi @rakesh3,

I hope you are doing well.

Does u-boot successfully able to boot the kernel?

Do hab_status commands show similar output?

Please provide me with the silicon revision of the chip, and u-boot logs( which can be seen in the u-boot logs). and the command used to authenticate the kernel image.

How to perform rng_self_test and remove this last warning also?
[Ans]: rng_selt_test runs when enabling CONFIG_RNG_SELF_TEST option.

This issue does not have any real impact on secure Boot flow and does not compromise the security of the device. 

The descriptors used to run the RNG self-test in certain HAB versions of i.MX chips have been constructed incorrectly due to which the RNG self-test fails in CAAM.

Thanks & Regards,
Dhruvit Vasavada

 

 

0 Kudos
Reply

2,996 Views
rakesh3
Contributor V

Hi Dhruvit,

Thanks for your response.

Does u-boot successfully able to boot the kernel?

[Ans] - Yes, I am able to successfully able to boot u-boot and kernel and getting only one same warning.

Do hab_status commands show similar output? 

[Ans] - Yes

Silicon version - 1.6  (CPU: i.MX6D rev1.6 at 792MHz)

Below is the u-boot logs.

Image Type: Freescale IMX Boot Image
Image Ver: 2 (i.MX53/6/7 compatible)
Mode: DCD
Data Size: 610400 Bytes = 596.09 KiB = 0.58 MiB
Load Address: 177ff420
Entry Point: 17800000
HAB Blocks: 0x177ff400 0x00000000 0x00092c00
DCD Blocks: 0x00910000 0x0000002c 0x000002f8

$ hexdump -C vmlinuz-pad.bin | tail -n 1
00933000 

$ hexdump -C vmlinuz-pad-ivt.bin | tail -n 1
00933020 

$  hexdump -C vmlinuz-new-signed.bin | tail -n 1
00933f60

below is content of kernel_genIVT.pl

#! /usr/bin/perl -w

use strict;
open(my $out, '>:raw', 'ivt.bin') or die "Unable to open: $!";
print $out pack("V", 0x402000D1); # Signature
print $out pack("V", 0x12000000); # Load Address (*load_address)
print $out pack("V", 0x0); # Reserved
print $out pack("V", 0x0); # DCD pointer
print $out pack("V", 0x0); # Boot Data
print $out pack("V", 0x12933000); # Self Pointer (*ivt)
print $out pack("V", 0x12933020); # CSF Pointer (*csf)
print $out pack("V", 0x0); # Reserved
close($out);

Command used to Authenticate kernel image is

=>hab_auth_img 0x12000000 0x00933f60 0x00933000

after enabling DEBUG in hab.c i can see correct expected o/p.

U-Boot > hab_auth_img 0x12000000 0x00933f60 0x00933000
hab fuse not enabled

Authenticate image from DDR location 0x12000000...

 

ivt_offset = 0x933000, ivt addr = 0x12933000
ivt entry = 0x12000000, dcd = 0x00000000, csf = 0x12933020
Dumping IVT
12933000: 402000d1 12000000 00000000 00000000    .. @............
12933010: 00000000 12933000 12933020 00000000    .....0.. 0......
Dumping CSF Header
12933020: 425000d4 000c00be 00001703 50000000    ..PB...........P
12933030: 020c00be 01000009 90040000 000c00ca    ................
12933040: 001dc501 e4070000 000c00be 02000009    ................
12933050: e8090000 001400ca 001dc502 3c0d0000    ...............<

If you need any further file info (drivers/crypto/rng_self_test.c) then can tell 

Regards,

Rk

0 Kudos
Reply

2,960 Views
Dhruvit
NXP TechSupport
NXP TechSupport

Hi @rakesh3,

I hope you are doing well.

This warning message was generated by HAB due to incorrect implementation of drng
self test in boot ROM.

There is no method to remove the warning that occurs in the Boot ROM phase.
After implementing the rng_self_test (CONFIG_RNG_SELF_TEST=y) this warning can be ignored in further implementation of security.

Thanks & Regards,
Dhruvit Vasavada

0 Kudos
Reply

2,874 Views
rakesh3
Contributor V

Thanks Dhruvit,

 

Thanks for such good support.

Summary of whole discussion: -

1) 

bad version magic=0x0 length=0xa000 version=0xe1
Error: Invalid IVT structure

Allowed IVT structure:
IVT HDR = 0x4X2000D1
IVT ENTRY = 0xXXXXXX

Solution:- Mostly this error comes because of incorrect address passed during signed signing of img.

1) Mistake :- Calculation of padding bytes to kernel img:

solution :- it should be padded to its nearest 4kb(0x1000) length.

2) Calculation of IVT-offset - 

=>hab_auth_img <load_address> <signed_img_size> <ivt_offset_in_signed_img>

$ hexdump -C signed_img  - search of ivt header (0xd1 00 20 41/41)  ..thats will be ivt-offset in signed image.

Thanks for your support.

 

Regards,

Rk

0 Kudos
Reply

2,850 Views
Dhruvit
NXP TechSupport
NXP TechSupport

Hi @rakesh3,

I hope you are doing well.

can I mark this case as close now?

Thanks & Regards,
Dhruvit Vasavada

0 Kudos
Reply

2,848 Views
rakesh3
Contributor V

Hi Druvit,

 

Yes, you can close this ticket now.

 

Thanks for such great support.

 

Regards,

Rk

0 Kudos
Reply