tools: fit: sign all config image references
PATCH 1/1 tools: fit: sign all config image references
Target-side configuration verification builds the signed-region list from every image-reference property in the selected configuration. Host-side signing still uses either the signature node sign-images property or the legacy kernel/fdt/script default list.
This lets mkimage generate configuration signatures which U-Boot cannot verify when the configuration references other image types, such as firmware, loadables or ramdisk entries. It also lets the host and target disagree when sign-images names only a subset of the configuration images.
Build the host-side signing list from the configuration properties in the same way as target-side verification. This makes signed configurations cover the root node, the configuration node, every referenced image node, and its hash/cipher subnodes, regardless of image type.
Update the signed-configuration documentation to describe the same rule and to stop recommending sign-images as a selection mechanism.
--- doc/board/ti/k3.rst | 10 ++-- doc/usage/fit/beaglebone_vboot.rst | 5 +- doc/usage/fit/sign-configs.rst | 7 ++- doc/usage/fit/signature.rst | 25 ++++----- doc/usage/fit/uefi.rst | 2 - tools/fit_image.c | 12 ++--- tools/image-host.c | 82 ++++++++++++------------------ 7 files changed, 63 insertions(+), 80 deletions(-)
doc/board/ti/k3.rst +4 -6
@@ -546,7 +546,6 @@ corresponding configuration node as follows. signature-1 { algo = "sha512,rsa4096"; key-name-hint = "custMpk"; - sign-images = "kernel", "fdt"; }; }; # Optional configurations
@@ -557,14 +556,13 @@ corresponding configuration node as follows. signature-1 { algo = "sha512,rsa4096"; key-name-hint = "custMpk"; - sign-images = "fdt"; }; }; -Specify all images you need the signature to authenticate as a part of -sign-images. The key-name-hint needs to be changed if you are using some -other key other than the TI dummy key that we are using for this example. -It should be the name of the file containing the keys. +Signed configurations authenticate all images referenced by the configuration +node. The key-name-hint needs to be changed if you are using some other key +other than the TI dummy key that we are using for this example. It should be +the name of the file containing the keys. .. note::
doc/usage/fit/beaglebone_vboot.rst +2 -3
@@ -169,7 +169,6 @@ Put this into a file in that directory called sign.its:: signature-1 { algo = "sha256,rsa2048"; key-name-hint = "dev"; - sign-images = "fdt", "kernel"; }; }; };
@@ -178,7 +177,8 @@ Put this into a file in that directory called sign.its:: The explanation for this is all in the documentation you have already read. But briefly it packages a kernel and device tree, and provides a single -configuration to be signed with a key named 'dev'. The kernel is compressed +configuration to be signed with a key named 'dev'. The configuration signature +covers all images referenced by the configuration. The kernel is compressed with LZO to make it smaller.
@@ -407,7 +407,6 @@ First we can check which nodes are actually hashed by the configuration:: value algo key-name-hint - sign-images $ fdtget image.fit /configurations/conf-1/signature-1 hashed-nodes / /configurations/conf-1 /images/fdt-1 /images/fdt-1/hash /images/kernel /images/kernel/hash-1
doc/usage/fit/sign-configs.rst +6 -1
@@ -45,8 +45,13 @@ Signed configurations signature { algo = "sha256,rsa2048"; key-name-hint = "dev"; - sign-images = "fdt", "kernel"; }; }; }; }; + +For signed configurations, mkimage signs every image referenced by the +configuration node, such as ``kernel``, ``fdt``, ``ramdisk``, ``firmware`` and +``loadables`` entries. No ``sign-images`` property is required. Older FIT +source files may still include ``sign-images``, but current mkimage and U-Boot +verification do not use it to limit the signed image list.
doc/usage/fit/signature.rst +13 -12
@@ -341,25 +341,26 @@ So the above example is adjusted to look like this:: You can see that we have added hashes for all images (since they are no longer signed), and a signature to each configuration. In the above example, -mkimage will sign configurations/conf-1, the kernel and fdt that are -pointed to by the configuration (/images/kernel-1, /images/kernel-1/hash-1, -/images/fdt-1, /images/fdt-1/hash-1) and the root structure of the image -(so that it isn't possible to add or remove root nodes). The signature is -written into /configurations/conf-1/signature-1/value. It can easily be -verified later even if the FIT has been signed with other keys in the -meantime. +mkimage will sign configurations/conf-1, every image referenced by that +configuration (kernel, fdt, ramdisk, firmware, loadables, etc.) and the root +structure of the image (so that it isn't possible to add or remove root +nodes). The signature is written into +/configurations/conf-1/signature-1/value. It can easily be verified later +even if the FIT has been signed with other keys in the meantime. Details ------- The signature node contains a property ('hashed-nodes') which lists all the -nodes that the signature was made over. The signer (mkimage) writes this -property as a record of what was included in the hash. During verification, +nodes that the signature was made over. The signer (mkimage) writes this +property as a record of what was included in the hash. During verification, however, U-Boot does not read 'hashed-nodes'. Instead it rebuilds the node list from the configuration's own image references (kernel, fdt, ramdisk, -etc.), since 'hashed-nodes' is not itself covered by the signature. The -rebuilt list always includes the root node, the configuration node, each -referenced image node and its hash/cipher subnodes. +firmware, loadables, etc.), since 'hashed-nodes' is not itself covered by the +signature. The rebuilt list always includes the root node, the configuration +node, each referenced image node and its hash/cipher subnodes. Current mkimage +uses the same rule when signing configurations. The older 'sign-images' +property is not required and is not used to limit the signed image list. The image is walked in order and each tag processed as follows:
doc/usage/fit/uefi.rst +0 -2
@@ -55,7 +55,6 @@ relies on the FDT provided by the board emulator. signature-1 { algo = "sha256,rsa2048"; key-name-hint = "dev"; - sign-images = "kernel", "fdt"; }; };
@@ -65,7 +64,6 @@ relies on the FDT provided by the board emulator. signature-1 { algo = "sha256,rsa2048"; key-name-hint = "dev"; - sign-images = "kernel"; }; }; };
tools/fit_image.c +5 -7
@@ -60,13 +60,11 @@ static int fit_estimate_hash_sig_size(struct image_tool_params *params, const ch* FDT by fit_image_process_verity(). * * One could try to be more precise in the estimates by -* looking at the "algo" property and, in the case of -* configuration signatures, the sign-images property. Also, -* when signing an already created FIT image, the hash nodes -* already have properly sized value properties, so one could -* also take pre-existence of "value" properties in hash nodes -* into account. But this rather simple approach should work -* well enough in practice. +* looking at the "algo" property. Also, when signing an already +* created FIT image, the hash nodes already have properly sized value +* properties, so one could also take pre-existence of "value" +* properties in hash nodes into account. But this rather simple +* approach should work well enough in practice. */ for (depth = 0, noffset = fdt_next_node(fdt, 0, &depth); noffset >= 0 && depth > 0;
tools/image-host.c +33 -49
114 lines not on this page · raw message
Signature · 1 line
2.53.0
Hi James,
Quoted 31 lines · James Hilliard
tools: fit: sign all config image references
Target-side configuration verification builds the signed-region list from every image-reference property in the selected configuration. Host-side signing still uses either the signature node sign-images property or the legacy
kernel/fdt/scriptdefault list.This lets mkimage generate configuration signatures which U-Boot cannot verify when the configuration references other image types, such as firmware, loadables or ramdisk entries. It also lets the host and target disagree when sign-images names only a subset of the configuration images.
Build the host-side signing list from the configuration properties in the same way as target-side verification. This makes signed configurations cover the root node, the configuration node, every referenced image node, and its hash/cipher subnodes, regardless of image type.
Update the signed-configuration documentation to describe the same rule and to stop recommending sign-images as a selection mechanism.
[...]
doc/board/ti/k3.rst| 10 ++---doc/usage/fit/beaglebone_vboot.rst | 5 +-- doc/usage/fit/sign-configs.rst | 7 +++- doc/usage/fit/signature.rst | 25 ++++++------ doc/usage/fit/uefi.rst | 2 - tools/fit_image.c | 12 +++--- tools/image-host.c | 82 +++++++++++++++----------------------- 7 files changed, 63 insertions(+), 80 deletions(-)
Quoted 4 lines
Build the host-side signing list from the configuration properties in the same way as target-side verification. This makes signed configurations cover the root node, the configuration node, every referenced image node, and its hash/cipher subnodes, regardless of image type.
Since you are changing mkimage behaviour you may need a test. The existing vboot .its files only reference kernel and fdt, so nothing checks that a ramdisk, firmware or loadables entry is covered by the signature. Please can you extend one of the sign-configs .its files (or add a new one) with such an entry and check the resulting hashed-nodes, or that tampering with the extra image is detected? It may be worth keeping one file with sign-images present, to confirm it is ignored, and dropping it from the others.
I did check that signing and fit_check_sign work with a ramdisk entry, and that the existing check in fit_image.c still catches dangling image references, so the silent continue on a missing image node is fine.
tools/image-host.c static int strlist_add(struct strlist *list, const char *str) · line 1167
Quoted 8 lines
tools/image-host.c +0
-6@@ -1162,27 +1162,6 @@ static int strlist_add(struct strlist *list, const char *str) -/* If there is an 'sign-image' property, use that */ - prop =fdt_getprop (fit, noffset,'sign-images' , lenp); -if (prop) { - *allow_missingp =0 ; -return *lenp ? prop :NULL ; - }
With this gone, sign-images is silently ignored, so anyone using it to sign a subset gets a different signature with no indication of why. Please can you add a one-line warning from mkimage when the property is present, to help people migrate?
tools/image-host.c static int fit_config_get_hash_list(const void *fit, int conf_noffset, · line 1290
Quoted 7 lines
tools/image-host.c +5
-0@@ -1306,34 +1286,38 @@ static int fit_config_get_hash_list(const void *fit, int conf_noffset, +/* Skip properties that are not image references */ +if (!strcmp (prop_name,FIT_DESC_PROP ) || + !strcmp (prop_name,FIT_COMPAT_PROP ) || + !strcmp (prop_name,FIT_DEFAULT_PROP )) +continue ;
This skip list duplicates the one in fit_config_get_hash_list() in boot/image-fit-sig.c and any drift between the two breaks verification, which is exactly the bug this patch fixes. Please can you put the list in one place, e.g. a shared array or helper declared in image.h? BTW the comment on the target-side function mentions 'load-only' being skipped, but neither implementation does that, so that needs fixing too.
doc/usage/fit/sign-configs.rst Signed configurations · line 49
Quoted 7 lines
doc/usage/fit/sign-configs.rst +5
-0@@ -45,8 +45,13 @@ Signed configurations +For signed configurations, mkimage signs every image referenced by the +configuration node, such as `kernel, fdt, ramdisk, firmware and +loadables entries. No sign-images property is required. Older FIT +source files may still include sign-images`, but current mkimage and U-Boot +verification do not use it to limit the signed image list.
Please can you also mention that every referenced image must have at least one hash subnode? Images outside the old default list (e.g. loadables without hashes) previously signed fine, but fit_config_add_hash() now fails with -ENOMSG for them, so this is a new requirement on existing source files.
Regards,
Simon