summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarek Vasut <marex@denx.de>2025-02-25 15:49:03 +0000
committerSteve Sakoman <steve@sakoman.com>2025-03-05 06:03:47 -0800
commit560f9602953d8a93767fae79ea6110dab1a6c7ac (patch)
treed21313ff0c5ca3327f7aeefb8eafd76c7978546a
parent84492696d2b9385c72496cd9fd26e47759f35d61 (diff)
downloadpoky-560f9602953d8a93767fae79ea6110dab1a6c7ac.tar.gz
u-boot: kernel-fitimage: Restore FIT_SIGN_INDIVIDUAL="1" behavior
OE FIT_SIGN_INDIVIDUAL is implemented in an unusual manner, where the resulting signed fitImage contains both signed images and signed configurations, possibly using different keys. This kind of signing of images is redundant, but so is the behavior of FIT_SIGN_INDIVIDUAL="1" and that is here to stay. Adjust the process of public key insertion into u-boot.dtb such that if FIT_SIGN_INDIVIDUAL==1, the image signing key is inserted into u-boot.dtb first, and in any case the configuration signing key is inserted into u-boot.dtb last. The verification of the keys inserted into u-boot.dtb against unused.itb is performed only for FIT_SIGN_INDIVIDUAL!=1 due to mkimage limitation, which does not allow mkimage -f auto-conf to update the generated unused.itb, and instead rewrites it. Fixes: 259bfa86f384 ("u-boot: kernel-fitimage: Fix dependency loop if UBOOT_SIGN_ENABLE and UBOOT_ENV enabled") (From OE-Core rev: 699822a163a4efa32735f75d21fde4ffa195c0e0) Signed-off-by: Marek Vasut <marex@denx.de> Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit 0106e5efab99c8016836a2ab71e2327ce58a9a9d) Signed-off-by: Jose Quaresma <jose.quaresma@foundries.io> Signed-off-by: Steve Sakoman <steve@sakoman.com>
-rw-r--r--meta/classes-recipe/uboot-sign.bbclass60
1 files changed, 51 insertions, 9 deletions
diff --git a/meta/classes-recipe/uboot-sign.bbclass b/meta/classes-recipe/uboot-sign.bbclass
index 96c47ab016..5c579a9fb0 100644
--- a/meta/classes-recipe/uboot-sign.bbclass
+++ b/meta/classes-recipe/uboot-sign.bbclass
@@ -101,27 +101,69 @@ concat_dtb() {
101 binary="$2" 101 binary="$2"
102 102
103 if [ -e "${UBOOT_DTB_BINARY}" ]; then 103 if [ -e "${UBOOT_DTB_BINARY}" ]; then
104 # Re-sign the kernel in order to add the keys to our dtb
105 UBOOT_MKIMAGE_MODE="auto-conf"
106 # Signing individual images is not recommended as that 104 # Signing individual images is not recommended as that
107 # makes fitImage susceptible to mix-and-match attack. 105 # makes fitImage susceptible to mix-and-match attack.
106 #
107 # OE FIT_SIGN_INDIVIDUAL is implemented in an unusual manner,
108 # where the resulting signed fitImage contains both signed
109 # images and signed configurations. This is redundant. In
110 # order to prevent mix-and-match attack, it is sufficient
111 # to sign configurations. The FIT_SIGN_INDIVIDUAL = "1"
112 # support is kept to avoid breakage of existing layers, but
113 # it is highly recommended to avoid FIT_SIGN_INDIVIDUAL = "1",
114 # i.e. set FIT_SIGN_INDIVIDUAL = "0" .
108 if [ "${FIT_SIGN_INDIVIDUAL}" = "1" ] ; then 115 if [ "${FIT_SIGN_INDIVIDUAL}" = "1" ] ; then
109 UBOOT_MKIMAGE_MODE="auto" 116 # Sign dummy image images in order to
117 # add the image signing keys to our dtb
118 ${UBOOT_MKIMAGE_SIGN} \
119 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
120 -f auto \
121 -k "${UBOOT_SIGN_KEYDIR}" \
122 -o "${FIT_HASH_ALG},${FIT_SIGN_ALG}" \
123 -g "${UBOOT_SIGN_IMG_KEYNAME}" \
124 -K "${UBOOT_DTB_BINARY}" \
125 -d /dev/null \
126 -r ${B}/unused.itb \
127 ${UBOOT_MKIMAGE_SIGN_ARGS}
110 fi 128 fi
129
130 # Sign dummy image configurations in order to
131 # add the configuration signing keys to our dtb
111 ${UBOOT_MKIMAGE_SIGN} \ 132 ${UBOOT_MKIMAGE_SIGN} \
112 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \ 133 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
113 -f $UBOOT_MKIMAGE_MODE \ 134 -f auto-conf \
114 -k "${UBOOT_SIGN_KEYDIR}" \ 135 -k "${UBOOT_SIGN_KEYDIR}" \
115 -o "${FIT_HASH_ALG},${FIT_SIGN_ALG}" \ 136 -o "${FIT_HASH_ALG},${FIT_SIGN_ALG}" \
116 -g "${UBOOT_SIGN_IMG_KEYNAME}" \ 137 -g "${UBOOT_SIGN_KEYNAME}" \
117 -K "${UBOOT_DTB_BINARY}" \ 138 -K "${UBOOT_DTB_BINARY}" \
118 -d /dev/null \ 139 -d /dev/null \
119 -r ${B}/unused.itb \ 140 -r ${B}/unused.itb \
120 ${UBOOT_MKIMAGE_SIGN_ARGS} 141 ${UBOOT_MKIMAGE_SIGN_ARGS}
121 # Verify the kernel image and u-boot dtb 142
122 ${UBOOT_FIT_CHECK_SIGN} \ 143 # Verify the dummy fitImage signature against u-boot.dtb
123 -k "${UBOOT_DTB_BINARY}" \ 144 # augmented using public key material.
124 -f ${B}/unused.itb 145 #
146 # This only works for FIT_SIGN_INDIVIDUAL = "0", because
147 # mkimage -f auto-conf does not support -F to extend the
148 # existing unused.itb , and instead rewrites unused.itb
149 # from scratch.
150 #
151 # Using two separate unused.itb for mkimage -f auto and
152 # mkimage -f auto-conf invocation above would not help, as
153 # the signature verification process below checks whether
154 # all keys inserted into u-boot.dtb /signature node pass
155 # the verification. Separate unused.itb would each miss one
156 # of the signatures.
157 #
158 # The FIT_SIGN_INDIVIDUAL = "1" support is kept to avoid
159 # breakage of existing layers, but it is highly recommended
160 # to not use FIT_SIGN_INDIVIDUAL = "1", i.e. set
161 # FIT_SIGN_INDIVIDUAL = "0" .
162 if [ "${FIT_SIGN_INDIVIDUAL}" != "1" ] ; then
163 ${UBOOT_FIT_CHECK_SIGN} \
164 -k "${UBOOT_DTB_BINARY}" \
165 -f ${B}/unused.itb
166 fi
125 cp ${UBOOT_DTB_BINARY} ${UBOOT_DTB_SIGNED} 167 cp ${UBOOT_DTB_BINARY} ${UBOOT_DTB_SIGNED}
126 fi 168 fi
127 169