package/uboot-tools: fix host FIT signature support
PATCH v2 1/1 package/uboot-tools: fix host FIT signature support
U-Boot host tools use the tools configuration namespace when code calls CONFIG_IS_ENABLED(). With USE_HOSTCC, CONFIG_IS_ENABLED(FIT_SIGNATURE) resolves to CONFIG_TOOLS_FIT_SIGNATURE, while CONFIG_VAL(FIT_SIGNATURE_MAX_SIZE) resolves to CONFIG_TOOLS_FIT_SIGNATURE_MAX_SIZE.
The host-uboot-tools package only generates the old CONFIG_FIT_SIGNATURE define. This makes tools/Makefile include fit_check_sign, but the host code sees FIT signature support as disabled and the OpenSSL-backed signing and verification objects are omitted. As a result, mkimage accepts a signature node without writing its value or injecting a required public key. fit_check_sign then has no required key and reports success without checking the configuration signature.
A FIT-support-only configuration never exercises this path, which is why the existing hash-only runtime test still passes.
Generate the tools FIT signature options needed by the host code and pass CONFIG_TOOLS_LIBCRYPTO=y so the OpenSSL-backed signing, verification and cipher objects are selected. Keep CONFIG_FIT_SIGNATURE=y in the make options because U-Boot tools/Makefile still uses it to build fit_check_sign.
Extend TestHostUbootTools to create an RSA-signed FIT, require a 256-byte configuration signature and a required public key, verify the FIT, corrupt the signature, and require verification to fail.
---
Changes v1 -> v2:
- Clarify that the old configuration silently omits FIT signatures
- Add FIT signing, required-key and tamper-rejection runtime coverage
--- package/uboot-tools/uboot-tools.mk | 7 ++- .../testing/tests/package/test_uboot_tools.py | 57 +++++++++++++++++++ .../tests/package/test_uboot_tools/key.dts | 4 ++ .../tests/package/test_uboot_tools/signed.its | 38 +++++++++++++ 4 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 support/testing/tests/package/test_uboot_tools/key.dts create mode 100644 support/testing/tests/package/test_uboot_tools/signed.its
package/uboot-tools/uboot-tools.mk +5 -2
@@ -126,7 +126,10 @@ define HOST_UBOOT_TOOLS_CONFIGURE_CMDS mkdir -p $(@D)/include/generated $(if $(BR2_PACKAGE_HOST_UBOOT_TOOLS_FIT_SUPPORT),$(UBOOT_TOOLS_ENABLE_HASH_ALGOS)) $(if $(BR2_PACKAGE_HOST_UBOOT_TOOLS_FIT_SUPPORT),echo '#define CONFIG_TOOLS_FIT_PRINT 1' >> $(@D)/include/generated/autoconf.h) - echo $(if $(BR2_PACKAGE_HOST_UBOOT_TOOLS_FIT_SIGNATURE_SUPPORT),'#define CONFIG_FIT_SIGNATURE 1') >> $(@D)/include/generated/autoconf.h + $(if $(BR2_PACKAGE_HOST_UBOOT_TOOLS_FIT_SIGNATURE_SUPPORT),echo '#define CONFIG_TOOLS_IMAGE_PRE_LOAD 1' >> $(@D)/include/generated/autoconf.h) + $(if $(BR2_PACKAGE_HOST_UBOOT_TOOLS_FIT_SIGNATURE_SUPPORT),echo '#define CONFIG_TOOLS_RSASSA_PSS 1' >> $(@D)/include/generated/autoconf.h) + $(if $(BR2_PACKAGE_HOST_UBOOT_TOOLS_FIT_SIGNATURE_SUPPORT),echo '#define CONFIG_TOOLS_FIT_SIGNATURE 1' >> $(@D)/include/generated/autoconf.h) + $(if $(BR2_PACKAGE_HOST_UBOOT_TOOLS_FIT_SIGNATURE_SUPPORT),echo '#define CONFIG_TOOLS_FIT_SIGNATURE_MAX_SIZE 0x10000000' >> $(@D)/include/generated/autoconf.h) mkdir -p $(@D)/include/asm touch $(@D)/include/asm/linkage.h endef
@@ -142,7 +145,7 @@ HOST_UBOOT_TOOLS_DEPENDENCIES += host-dtc endif ifeq ($(BR2_PACKAGE_HOST_UBOOT_TOOLS_FIT_SIGNATURE_SUPPORT),y) -HOST_UBOOT_TOOLS_MAKE_OPTS += CONFIG_FIT_SIGNATURE=y CONFIG_FIT_SIGNATURE_MAX_SIZE=0x10000000 +HOST_UBOOT_TOOLS_MAKE_OPTS += CONFIG_TOOLS_LIBCRYPTO=y CONFIG_FIT_SIGNATURE=y HOST_UBOOT_TOOLS_DEPENDENCIES += host-openssl define HOST_UBOOT_TOOLS_INSTALL_FIT_CHECK_SIGN $(INSTALL) -m 0755 -D $(@D)/tools/fit_check_sign $(HOST_DIR)/bin/fit_check_sign
support/testing/tests/package/test_uboot_tools.py +57 -0
77 lines not on this page · raw message
support/testing/tests/package/test_uboot_tools/key.dts new file +4 -0
@@ -0,0 +1,4 @@ +/dts-v1/; + +/ { +};
support/testing/tests/package/test_uboot_tools/signed.its new file +38 -0
@@ -0,0 +1,38 @@ +/dts-v1/; + +/ { + description = "Signed test FIT"; + #address-cells = <1>; + + images { + kernel { + description = "This file, pretending to be a kernel"; + data = /incbin/("example.its"); + type = "kernel"; + arch = "arm64"; + os = "linux"; + compression = "none"; + load = <0x40400000>; + entry = <0x40400000>; + + hash-1 { + algo = "sha256"; + }; + }; + }; + + configurations { + default = "config-1"; + + config-1 { + description = "Signed test entry"; + kernel = "kernel"; + + signature-1 { + algo = "sha256,rsa2048"; + key-name-hint = "dev"; + sign-images = "kernel"; + }; + }; + }; +};
Signature · 6 lines
2.53.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Julien Olivain via buildroot
AppliedQuoted 23 lines · James Hilliard
U-Boot host tools use the tools configuration namespace when code calls
CONFIG_IS_ENABLED(). WithUSE_HOSTCC,CONFIG_IS_ENABLED(FIT_SIGNATURE)resolves toCONFIG_TOOLS_FIT_SIGNATURE, whileCONFIG_VAL(FIT_SIGNATURE_MAX_SIZE)resolves toCONFIG_TOOLS_FIT_SIGNATURE_MAX_SIZE.The host-uboot-tools package only generates the old
CONFIG_FIT_SIGNATUREdefine. This makestools/Makefileincludefit_check_sign, but the host code sees FIT signature support as disabled and the OpenSSL-backed signing and verification objects are omitted. As a result, mkimage accepts a signature node without writing its value or injecting a required public key.fit_check_signthen has no required key and reports success without checking the configuration signature.A FIT-support-only configuration never exercises this path, which is why the existing hash-only runtime test still passes.
Generate the tools FIT signature options needed by the host code and pass
CONFIG_TOOLS_LIBCRYPTO=yso the OpenSSL-backed signing, verification and cipher objects are selected. KeepCONFIG_FIT_SIGNATURE=yin the make options because U-Boottools/Makefilestill uses it to buildfit_check_sign.
Quoted 5 lines
Extend TestHostUbootTools to create an RSA-signed FIT, require a 256-byte configuration signature and a required public key, verify the FIT, corrupt the signature, and require verification to fail.
Signed-off-by James Hilliard <[email protected]>
Applied to master, thanks.
For info, I added comments in the runtime test, to explain the test sequence. See:
https://gitlab.com/buildroot.org/buildroot/-/commit/928cc5dc5cb82e6f2cb43f853488309eb806ef89
Best regards,
Julien.
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot