u-boot: kernel-fitimage: Fix dependency loop if UBOOT_SIGN_ENABLE and UBOOT_ENV enabled
PATCH v4 1/1 u-boot: kernel-fitimage: Fix dependency loop if UBOOT_SIGN_ENABLE and UBOOT_ENV enabled
In case both UBOOT_SIGN_ENABLE and UBOOT_ENV are enabled and kernel-fitimage.bbclass is in use to generate signed kernel fitImage, there is a circular dependency between uboot-sign and kernel-fitimage bbclasses . The loop looks like this:
kernel-fitimage.bbclass:
- do_populate_sysroot depends on do_assemble_fitimage
- do_assemble_fitimage depends on virtual/bootloader:do_populate_sysroot
- virtual/bootloader:do_populate_sysroot depends on virtual/bootloader:do_install => The virtual/bootloader:do_install installs and the virtual/bootloader:do_populate_sysroot places into
sysroot an U-Boot environment script embedded into
kernel fitImage during do_assemble_fitimage run .
uboot-sign.bbclass:
- DEPENDS on KERNEL_PN, which is really virtual/kernel. More accurately
- do_deploy depends on do_uboot_assemble_fitimage
- do_install depends on do_uboot_assemble_fitimage
- do_uboot_assemble_fitimage depends on virtual/kernel:do_populate_sysroot => do_install depends on virtual/kernel:do_populate_sysroot
=> virtual/bootloader:do_install depends on virtual/kernel:do_populate_sysroot
virtual/kernel:do_populate_sysroot depends on virtual/bootloader:do_install
Attempt to resolve the loop. Pull fitimage configuration options into separate new bbclass kernel-fitimage-config.bbclass so these configuration options can be shared by both uboot-sign.bbclass and kernel-fitimage.bbclass, and make use of mkimage -f auto-conf / mkimage -f auto option to insert /signature node key-* subnode into U-Boot control DT without depending on the layout of kernel fitImage itself. This is perfectly valid to do, because the U-Boot /signature node key-* subnodes 'required' property can contain either of two values, 'conf' or 'image' to authenticate either selected configuration or all of images when booting the fitImage.
For details of the U-Boot fitImage signing process, see:
https://docs.u-boot.org/en/latest/usage/fit/signature.html
For details of mkimage -f auto-conf and -f auto, see:
https://manpages.debian.org/experimental/u-boot-tools/mkimage.1.en.html#EXAMPLES
---
Cc: Adrian Freihofer <[email protected]>
Cc: Alexandre Belloni <[email protected]>
Cc: Richard Purdie <[email protected]>
Cc: Sean Anderson <[email protected]>
---
V2: Take a different approach, split the kernel-fitimage.bbclass and
use it to generate dummy fitImage on demand
V3: Use mkimage -f auto-conf and mkimage -f auto to break the loop,
the fitImage .its source is not even needed because the 'required' property can only have two values, 'conf' or 'image' .
V4: Restore CC list
--- .../kernel-fitimage-config.bbclass | 50 +++++++++++++++++ meta/classes-recipe/kernel-fitimage.bbclass | 54 +------------------ meta/classes-recipe/uboot-sign.bbclass | 26 ++++----- 3 files changed, 64 insertions(+), 66 deletions(-) create mode 100644 meta/classes-recipe/kernel-fitimage-config.bbclass
meta/classes-recipe/kernel-fitimage-config.bbclass new file +50 -0
@@ -0,0 +1,50 @@ +# Description string +FIT_DESC ?= "Kernel fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}" + +# Kernel fitImage Hash Algo +FIT_HASH_ALG ?= "sha256" + +# Kernel fitImage Signature Algo +FIT_SIGN_ALG ?= "rsa2048" + +# Kernel / U-Boot fitImage Padding Algo +FIT_PAD_ALG ?= "pkcs-1.5" + +# Generate keys for signing Kernel fitImage +FIT_GENERATE_KEYS ?= "0" + +# Size of private keys in number of bits +FIT_SIGN_NUMBITS ?= "2048" + +# args to openssl genrsa (Default is just the public exponent) +FIT_KEY_GENRSA_ARGS ?= "-F4" + +# args to openssl req (Default is -batch for non interactive mode and +# -new for new certificate) +FIT_KEY_REQ_ARGS ?= "-batch -new" + +# Standard format for public key certificate +FIT_KEY_SIGN_PKCS ?= "-x509" + +# Sign individual images as well +FIT_SIGN_INDIVIDUAL ?= "0" + +FIT_CONF_PREFIX ?= "conf-" +FIT_CONF_PREFIX[doc] = "Prefix to use for FIT configuration node name" + +FIT_SUPPORTED_INITRAMFS_FSTYPES ?= "cpio.lz4 cpio.lzo cpio.lzma cpio.xz cpio.zst cpio.gz ext2.gz cpio" + +# Allow user to select the default DTB for FIT image when multiple dtb's exists. +FIT_CONF_DEFAULT_DTB ?= "" + +# length of address in number of <u32> cells +# ex: 1 32bits address, 2 64bits address +FIT_ADDRESS_CELLS ?= "1" + +# Keys used to sign individually image nodes. +# The keys to sign image nodes must be different from those used to sign +# configuration nodes, otherwise the "required" property, from +# UBOOT_DTB_BINARY, will be set to "conf", because "conf" prevails on "image". +# Then the images signature checking will not be mandatory and no error will be +# raised in case of failure. +# UBOOT_SIGN_IMG_KEYNAME = "dev2" # keys name in keydir (eg. "dev2.crt", "dev2.key")
meta/classes-recipe/kernel-fitimage.bbclass +1 -53
66 lines not on this page · raw message
meta/classes-recipe/uboot-sign.bbclass +13 -13
@@ -25,7 +25,7 @@ # For more details on signature process, please refer to U-Boot documentation. # We need some variables from u-boot-config -inherit uboot-config +inherit uboot-config kernel-fitimage-config # Enable use of a U-Boot fitImage UBOOT_FITIMAGE_ENABLE ?= "0"
@@ -85,9 +85,6 @@ UBOOT_FIT_KEY_SIGN_PKCS ?= "-x509" # ex: 1 32bits address, 2 64bits address UBOOT_FIT_ADDRESS_CELLS ?= "1" -# This is only necessary for determining the signing configuration -KERNEL_PN = "${PREFERRED_PROVIDER_virtual/kernel}" - UBOOT_FIT_UBOOT_LOADADDRESS ?= "${UBOOT_LOADADDRESS}" UBOOT_FIT_UBOOT_ENTRYPOINT ?= "${UBOOT_ENTRYPOINT}"
@@ -96,8 +93,6 @@ python() { sign = d.getVar('UBOOT_SIGN_ENABLE') == '1' if d.getVar('UBOOT_FITIMAGE_ENABLE') == '1' or sign: d.appendVar('DEPENDS', " u-boot-tools-native dtc-native") - if sign: - d.appendVar('DEPENDS', " " + d.getVar('KERNEL_PN')) } concat_dtb() {
@@ -106,16 +101,25 @@ concat_dtb() { if [ -e "${UBOOT_DTB_BINARY}" ]; then # Re-sign the kernel in order to add the keys to our dtb + UBOOT_MKIMAGE_MODE="auto-conf" + # Signing individual images is not recommended as that + # makes fitImage susceptible to mix-and-match attack. + if [ "${FIT_SIGN_INDIVIDUAL}" = "1" ] ; then + UBOOT_MKIMAGE_MODE="auto" + fi ${UBOOT_MKIMAGE_SIGN} \ ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \ - -F -k "${UBOOT_SIGN_KEYDIR}" \ + -f ${UBOOT_MKIMAGE_MODE} -d /dev/null \ + -k "${UBOOT_SIGN_KEYDIR}" \ + -o "${FIT_HASH_ALG},${FIT_SIGN_ALG}" \ + -g "${UBOOT_SIGN_IMG_KEYNAME}" \ -K "${UBOOT_DTB_BINARY}" \ - -r ${B}/fitImage-linux \ + -r ${B}/unused.itb ${UBOOT_MKIMAGE_SIGN_ARGS} # Verify the kernel image and u-boot dtb ${UBOOT_FIT_CHECK_SIGN} \ -k "${UBOOT_DTB_BINARY}" \ - -f ${B}/fitImage-linux + -f ${B}/unused.itb cp ${UBOOT_DTB_BINARY} ${UBOOT_DTB_SIGNED} fi
@@ -351,10 +355,6 @@ uboot_assemble_fitimage_helper() { } do_uboot_assemble_fitimage() { - if [ "${UBOOT_SIGN_ENABLE}" = "1" ] ; then - cp "${STAGING_DIR_HOST}/sysroot-only/fitImage" "${B}/fitImage-linux" - fi - if [ -n "${UBOOT_CONFIG}" ]; then unset i for config in ${UBOOT_MACHINE}; do
Signature · 1 line
2.45.2
Hi Marek
Quoted 276 lines · Marek Vasut via lists.openembedded.org
In case both
UBOOT_SIGN_ENABLEandUBOOT_ENVare enabled and kernel-fitimage.bbclass is in use to generate signed kernel fitImage, there is a circular dependency between uboot-sign and kernel-fitimage bbclasses . The loop looks like this:kernel-fitimage.bbclass:
-do_populate_sysrootdepends ondo_assemble_fitimage
-do_assemble_fitimagedepends on virtual/bootloader:do_populate_sysroot
- virtual/bootloader:do_populate_sysroot depends on virtual/bootloader:do_install
=> The virtual/bootloader:do_install installs and the virtual/bootloader:do_populate_sysroot places into sysroot an U-Boot environment script embedded into kernel fitImage duringdo_assemble_fitimagerun .uboot-sign.bbclass:
- DEPENDS onKERNEL_PN, which is really virtual/kernel. More accurately
-do_deploydepends ondo_uboot_assemble_fitimage
-do_installdepends ondo_uboot_assemble_fitimage
-do_uboot_assemble_fitimagedepends on virtual/kernel:do_populate_sysroot
=>do_installdepends on virtual/kernel:do_populate_sysroot=> virtual/bootloader:do_install depends on virtual/kernel:do_populate_sysroot virtual/kernel:do_populate_sysroot depends on virtual/bootloader:do_install
Attempt to resolve the loop. Pull fitimage configuration options into separate
new bbclass kernel-fitimage-config.bbclass so these configuration options can
be shared by both uboot-sign.bbclass and kernel-fitimage.bbclass, and make use
of mkimage -f auto-conf / mkimage -f auto option to insert /signature node key-*
subnode into U-Boot control DT without depending on the layout of kernel fitImage
itself. This is perfectly valid to do, because the U-Boot /signature node key-*
subnodes 'required' property can contain either of two values, 'conf' or 'image'
to authenticate either selected configuration or all of images when booting the
fitImage.For details of the U-Boot fitImage signing process, see:
https://docs.u-boot.org/en/latest/usage/fit/signature.html
For details of mkimage -f auto-conf and -f auto, see:
https://manpages.debian.org/experimental/u-boot-tools/mkimage.1.en.html#EXAMPLESFixes 5e12dc911d0c ("u-boot: Rework signing to removeinterdependencies")
Signed-off-by Marek Vasut <[email protected]>---
Cc: Adrian Freihofer <[email protected]>
Cc: Alexandre Belloni <[email protected]>
Cc: Richard Purdie <[email protected]>
Cc: Sean Anderson <[email protected]>
---
V2: Take a different approach, split the kernel-fitimage.bbclass and use it to generate dummy fitImage on demand
V3: Use mkimage -f auto-conf and mkimage -f auto to break the loop, the fitImage .its source is not even needed because the 'required'
property can only have two values, 'conf' or 'image' .
V4: Restore CC list
---
.../kernel-fitimage-config.bbclass | 50 +++++++++++++++++ meta/classes-recipe/kernel-fitimage.bbclass | 54 +---------------- --
meta/classes-recipe/uboot-sign.bbclass | 26 ++++-----3 files changed, 64 insertions(+), 66 deletions(-)create mode 100644 meta/classes-recipe/kernel-fitimage- config.bbclass
meta/classes-recipe/kernel-fitimage-config.bbclass new file +22
-0@@ -0,0 +1,50 @@ +# Description string +FIT_DESC ?= "Kernel fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}" + +# Kernel fitImage Hash Algo +FIT_HASH_ALG ?= "sha256" + +# Kernel fitImage Signature Algo +FIT_SIGN_ALG ?= "rsa2048" + +# Kernel / U-Boot fitImage Padding Algo +FIT_PAD_ALG ?= "pkcs-1.5" + +# Generate keys for signing Kernel fitImage +FIT_GENERATE_KEYS ?= "0" + +# Size of private keys in number of bits +FIT_SIGN_NUMBITS ?= "2048" + +# args to openssl genrsa (Default is just the public exponent) +FIT_KEY_GENRSA_ARGS ?= "-F4" + +# args to openssl req (Default is -batch for non interactive modeand
meta/classes-recipe/kernel-fitimage-config.bbclass new file +11
-0+# -new for new certificate) +FIT_KEY_REQ_ARGS ?= "-batch -new" + +# Standard format for public key certificate +FIT_KEY_SIGN_PKCS ?= "-x509" + +# Sign individual images as well +FIT_SIGN_INDIVIDUAL ?= "0" + +FIT_CONF_PREFIX ?= "conf-" +FIT_CONF_PREFIX[doc] = "Prefix to use for FIT configuration nodename"
meta/classes-recipe/kernel-fitimage-config.bbclass new file +2
-0+ +FIT_SUPPORTED_INITRAMFS_FSTYPES ?= "cpio.lz4 cpio.lzo cpio.lzmacpio.xz cpio.zst cpio.gz ext2.gz cpio"
meta/classes-recipe/kernel-fitimage-config.bbclass new file +2
-0+ +# Allow user to select the default DTB for FIT image when multipledtb's exists.
meta/classes-recipe/kernel-fitimage-config.bbclass new file +8
-0+FIT_CONF_DEFAULT_DTB ?= "" + +# length of address in number of <u32> cells +# ex: 1 32bits address, 2 64bits address +FIT_ADDRESS_CELLS ?= "1" + +# Keys used to sign individually image nodes. +# The keys to sign image nodes must be different from those used tosign
meta/classes-recipe/kernel-fitimage-config.bbclass new file +2
-0+# configuration nodes, otherwise the "required" property, from +# UBOOT_DTB_BINARY, will be set to "conf", because "conf" prevailson "image".
+# Then the images signature checking will not be mandatory and no error will bemeta/classes-recipe/kernel-fitimage-config.bbclass new file +2
-0+# raised in case of failure. +# UBOOT_SIGN_IMG_KEYNAME = "dev2" # keys name in keydir (eg."dev2.crt", "dev2.key")
meta/classes-recipe/kernel-fitimage.bbclass +0
-0@@ -4,7 +4,7 @@ # SPDX-License-Identifier: MIT #meta/classes-recipe/kernel-fitimage.bbclass +1
-1-inherit kernel-uboot kernel-artifact-names uboot-config +inherit kernel-uboot kernel-artifact-names uboot-config kernel-fitimage-config
defget_fit_replacement_type(d):
kerneltypes =d.getVar('KERNEL_IMAGETYPES')or ""meta/classes-recipe/kernel-fitimage.bbclass +0
-0@@ -52,58 +52,6 @@ python __anonymous () { d.setVar('EXTERNAL_KERNEL_DEVICETREE', "${RECIPE_SYSROOT}/boot/devicetree") }meta/classes-recipe/kernel-fitimage.bbclass +0
-23- -# Description string -FIT_DESC ?= "Kernel fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}" - -# Kernel fitImage Hash Algo -FIT_HASH_ALG ?= "sha256" - -# Kernel fitImage Signature Algo -FIT_SIGN_ALG ?= "rsa2048" - -# Kernel / U-Boot fitImage Padding Algo -FIT_PAD_ALG ?= "pkcs-1.5" - -# Generate keys for signing Kernel fitImage -FIT_GENERATE_KEYS ?= "0" - -# Size of private keys in number of bits -FIT_SIGN_NUMBITS ?= "2048" - -# args to openssl genrsa (Default is just the public exponent) -FIT_KEY_GENRSA_ARGS ?= "-F4" - -# args to openssl req (Default is -batch for non interactive modeand
meta/classes-recipe/kernel-fitimage.bbclass +0
-11-# -new for new certificate) -FIT_KEY_REQ_ARGS ?= "-batch -new" - -# Standard format for public key certificate -FIT_KEY_SIGN_PKCS ?= "-x509" - -# Sign individual images as well -FIT_SIGN_INDIVIDUAL ?= "0" - -FIT_CONF_PREFIX ?= "conf-" -FIT_CONF_PREFIX[doc] = "Prefix to use for FIT configuration nodename"
meta/classes-recipe/kernel-fitimage.bbclass +0
-2- -FIT_SUPPORTED_INITRAMFS_FSTYPES ?= "cpio.lz4 cpio.lzo cpio.lzmacpio.xz cpio.zst cpio.gz ext2.gz cpio"
meta/classes-recipe/kernel-fitimage.bbclass +0
-2- -# Allow user to select the default DTB for FIT image when multipledtb's exists.
meta/classes-recipe/kernel-fitimage.bbclass +0
-8-FIT_CONF_DEFAULT_DTB ?= "" - -# length of address in number of <u32> cells -# ex: 1 32bits address, 2 64bits address -FIT_ADDRESS_CELLS ?= "1" - -# Keys used to sign individually image nodes. -# The keys to sign image nodes must be different from those used tosign
meta/classes-recipe/kernel-fitimage.bbclass +0
-2-# configuration nodes, otherwise the "required" property, from -# UBOOT_DTB_BINARY, will be set to "conf", because "conf" prevailson "image".
-# Then the images signature checking will not be mandatory and no error will bemeta/classes-recipe/kernel-fitimage.bbclass +0
-2-# raised in case of failure. -# UBOOT_SIGN_IMG_KEYNAME = "dev2" # keys name in keydir (eg."dev2.crt", "dev2.key")
-
#
# Emit the fitImage ITS header
#meta/classes- renamed from meta/classes-recipe/uboot-sign.bbclass +0
-0recipe/uboot-sign.bbclass
indexa17be745cec..d23ae4d8d15100644meta/classes-recipe/uboot-sign.bbclass +0
-0@@ -25,7 +25,7 @@ # For more details on signature process, please refer to U-Bootdocumentation.
# We need some variables from u-boot-configmeta/classes-recipe/uboot-sign.bbclass +1
-1-inherit uboot-config +inherit uboot-config kernel-fitimage-config
# Enable use of a U-Boot fitImage
UBOOT_FITIMAGE_ENABLE ?= "0"meta/classes-recipe/uboot-sign.bbclass +0
-0@@ -85,9 +85,6 @@ UBOOT_FIT_KEY_SIGN_PKCS ?= "-x509" # ex: 1 32bits address, 2 64bits addressUBOOT_FIT_ADDRESS_CELLS ?= "1"
meta/classes-recipe/uboot-sign.bbclass +0
-3-# This is only necessary for determining the signing configuration -KERNEL_PN = "${PREFERRED_PROVIDER_virtual/kernel}" -UBOOT_FIT_UBOOT_LOADADDRESS ?= "${UBOOT_LOADADDRESS}"
UBOOT_FIT_UBOOT_ENTRYPOINT?= "${UBOOT_ENTRYPOINT}"meta/classes-recipe/uboot-sign.bbclass +0
-0@@ -96,8 +93,6 @@ python() {sign =
d.getVar('UBOOT_SIGN_ENABLE')== '1'
ifd.getVar('UBOOT_FITIMAGE_ENABLE')== '1' or sign:
d.appendVar('DEPENDS', " u-boot-tools-native dtc-native")- if sign:
-d.appendVar('DEPENDS', " " + d.getVar('KERNEL_PN'))}
concat_dtb() {meta/classes-recipe/uboot-sign.bbclass +0
-0@@ -106,16 +101,25 @@ concat_dtb() {
if [ -e "${UBOOT_DTB_BINARY}" ]; then
# Re-sign the kernel in order to add the keys to our dtbmeta/classes-recipe/uboot-sign.bbclass +2
-0+ UBOOT_MKIMAGE_MODE="auto-conf" + # Signing individual images is not recommended asthat
meta/classes-recipe/uboot-sign.bbclass +1
-0+ # makes fitImage susceptible to mix-and-matchattack.
meta/classes-recipe/uboot-sign.bbclass +3
-0+ if [ "${FIT_SIGN_INDIVIDUAL}" = "1" ] ; then + UBOOT_MKIMAGE_MODE="auto" + fi${UBOOT_MKIMAGE_SIGN} \
${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' iflen('${UBOOT_MKIMAGE_DTCOPTS}')else ''} \
meta/classes-recipe/uboot-sign.bbclass concat_dtb() { · line 112
Quoted 2 lines
meta/classes-recipe/uboot-sign.bbclass +1
-1- -F -k "${UBOOT_SIGN_KEYDIR}" \ + -f ${UBOOT_MKIMAGE_MODE} -d /dev/null \
As UBOOT_MKIMAGE_MODE appears to be a shell variable and not a bitbake variable, it should be used like $UBOOT_MKIMAGE_MODE and not like ${UBOOT_MKIMAGE_MODE}.
meta/classes-recipe/uboot-sign.bbclass concat_dtb() { · line 117
Quoted 6 lines
meta/classes-recipe/uboot-sign.bbclass +3
-0+ -k "${UBOOT_SIGN_KEYDIR}" \ + -o "${FIT_HASH_ALG},${FIT_SIGN_ALG}" \ + -g "${UBOOT_SIGN_IMG_KEYNAME}" \-K "${UBOOT_DTB_BINARY}" \
meta/classes-recipe/uboot-sign.bbclass +1
-1- -r ${B}/fitImage-linux \ + -r ${B}/unused.itb
Here a \ is missing. The line should look like:
-r ${B}/unused.itb \This patch looks much simpler than v2 and is a good step towards decoupling the kernel and u-boot. Now the dependencies between u-boot and the kernel are primarily some shared variables. The task dependencies are much less critical.
Thank you
Adrian
Quoted 33 lines
${UBOOT_MKIMAGE_SIGN_ARGS} # Verify the kernel image and u-boot dtb ${UBOOT_FIT_CHECK_SIGN} \
-k "${UBOOT_DTB_BINARY}" \meta/classes-recipe/uboot-sign.bbclass +1
-1- -f ${B}/fitImage-linux + -f ${B}/unused.itbcp ${UBOOT_DTB_BINARY} ${UBOOT_DTB_SIGNED} fi
meta/classes-recipe/uboot-sign.bbclass +0
-0@@ -351,10 +355,6 @@ uboot_assemble_fitimage_helper() { }
do_uboot_assemble_fitimage() {meta/classes-recipe/uboot-sign.bbclass +0
-2- if [ "${UBOOT_SIGN_ENABLE}" = "1" ] ; then - cp "${STAGING_DIR_HOST}/sysroot-only/fitImage""${B}/fitImage-linux"
meta/classes-recipe/uboot-sign.bbclass +0
-2- fi -if [ -n "${UBOOT_CONFIG}" ]; then unset i
for config in ${UBOOT_MACHINE}; do-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#210008):
https://lists.openembedded.org/g/openembedded-core/message/210008
Mute This Topic: https://lists.openembedded.org/mt/110697929/4454582
Group Owner: [email protected] Unsubscribe:
https://lists.openembedded.org/g/openembedded-core/unsub [
[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-