boot: Add fit_config_get_hash_list() to build signed node list
PATCH v2 1/1 boot: Add fit_config_get_hash_list() to build signed node list
From: Simon Glass <[email protected]>
The hashed-nodes property in a FIT signature node lists which FDT paths are included in the signature hash. It is intended as a hint so should not be used for verification.
Add a function to build the node list from scratch by iterating the configuration's image references. Skip properties known not to be image references. For each image, collect the path plus all hash and cipher subnodes.
Use the new function in fit_config_check_sig() instead of reading 'hashed-nodes'.
Update the test_vboot kernel@ test case: fit_check_sign now catches the attack at signature-verification time (the @-suffixed node is hashed instead of the real one, causing a mismatch) rather than at fit_check_format() time.
Update the docs to cover this. The FIT spec can be updated separately.
---
Changes in v2:
- Update messages for a test case
boot/image-fit-sig.c | 227 +++++++++++++++++++++++++++++------- doc/usage/fit/signature.rst | 19 ++- test/py/tests/test_vboot.py | 8 +- 3 files changed, 201 insertions(+), 53 deletions(-)
boot/image-fit-sig.c +182 -45
@@ -18,6 +18,7 @@ DECLARE_GLOBAL_DATA_PTR;#include <u-boot/hash-checksum.h> #define IMAGE_MAX_HASHED_NODES 100 +#define FIT_MAX_HASH_PATH_BUF 4096/** * fit_region_make_list() - Make a list of image regions
@@ -229,6 +230,179 @@ int fit_image_verify_required_sigs(const void *fit, int image_noffset,return 0 ; } +/** +* fit_config_add_hash() - Add hash nodes for one image to the node list +* +* Adds the image path, all its hash-* subnode paths, and its cipher +* subnode path (if present) to the packed buffer. +* +* @fit: FIT blob +* @image_noffset: Image node offset (e.g. /images/kernel-1) +* @node_inc: Array of path pointers to fill +* @count: Pointer to current count (updated on return) +* @max_nodes: Maximum entries in @node_inc +* @buf: Buffer for packed path strings +* @buf_used: Pointer to bytes used in @buf (updated on return) +* @buf_len: Total size of @buf +* Return: 0 on success, -ve on error +*/ +static int fit_config_add_hash (const void *fit,int image_noffset, +char **node_inc,int *count,int max_nodes, +char *buf,int *buf_used,int buf_len) +{ +int noffset, hash_count, ret, len; + +if (*count >= max_nodes) +return -ENOSPC ; + + ret =fdt_get_path (fit, image_noffset, buf + *buf_used, + buf_len - *buf_used); +if (ret <0 ) +return -ENOENT ; + len =strlen (buf + *buf_used) +1 ; + node_inc[(*count)++] = buf + *buf_used; + *buf_used += len; + +/* Add all this image's hash subnodes */ + hash_count =0 ; +for (noffset =fdt_first_subnode (fit, image_noffset); + noffset >=0 ; + noffset =fdt_next_subnode (fit, noffset)) { +const char *name =fit_get_name (fit, noffset,NULL ); + +if (strncmp (name,FIT_HASH_NODENAME , +strlen (FIT_HASH_NODENAME ))) +continue ; +if (*count >= max_nodes) +return -ENOSPC ; + ret =fdt_get_path (fit, noffset, buf + *buf_used, + buf_len - *buf_used); +if (ret <0 ) +return -ENOENT ; + len =strlen (buf + *buf_used) +1 ; + node_inc[(*count)++] = buf + *buf_used; + *buf_used += len; + hash_count++; + } + +if (!hash_count) { +printf ("No hash nodes in image '%s'\n" , +fdt_get_name (fit, image_noffset,NULL )); +return -ENOMSG ; + } + +/* Add this image's cipher node if present */ + noffset =fdt_subnode_offset (fit, image_noffset,FIT_CIPHER_NODENAME ); +if (noffset != -FDT_ERR_NOTFOUND ) { +if (noffset <0 ) +return -EIO ; +if (*count >= max_nodes) +return -ENOSPC ; + ret =fdt_get_path (fit, noffset, buf + *buf_used, + buf_len - *buf_used); +if (ret <0 ) +return -ENOENT ; + len =strlen (buf + *buf_used) +1 ; + node_inc[(*count)++] = buf + *buf_used; + *buf_used += len; + } + +return 0 ; +} + +/** +* fit_config_get_hash_list() - Build the list of nodes to hash +* +* Works through every image referenced by the configuration and collects the +* node paths: root + config + all referenced images with their hash and +* cipher subnodes. +* +* Properties known not to be image references (description, compatible, +* default, load-only) are skipped, so any new image type is covered by default. +* +* @fit: FIT blob +* @conf_noffset: Configuration node offset +* @node_inc: Array to fill with path string pointers +* @max_nodes: Size of @node_inc array +* @buf: Buffer for packed null-terminated path strings +* @buf_len: Size of @buf +* Return: number of entries in @node_inc, or -ve on error +*/ +static int fit_config_get_hash_list (const void *fit,int conf_noffset, +char **node_inc,int max_nodes, +char *buf,int buf_len) +{ +const char *conf_name; +int image_count; +int prop_offset; +int used =0 ; +int count =0 ; +int ret, len; + + conf_name =fit_get_name (fit, conf_noffset,NULL ); + +/* Always include the root node and the configuration node */ +if (max_nodes <2 ) +return -ENOSPC ; + + len =2 ;/* "/" + nul */ +if (len > buf_len) +return -ENOSPC ; +strcpy (buf,"/" ); + node_inc[count++] = buf; + used += len; + + len =snprintf (buf + used, buf_len - used,"%s/%s" ,FIT_CONFS_PATH , + conf_name) +1 ; +if (used + len > buf_len) +return -ENOSPC ; + node_inc[count++] = buf + used; + used += len; + +/* Process each image referenced by the config */ + image_count =0 ; +fdt_for_each_property_offset (prop_offset, fit, conf_noffset) { +const char *prop_name; +int img_count, i; + +fdt_getprop_by_offset (fit, prop_offset, &prop_name,NULL ); +if (!prop_name) +continue ; + +/* 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 ; + + img_count =fdt_stringlist_count (fit, conf_noffset, prop_name); +for (i =0 ; i < img_count; i++) { +int noffset; + + noffset =fit_conf_get_prop_node_index (fit, + conf_noffset, + prop_name, i); +if (noffset <0 ) +continue ; + + ret =fit_config_add_hash (fit, noffset, node_inc, + &count, max_nodes, buf, &used, + buf_len); +if (ret <0 ) +return ret; + + image_count++; + } + } + +if (!image_count) { +printf ("No images in config '%s'\n" , conf_name); +return -ENOMSG ; + } + +return count; +} +/** * fit_config_check_sig() - Check the signature of a config *
@@ -269,20 +443,16 @@ static int fit_config_check_sig(const void *fit, int noffset, int conf_noffset,FIT_DATA_POSITION_PROP , FIT_DATA_OFFSET_PROP, }; - -const char *prop, *end, *name; +char *node_inc[IMAGE_MAX_HASHED_NODES ]; +char hash_buf[FIT_MAX_HASH_PATH_BUF ];struct image_sign_info info;const uint32_t *strings; -const char *config_name;uint8_t *fit_value;int fit_value_len; -bool found_config;int max_regions; -int i, prop_len;char path[200 ];int count; - config_name =fit_get_name (fit, conf_noffset,NULL );debug ("%s: fdt=%p, conf='%s', sig='%s'\n" , __func__, key_blob,fit_get_name (fit, noffset,NULL ),fit_get_name (key_blob, required_keynode,NULL ));
@@ -297,45 +467,12 @@ static int fit_config_check_sig(const void *fit, int noffset, int conf_noffset,return -1 ; } -/* Count the number of strings in the property */ - prop =fdt_getprop (fit, noffset,"hashed-nodes" , &prop_len); - end = prop ? prop + prop_len : prop; -for (name = prop, count =0 ; name < end; name++) -if (!*name) - count++; -if (!count) { - *err_msgp ="Can't get hashed-nodes property" ; -return -1 ; - } - -if (prop && prop_len >0 && prop[prop_len -1 ] !='\0' ) { - *err_msgp ="hashed-nodes property must be null-terminated" ; -return -1 ; - } - -/* Add a sanity check here since we are using the stack */ -if (count >IMAGE_MAX_HASHED_NODES ) { - *err_msgp ="Number of hashed nodes exceeds maximum" ; -return -1 ; - } - -/* Create a list of node names from those strings */ -char *node_inc[count]; - -debug ("Hash nodes (%d):\n" , count); - found_config = false; -for (name = prop, i =0 ; name < end; name +=strlen (name) +1 , i++) { -debug (" '%s'\n" , name); - node_inc[i] = (char *)name; -if (!strncmp (FIT_CONFS_PATH , name,strlen (FIT_CONFS_PATH )) && - name[sizeof (FIT_CONFS_PATH ) -1 ] =='/' && - !strcmp (name +sizeof (FIT_CONFS_PATH ), config_name)) { -debug (" (found config node %s)" , config_name); - found_config = true; - } - } -if (!found_config) { - *err_msgp ="Selected config not in hashed nodes" ; +/* Build the node list from the config, ignoring hashed-nodes */ + count =fit_config_get_hash_list (fit, conf_noffset, + node_inc,IMAGE_MAX_HASHED_NODES , + hash_buf,sizeof (hash_buf)); +if (count <0 ) { + *err_msgp ="Failed to build hash node list" ;return -1 ; }
doc/usage/fit/signature.rst +13 -6
@@ -353,20 +353,27 @@ meantime. Details ------- The signature node contains a property ('hashed-nodes') which lists all the -nodes that the signature was made over. The image is walked in order and each -tag processed as follows: +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. + +The image is walked in order and each tag processed as follows: DTB_BEGIN_NODE The tag and the following name are included in the signature - if the node or its parent are present in 'hashed-nodes' + if the node or its parent are present in the node list DTB_END_NODE The tag is included in the signature if the node or its parent - are present in 'hashed-nodes' + are present in the node list DTB_PROPERTY The tag, the length word, the offset in the string table, and - the data are all included if the current node is present in 'hashed-nodes' + the data are all included if the current node is present in the node list and the property name is not 'data'. DTB_END
@@ -374,7 +381,7 @@ DTB_END DTB_NOP The tag is included in the signature if the current node is present - in 'hashed-nodes' + in the node list In addition, the signature contains a property 'hashed-strings' which contains the offset and length in the string table of the strings that are to be
test/py/tests/test_vboot.py +6 -2
@@ -362,10 +362,14 @@ def test_vboot(ubman, name, sha_algo, padding, sign_options, required, shutil.copyfile(fit, efit) vboot_evil.add_evil_node(fit, efit, evil_kernel, 'kernel@') - msg = 'Signature checking prevents use of unit addresses (@) in nodes' + # fit_check_sign catches this via signature mismatch (the @ + # node is hashed instead of the real one) utils.run_and_log_expect_exception( ubman, [fit_check_sign, '-f', efit, '-k', dtb], - 1, msg) + 1, 'Failed to verify required signature') + + # bootm catches it earlier, at fit_check_format() time + msg = 'Signature checking prevents use of unit addresses (@) in nodes' run_bootm(sha_algo, 'evil kernel@', msg, False, efit) # Create a new properly signed fit and replace header bytes
Signature · 4 lines
2.43.0 base-commit: c0ca147ac6228949a6d6497531c9f2f4a0dc6c67 branch: fitg2
Quoted 14 lines · Simon Glass
From: Simon Glass <[email protected]>
The hashed-nodes property in a FIT signature node lists which FDT paths are included in the signature hash. It is intended as a hint so should not be used for verification.
Add a function to build the node list from scratch by iterating the configuration's image references. Skip properties known not to be image references. For each image, collect the path plus all hash and cipher subnodes.
Use the new function in
fit_config_check_sig()instead of reading 'hashed-nodes'.
Quoted 8 lines
Update the
test_vbootkernel@ test case:fit_check_signnow catches the attack at signature-verification time (the @-suffixed node is hashed instead of the real one, causing a mismatch) rather than atfit_check_format()time.Update the docs to cover this. The FIT spec can be updated separately.
Signed-off-by Simon Glass <[email protected]>
Thanks again for looking in to this!
Signature · 1 line
Tom
Hi Tom,
Quoted 24 lines · Tom Rini
Quoted 21 lines · Simon Glass
From: Simon Glass <[email protected]>
The hashed-nodes property in a FIT signature node lists which FDT paths are included in the signature hash. It is intended as a hint so should not be used for verification.
Add a function to build the node list from scratch by iterating the configuration's image references. Skip properties known not to be image references. For each image, collect the path plus all hash and cipher subnodes.
Use the new function in
fit_config_check_sig()instead of reading 'hashed-nodes'.Update the
test_vbootkernel@ test case:fit_check_signnow catches the attack at signature-verification time (the @-suffixed node is hashed instead of the real one, causing a mismatch) rather than atfit_check_format()time.Update the docs to cover this. The FIT spec can be updated separately.
Quoted 7 lines
Quoted 1 line
Signed-off-by Simon Glass <[email protected]>Thanks again for looking in to this!
Reported-by Apple Security Engineering and Architecture (SEAR)Tested-by Tom Rini <[email protected]>
OK good!
- Simon
Quoted 10 lines · Simon Glass
The hashed-nodes property in a FIT signature node lists which FDT paths are included in the signature hash. It is intended as a hint so should not be used for verification.
Add a function to build the node list from scratch by iterating the configuration's image references. Skip properties known not to be image references. For each image, collect the path plus all hash and cipher subnodes.
[...]
Applied to u-boot/master, thanks!
[1/1] boot: Add fit_config_get_hash_list() to build signed node list
commit: 2092322b31cc8b1f8c9e2e238d1043ae0637b241
Signature · 1 line
Tom
Quoted 6 lines · Simon Glass
From: Simon Glass <[email protected]>
The hashed-nodes property in a FIT signature node lists which FDT paths are included in the signature hash. It is intended as a hint so should not be used for verification.
Quoted 7 lines
Add a function to build the node list from scratch by iterating the configuration's image references. Skip properties known not to be image references. For each image, collect the path plus all hash and cipher subnodes.
Use the new function in
fit_config_check_sig()instead of reading 'hashed-nodes'.
While growing more grey hair trying to wrap my head around this I found a mean trap. mkimage reads a 'sign-images' property to determine which images to include in the hash regions. Without that property only kernel, fdt and script properties are included at image generation time (see fit_config_get_image_list()).
The new verification code works without such a weird hardcoded list. So as soon as a FIT image has e.g. a ramdisk and it's not listed in 'sign- images' the verification fails.
Review
Quoted 3 lines
(quoted diff) +3
-0+static int fit_config_add_hash(const void *fit, int image_noffset, + char **node_inc, int *count, int max_nodes, + char *buf, int *buf_used, int buf_len)
Took me a while to figure out that a function with the same name is also in tools/image-host.c. Might make sense to pick a different one :- )
cu
Ludwig
Signature · 3 lines
Ludwig Nussel Siemens AG www.siemens.com
From 0000cb8640c46cfddbe4393053609510b25ba82f Mon Sep 17 00:00:00 2001
From: Ludwig Nussel <[email protected]>
Date: Mon, 9 Mar 2026 18:13:47 +0100
Subject: [PATCH] machbunt
To: [email protected]
--- boot/image-fit-sig.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
boot/image-fit-sig.c +38 -0
@@ -2,10 +2,12 @@/* * Copyright (c) 2013, Google Inc. */ +#define LOG_DEBUG #ifdef USE_HOSTCC #include "mkimage.h" #include <time.h> +#include <ctype.h> #else #include <log.h> #include <malloc.h>
@@ -54,12 +56,47 @@ struct image_region *fit_region_make_list(const void *fit,if (!region)return NULL ;for (i =0 ; i < count; i++) { +debug ("\e[04%dm" , i%5 +1 );debug ("%10x %10x\n" , fdt_regions[i].offset, fdt_regions[i].size); +debug ("\e[m" ); region[i].data = fit + fdt_regions[i].offset; region[i].size = fdt_regions[i].size; } +#ifdef USE_HOSTCC + i =0 ; +unsigned o =0 ; +while (o <fdt_totalsize (fit)) { +if (o%16 ==0 )printf ("%08x:" , o); +if (o%2 ==0 )printf (" " ); +printf ("%02hhx" , ((const char *)fit)[o]); + ++o; +if (o && o%16 ==0 ) { +printf (" " ); +int on =0 ; +for (const char * h = fit+o-16 ; (void *)h < fit+o; ++h) { +if (i < count && (void *)h == region[i].data + region[i].size ) { +printf ("\e[m" ); + on =0 ; + ++i; + } +if (i < count && (void *)h >= region[i].data) { +if (!on) { +printf ("\e[04%dm" , i%5 +1 ); + on =1 ; + } + } +if (isprint (*h))printf ("%c" , *h); +else printf ("." ); + } +if (on)printf ("\e[m" ); +printf ("\n" ); + } + } +printf ("\n" ); +#endif +return region; }
@@ -385,6 +422,7 @@ static int fit_config_get_hash_list(const void *fit, int conf_noffset,if (noffset <0 )continue ; +printf ("adding hash for %s\n" , prop_name); ret =fit_config_add_hash (fit, noffset, node_inc, &count, max_nodes, buf, &used, buf_len);
Signature · 1 line
2.43.0
Hi Ludwig,
Quoted 22 lines · Ludwig
Quoted 6 lines · Simon Glass
From: Simon Glass <[email protected]>
The hashed-nodes property in a FIT signature node lists which FDT paths are included in the signature hash. It is intended as a hint so should not be used for verification.
Quoted 7 lines
Add a function to build the node list from scratch by iterating the configuration's image references. Skip properties known not to be image references. For each image, collect the path plus all hash and cipher subnodes.
Use the new function in
fit_config_check_sig()instead of reading 'hashed-nodes'.While growing more grey hair trying to wrap my head around this I found a mean trap. mkimage reads a 'sign-images' property to determine which images to include in the hash regions. Without that property only kernel, fdt and script properties are included at image generation time (see
fit_config_get_image_list()).
Quoted 3 lines
The new verification code works without such a weird hardcoded list. So as soon as a FIT image has e.g. a ramdisk and it's not listed in 'sign- images' the verification fails.
Yes I noticed that...I was thinking we could have mkimage report an error, but fit_check_sign does do this check.
When designing all this I felt it was nice to have a sign-images property which explicltly contains the things to sign, since it makes you think about what you are doing. But perhaps we could just do without it?
Quoted 10 lines
Review
Quoted 4 lines
(quoted diff) +3
-0+static int fit_config_add_hash(const void *fit, int image_noffset, + char **node_inc, int *count, int max_nodes, + char *buf, int *buf_used, int buf_len)Took me a while to figure out that a function with the same name is also in
tools/image-host.c. Might make sense to pick a different one :- )
Quoted 7 lines
cu
Ludwig--
Ludwig Nussel
Siemens AG
www.siemens.com
Regards,
Simon
Quoted 25 lines · Simon Glass
Hi Ludwig,
Quoted 22 lines · Ludwig
Quoted 6 lines · Simon Glass
From: Simon Glass <[email protected]>
The hashed-nodes property in a FIT signature node lists which FDT paths are included in the signature hash. It is intended as a hint so should not be used for verification.
Quoted 7 lines
Add a function to build the node list from scratch by iterating the configuration's image references. Skip properties known not to be image references. For each image, collect the path plus all hash and cipher subnodes.
Use the new function in
fit_config_check_sig()instead of reading 'hashed-nodes'.While growing more grey hair trying to wrap my head around this I found a mean trap. mkimage reads a 'sign-images' property to determine which images to include in the hash regions. Without that property only kernel, fdt and script properties are included at image generation time (see
fit_config_get_image_list()).
Quoted 6 lines
Quoted 3 lines
The new verification code works without such a weird hardcoded list. So as soon as a FIT image has e.g. a ramdisk and it's not listed in 'sign- images' the verification fails.
Yes I noticed that...I was thinking we could have mkimage report an error, but
fit_check_signdoes do this check.
For me when I tried the patch it wasn't clear why the signature check failed at first. I assume for anyone not deep in the topic it's just outright frustrating when there are no helpful error messages. So yes, I think it makes sense to have mkimage do some checks to make sure fit_check_sign actually works :-)
Quoted 4 lines
When designing all this I felt it was nice to have a sign-images property which explicltly contains the things to sign, since it makes you think about what you are doing. But perhaps we could just do without it?
Is there a use case for not including images in the signature that are referenced from a config? IIUC with the current patch it wouldn't work anyway as signature verification enforces inclusion of all images now. IMO it would make sense to still read 'hashed-nodes' in the check to stay compatible (if it's a subset) but complain loudly and declare the feature deprecated.
cu
Ludwig
Signature · 3 lines
Ludwig Nussel Siemens AG www.siemens.com
Hello Simon,
Quoted 5 lines · Simon Glass
From: Simon Glass <[email protected]>
boot/image-fit-sig.c +3
-0+/* Process each image referenced by the config */ + image_count =0 ; +fdt_for_each_property_offset (prop_offset, fit, conf_noffset) {
boot/image-fit-sig.c int fit_image_verify_required_sigs(const void *fit, int image_noffset, · line 374
Quoted 10 lines
boot/image-fit-sig.c +10
-0+const char *prop_name; +int img_count, i; + +fdt_getprop_by_offset (fit, prop_offset, &prop_name,NULL ); +if (!prop_name) +continue ; + +/* Skip properties that are not image references */ + if (!strcmp(prop_name, FIT_DESC_PROP) || + !strcmp(prop_name, FIT_COMPAT_PROP) ||
I know you need to mimic what mkimage does on the other side, but I found this surprising:
The configuration node name is probably hashed along with the FDT node, but compatible isn't, so relying on compatible means an attacker can trivially control which configuration is booted.
boot/image-fit-sig.c int fit_image_verify_required_sigs(const void *fit, int image_noffset, · line 375
Quoted 1 line
boot/image-fit-sig.c +1
-0+ !strcmp(prop_name, FIT_DEFAULT_PROP))
I am aware of /configurations/default, but what does a default property within a configuration signify?
Thanks,
Ahmad
Quoted 175 lines
boot/image-fit-sig.c +38
-45+continue ; + + img_count =fdt_stringlist_count (fit, conf_noffset, prop_name); +for (i =0 ; i < img_count; i++) { +int noffset; + + noffset =fit_conf_get_prop_node_index (fit, + conf_noffset, + prop_name, i); +if (noffset <0 ) +continue ; + + ret =fit_config_add_hash (fit, noffset, node_inc, + &count, max_nodes, buf, &used, + buf_len); +if (ret <0 ) +return ret; + + image_count++; + } + } + +if (!image_count) { +printf ("No images in config '%s'\n" , conf_name); +return -ENOMSG ; + } + +return count; +} +/** * fit_config_check_sig() - Check the signature of a config * @@ -269,20 +443,16 @@ static int fit_config_check_sig(const void *fit, int noffset, int conf_noffset,FIT_DATA_POSITION_PROP , FIT_DATA_OFFSET_PROP, }; - -const char *prop, *end, *name; +char *node_inc[IMAGE_MAX_HASHED_NODES ]; +char hash_buf[FIT_MAX_HASH_PATH_BUF ];struct image_sign_info info;const uint32_t *strings; -const char *config_name;uint8_t *fit_value;int fit_value_len; -bool found_config;int max_regions; -int i, prop_len;char path[200 ];int count; - config_name =fit_get_name (fit, conf_noffset,NULL );debug ("%s: fdt=%p, conf='%s', sig='%s'\n" , __func__, key_blob,fit_get_name (fit, noffset,NULL ),fit_get_name (key_blob, required_keynode,NULL ));@@ -297,45 +467,12 @@ static int fit_config_check_sig(const void *fit, int noffset, int conf_noffset,return -1 ; } -/* Count the number of strings in the property */ - prop =fdt_getprop (fit, noffset,"hashed-nodes" , &prop_len); - end = prop ? prop + prop_len : prop; -for (name = prop, count =0 ; name < end; name++) -if (!*name) - count++; -if (!count) { - *err_msgp ="Can't get hashed-nodes property" ; -return -1 ; - } - -if (prop && prop_len >0 && prop[prop_len -1 ] !='\0' ) { - *err_msgp ="hashed-nodes property must be null-terminated" ; -return -1 ; - } - -/* Add a sanity check here since we are using the stack */ -if (count >IMAGE_MAX_HASHED_NODES ) { - *err_msgp ="Number of hashed nodes exceeds maximum" ; -return -1 ; - } - -/* Create a list of node names from those strings */ -char *node_inc[count]; - -debug ("Hash nodes (%d):\n" , count); - found_config = false; -for (name = prop, i =0 ; name < end; name +=strlen (name) +1 , i++) { -debug (" '%s'\n" , name); - node_inc[i] = (char *)name; -if (!strncmp (FIT_CONFS_PATH , name,strlen (FIT_CONFS_PATH )) && - name[sizeof (FIT_CONFS_PATH ) -1 ] =='/' && - !strcmp (name +sizeof (FIT_CONFS_PATH ), config_name)) { -debug (" (found config node %s)" , config_name); - found_config = true; - } - } -if (!found_config) { - *err_msgp ="Selected config not in hashed nodes" ; +/* Build the node list from the config, ignoring hashed-nodes */ + count =fit_config_get_hash_list (fit, conf_noffset, + node_inc,IMAGE_MAX_HASHED_NODES , + hash_buf,sizeof (hash_buf)); +if (count <0 ) { + *err_msgp ="Failed to build hash node list" ;return -1 ; }doc/usage/fit/signature.rst +13
-6@@ -353,20 +353,27 @@ meantime. Details ------- The signature node contains a property ('hashed-nodes') which lists all the -nodes that the signature was made over. The image is walked in order and each -tag processed as follows: +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. + +The image is walked in order and each tag processed as follows: DTB_BEGIN_NODE The tag and the following name are included in the signature - if the node or its parent are present in 'hashed-nodes' + if the node or its parent are present in the node list DTB_END_NODE The tag is included in the signature if the node or its parent - are present in 'hashed-nodes' + are present in the node list DTB_PROPERTY The tag, the length word, the offset in the string table, and - the data are all included if the current node is present in 'hashed-nodes' + the data are all included if the current node is present in the node list and the property name is not 'data'. DTB_END@@ -374,7 +381,7 @@ DTB_END DTB_NOP The tag is included in the signature if the current node is present - in 'hashed-nodes' + in the node list In addition, the signature contains a property 'hashed-strings' which contains the offset and length in the string table of the strings that are to betest/py/tests/test_vboot.py +6
-2@@ -362,10 +362,14 @@ def test_vboot(ubman, name, sha_algo, padding, sign_options, required, shutil.copyfile(fit, efit) vboot_evil.add_evil_node(fit, efit, evil_kernel, 'kernel@') - msg = 'Signature checking prevents use of unit addresses (@) in nodes' + # fit_check_sign catches this via signature mismatch (the @ + # node is hashed instead of the real one) utils.run_and_log_expect_exception( ubman, [fit_check_sign, '-f', efit, '-k', dtb], - 1, msg) + 1, 'Failed to verify required signature') + + # bootm catches it earlier, at fit_check_format() time + msg = 'Signature checking prevents use of unit addresses (@) in nodes' run_bootm(sha_algo, 'evil kernel@', msg, False, efit) # Create a new properly signed fit and replace header bytes
Signature · 4 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Hi Ahmad,
Quoted 23 lines · Ahmad Fatoum
Hello Simon,
Quoted 5 lines · Simon Glass
From: Simon Glass <[email protected]>
boot/image-fit-sig.c +3
-0+/* Process each image referenced by the config */ + image_count =0 ; +fdt_for_each_property_offset (prop_offset, fit, conf_noffset) {boot/image-fit-sig.c int fit_image_verify_required_sigs(const void *fit, int image_noffset, · line 374
Quoted 10 lines
boot/image-fit-sig.c +10
-0+const char *prop_name; +int img_count, i; + +fdt_getprop_by_offset (fit, prop_offset, &prop_name,NULL ); +if (!prop_name) +continue ; + +/* Skip properties that are not image references */ + if (!strcmp(prop_name, FIT_DESC_PROP) || + !strcmp(prop_name, FIT_COMPAT_PROP) ||I know you need to mimic what mkimage does on the other side, but I found this surprising:
Quoted 8 lines
The configuration node name is probably hashed along with the FDT node, but compatible isn't, so relying on compatible means an attacker can trivially control which configuration is booted.
Quoted 1 line
+ !strcmp(prop_name,
FIT_DEFAULT_PROP))I am aware of /configurations/default, but what does a default property within a configuration signify?
Belated reply, but yes we don't use a defauilt property within the configuration.
So we don't need that extra check, i.e. if someone did add a 'default' property into the configuration it would be OK to fail the signature check.
[..]
Regards,
Simon