efi_loader: add secure boot support
Subsystems (5)
cover efi_loader: add secure boot support
One of major missing features in current UEFI implementation is "secure boot." The ultimate goal of my attempt is to implement image authentication based on signature and provide UEFI secure boot support which would be fully compliant with UEFI specification, section 32[1].
(The code was originally developed by Patrick Wildt.)
While this patch/RFC is still rough-edged, the aim here is to get early feedbacks from the community as the patch is quite huge (in total) and also as it's a security enhancement.
Please note, however, this patch doesn't work on its own; there are a couple of functional dependencies[2], [3] and [4], that I have submitted before, in addition to related preparatory patches[5], [6], [7] and [8] for pytest support. For complete workable patch set, see my repository[9], which also contains exeperimental timestamp-based revocation suuport.
My "non-volatile" support[10], which is under reviews now, is not mandatory and so not included here, but this inevitably implies that, for example, signature database variables, like db and dbx, won't be persistent unless you explicitly run "env save" command and that UEFI variables are not separated from U-Boot environment. Anyhow, Linaro is also working on implementing real "secure storage" solution based on TF-A and OP-TEE.
Supported features:
* image authentication based on db and dbx
* supported signature types are EFI_CERT_SHA256_GUID (SHA256 digest for unsigned images) EFI_CERT_X509_GUID (x509 certificate for signed images)
* SecureBoot/SignatureSupport variables
* SetupMode and user mode
* variable authentication based on PK and KEK EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
* pytest test cases
Unsupported features:
* hash algorithms other than SHA256
* dbt: timestamp(RFC6131)-based certificate revocation
* dbr: OS recovery
* xxxDefault: default values for signature stores
* transition to AuditMode and DeployedMode
* recording rejected images in EFI_IMAGE_EXECUTION_INFO_TABLE
* variable authentication based on PK and KEK EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS
* real secure storage, including hardware-specific PK (Platform Key) installation
Known issues:
* [3] and [4] have not been well reviewed yet.
* Some test case(test_efi_var_auth1:1g) still fails.
* Extensive clean-ups
* not bisect-ready (for easier code modification) for now
TODO:
* implement "unsupported" features, in particular, timestamp-based revocation
* fix some workarounds in the source (marked as TODO/FIXME)
* extensive test suite (or more test cases) to confirm compatibility with EDK2
Hints about how to use:
(Please see other documents, or my pytest scripts, for details.)
* You can create your own certificates with openssl.
* You can sign your application with pesign (on Ubuntu).
* You can create raw data for signature database with efitools, and install/manage authenticated variables with "env -set -e" command or efitools' "UpdateVars.efi" application.
[1] https://uefi.org/sites/default/files/resources/UEFI_Spec_2_8_final.pdf
[2] https://lists.denx.de/pipermail/u-boot/2019-September/382911.html
(support APPEND_WRITE)
[3] https://lists.denx.de/pipermail/u-boot/2019-September/382573.html
(import x509/pkcs7 parsers from linux)
[4] https://lists.denx.de/pipermail/u-boot/2019-September/382917.html
(extend rsa_verify() for UEFI secure boot)
[5] https://lists.denx.de/pipermail/u-boot/2019-August/382027.html
(sandbox: fix cpu property in test.dts for pytest)
[6] https://lists.denx.de/pipermail/u-boot/2019-September/382914.html
(extend "env [set|print] -e to manage UEFI variables v1)
[7] https://lists.denx.de/pipermail/u-boot/2019-September/383343.html
(install FILE_SYSTEM_PROTOCOL to a whole disk)
[8] https://lists.denx.de/pipermail/u-boot/2019-September/383348.html
(support Sandbox's "host" device)
[9] http://git.linaro.org/people/takahiro.akashi/u-boot.git/ efi/secboot
[10] https://lists.denx.de/pipermail/u-boot/2019-September/382835.html
(non-volatile variables support)
AKASHI Takahiro (15):
lib: charset: add u16_str<n>cmp()
test: add tests for u16_str<n>cmp()
include: pe.h: add image-signing-related definitions
include: image.h: add key info to image_sign_info
include: image.h: export hash algorithm helper functions secure boot: rename CONFIG_SECURE_BOOT
efi_loader: add signature verification functions
efi_loader: variable: support variable authentication
efi_loader: variable: add VendorKeys and SignatureSupport variables
efi_loader: image_loader: support image authentication
efi_loader: initialize secure boot state
efi_loader: add CONFIG_EFI_SECURE_BOOT
cmd: env: provide appropriate guid for well-defined variable efi_loader, pytest: add UEFI secure boot tests (image) efi_loader, pytest: add UEFI secure boot tests (authenticated
variables)
Kconfig | 7 + arch/arm/cpu/armv7/ls102xa/Kconfig | 3 +- arch/arm/cpu/armv8/fsl-layerscape/Kconfig | 3 +- arch/arm/mach-imx/Kconfig | 3 +- arch/powerpc/cpu/mpc85xx/Kconfig | 3 +- cmd/nvedit_efi.c | 31 +- include/charset.h | 15 + include/efi_api.h | 47 + include/efi_loader.h | 58 +- include/image.h | 17 +- include/pe.h | 16 + lib/charset.c | 25 + lib/efi_loader/Kconfig | 13 + lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_boottime.c | 2 +- lib/efi_loader/efi_image_loader.c | 364 ++++++- lib/efi_loader/efi_setup.c | 5 + lib/efi_loader/efi_signature.c | 602 ++++++++++++ lib/efi_loader/efi_variable.c | 928 ++++++++++++++++-- test/py/tests/test_efi_secboot/conftest.py | 168 ++++ test/py/tests/test_efi_secboot/defs.py | 7 + .../py/tests/test_efi_secboot/test_authvar.py | 287 ++++++ test/py/tests/test_efi_secboot/test_signed.py | 97 ++ .../tests/test_efi_secboot/test_unsigned.py | 126 +++ test/unicode_ut.c | 13 + 25 files changed, 2714 insertions(+), 127 deletions(-) create mode 100644 lib/efi_loader/efi_signature.c create mode 100644 test/py/tests/test_efi_secboot/conftest.py create mode 100644 test/py/tests/test_efi_secboot/defs.py create mode 100644 test/py/tests/test_efi_secboot/test_authvar.py create mode 100644 test/py/tests/test_efi_secboot/test_signed.py create mode 100644 test/py/tests/test_efi_secboot/test_unsigned.py
Signature · 1 line
2.21.0
RFC 1/15 lib: charset: add u16_str<n>cmp()
u16 version of strcmp(): u16_strncmp() works like u16_strcmp() but only at most n characters (in u16) are compared.
This function will be used in my UEFI secure boot patch.
--- include/charset.h | 15 +++++++++++++++ lib/charset.c | 25 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+)
include/charset.h +15 -0
@@ -168,6 +168,21 @@ s32 utf_to_lower(const s32 code);*/ s32 utf_to_upper (const s32 code); +/* +* u16_strncmp() - compare two u16 string +* +* @s1: first string to compare +* @s2: second string to compare +* @n: maximum number of u16 to compare +* Return: 0 if the first n u16 are the same in s1 and s2 +* < 0 if the first different u16 in s1 is less than the +* corresponding u16 in s2 +* > 0 if the first different u16 in s1 is greater than the +* corresponding u16 in s2 +*/ +int u16_strncmp (const u16 *s1,const u16 *s2,size_t n); +#define u16_strcmp (s1, s2) u16_strncmp((s1), (s2), SIZE_MAX) +/** * u16_strlen - count non-zero words *
lib/charset.c +25 -0
@@ -335,6 +335,31 @@ s32 utf_to_upper(const s32 code)return ret; } +/* +* u16_strncmp() - compare two u16 string +* +* @s1: first string to compare +* @s2: second string to compare +* @n: maximum number of u16 to compare +* Return: 0 if the first n u16 are the same in s1 and s2 +* < 0 if the first different u16 in s1 is less than the +* corresponding u16 in s2 +* > 0 if the first different u16 in s1 is greater than the +* corresponding u16 in s2 +*/ +int u16_strncmp (const u16 *s1,const u16 *s2,size_t n) +{ +int ret =0 ; + +for (; n; --n, ++s1, ++s2) { + ret = *s1 - *s2; +if (ret || !*s1) +break ; + } + +return ret; +} +size_t u16_strlen (const void *in) {const char *pos = in;
Signature · 1 line
2.21.0
RFC 1/15 lib: charset: add u16_str<n>cmp()
Quoted 5 lines · AKASHI Takahiro
u16 version of
strcmp():u16_strncmp()works likeu16_strcmp()but only at most n characters (in u16) are compared.
This function will be used in my UEFI secure boot patch.Signed-off-by AKASHI Takahiro <[email protected]>
RFC 2/15 test: add tests for u16_str<n>cmp()
In reply to AKASHI TakahiroNew seven test cases for u16_str<n>cmp() are added under Unicode unit test, which should be executed by "ut unicode" command.
--- test/unicode_ut.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
test/unicode_ut.c +13 -0
@@ -567,6 +567,19 @@ static int unicode_test_utf_to_upper(struct unit_test_state *uts) }UNICODE_TEST (unicode_test_utf_to_upper); +static int unicode_test_u16_strncmp (struct unit_test_state *uts) +{ +ut_assert (u16_strncmp (L"abc" ,L"abc" ,3 ) ==0 ); +ut_assert (u16_strncmp (L"abcdef" ,L"abcghi" ,3 ) ==0 ); +ut_assert (u16_strncmp (L"abcdef" ,L"abcghi" ,6 ) <0 ); +ut_assert (u16_strncmp (L"abcghi" ,L"abcdef" ,6 ) >0 ); +ut_assert (u16_strcmp (L"abc" ,L"abc" ) ==0 ); +ut_assert (u16_strcmp (L"abcdef" ,L"deghi" ) <0 ); +ut_assert (u16_strcmp (L"deghi" ,L"abcdef" ) >0 ); +return 0 ; +} +UNICODE_TEST (unicode_test_u16_strncmp); +int do_ut_unicode (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) { struct unit_test *tests = ll_entry_start(struct unit_test, unicode_test);
Signature · 1 line
2.21.0
RFC 2/15 test: add tests for u16_str<n>cmp()
Quoted 4 lines · AKASHI Takahiro
New seven test cases for u16_str<n>cmp() are added under Unicode unit test, which should be executed by "ut unicode" command.
Signed-off-by AKASHI Takahiro <[email protected]>
RFC 3/15 include: pe.h: add image-signing-related definitions
In reply to AKASHI TakahiroThe index (IMAGE_DIRECTORY_ENTRY_CERTTABLE) in a table points to a region containing authentication information (image's signature) in PE format.
WIN_CERTIFICATE structure defines an embedded signature format.
Those definitions will be used in my UEFI secure boot patch.
--- include/pe.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
include/pe.h +16 -0
@@ -155,6 +155,7 @@ typedef struct _IMAGE_SECTION_HEADER {uint32_t Characteristics; }IMAGE_SECTION_HEADER , *PIMAGE_SECTION_HEADER ; +#define IMAGE_DIRECTORY_ENTRY_CERTTABLE 4#define IMAGE_DIRECTORY_ENTRY_BASERELOC 5 typedef struct _IMAGE_BASE_RELOCATION
@@ -252,4 +253,19 @@ typedef struct _IMAGE_RELOCATION#define IMAGE_REL_AMD64_PAIR 0x000F#define IMAGE_REL_AMD64_SSPAN32 0x0010 +/* certificate appended to PE image */ +typedef struct _WIN_CERTIFICATE { +uint32_t dwLength; +uint16_t wRevision; +uint16_t wCertificateType; +uint8_t bCertificate[]; +}WIN_CERTIFICATE , *LPWIN_CERTIFICATE ; + +#define WIN_CERT_TYPE_PKCS_SIGNED_DATA 0x0002 +#define WIN_CERT_TYPE_EFI_OKCS115 0x0EF0 +#define WIN_CERT_TYPE_EFI_GUID 0x0EF1 + +#define WIN_CERT_REVISION_1_0 0x0100 +#define WIN_CERT_REVISION_2_0 0x0200 +#endif /* _PE_H */
Signature · 1 line
2.21.0
RFC 4/15 include: image.h: add key info to image_sign_info
In reply to AKASHI TakahiroFor FIT verification, all the properties of a public key come from "control fdt" pointed to by fdt_blob. In UEFI secure boot, on the other hand, a public key is located and retrieved from dedicated signature database stored as UEFI variables.
Added two fields may hold values of a public key if fdt_blob is NULL, and will be used in rsa_verify_with_pkey() to verify a signature in UEFI sub-system.
--- include/image.h | 2 ++ 1 file changed, 2 insertions(+)
include/image.h +2 -0
@@ -1136,6 +1136,8 @@ struct image_sign_info {struct checksum_algo *checksum;/* Checksum algorithm information */ struct padding_algo *padding;/* Padding algorithm information */ struct crypto_algo *crypto;/* Crypto algorithm information */ +const void *key; +int keylen;const void *fdt_blob;/* FDT containing public keys */ int required_keynode;/* Node offset of key to use: -1=any */ const char *require_keys;/* Value for 'required' property */
Signature · 1 line
2.21.0
RFC 4/15 include: image.h: add key info to image_sign_info
Hi AKASHI,
Quoted 20 lines · AKASHI Takahiro
For FIT verification, all the properties of a public key come from "control fdt" pointed to by
fdt_blob. In UEFI secure boot, on the other hand, a public key is located and retrieved from dedicated signature database stored as UEFI variables.Added two fields may hold values of a public key if
fdt_blobis NULL, and will be used inrsa_verify_with_pkey()to verify a signature in UEFI sub-system.Signed-off-by AKASHI Takahiro <[email protected]>--- include/image.h | 2 ++ 1 file changed, 2 insertions(+)include/image.h +0
-0
include/image.h struct image_sign_info { · line 1140
Quoted 5 lines
include/image.h +2
-0@@ -1136,6 +1136,8 @@ struct image_sign_info {struct checksum_algo *checksum;/* Checksum algorithm information */ struct padding_algo *padding;/* Padding algorithm information */ struct crypto_algo *crypto;/* Crypto algorithm information */ +const void *key; +int keylen;
Please do add comments.
Also if these only relate to EFI they should have efi_ prefix and probably an #ifdef.
Quoted 6 lines
include/image.h +0
-1const void *fdt_blob;/* FDT containing public keys */ int required_keynode;/* Node offset of key to use: -1=any */ const char *require_keys;/* Value for 'required' property */ --2.21.0
Regards,
Simon
RFC 5/15 include: image.h: export hash algorithm helper functions
In reply to AKASHI TakahiroThis commit allows us to use common/image-sig.c even if CONFIG_FIT is disabled but CONFIG_EFI_LOADER is enabled.
--- include/image.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
include/image.h +9 -6
@@ -53,7 +53,7 @@ struct fdt_region;#endif /* USE_HOSTCC */ -#if IMAGE_ENABLE_FIT +#if IMAGE_ENABLE_FIT || defined(CONFIG_EFI_SECURE_BOOT )#include <hash.h> #include <linux/libfdt.h> #include <fdt_support.h>
@@ -86,13 +86,14 @@ struct fdt_region;#endif #if defined(CONFIG_FIT_ENABLE_SHA256_SUPPORT ) || \ - defined(CONFIG_SPL_SHA256_SUPPORT ) + defined(CONFIG_SPL_SHA256_SUPPORT ) || \ + defined(CONFIG_EFI_SECURE_BOOT )#define IMAGE_ENABLE_SHA256 1#else #define IMAGE_ENABLE_SHA256 0#endif -#endif /* IMAGE_ENABLE_FIT */ +#endif /* IMAGE_ENABLE_FIT || defined(CONFIG_EFI_SECURE_BOOT) */ #ifdef CONFIG_SYS_BOOT_GET_CMDLINE # define IMAGE_BOOT_GET_CMDLINE 1
@@ -1085,6 +1086,7 @@ int fit_conf_get_prop_node(const void *fit, int noffset,int fit_check_ramdisk (const void *fit,int os_noffset,uint8_t arch,int verify); +#endif /* IMAGE_ENABLE_FIT */ int calculate_hash (const void *data,int data_len,const char *algo,uint8_t *value,int *value_len);
@@ -1143,7 +1145,6 @@ struct image_sign_info {const char *require_keys;/* Value for 'required' property */ const char *engine_id;/* Engine to use for signing */ }; -#endif /* Allow struct image_region to always be defined for rsa.h */ /* A part of an image, used for hashing */ struct image_region {
@@ -1151,7 +1152,7 @@ struct image_region {int size; }; -#if IMAGE_ENABLE_FIT +#if IMAGE_ENABLE_FIT || defined(CONFIG_EFI_SECURE_BOOT )#if IMAGE_ENABLE_VERIFY # include <u-boot/rsa-checksum.h>
@@ -1252,7 +1253,9 @@ struct crypto_algo *image_get_crypto_algo(const char *full_name);* @return pointer to algorithm information, or NULL if not found */ struct padding_algo *image_get_padding_algo (const char *name); +#endif /* IMAGE_ENABLE_FIT || defined(CONFIG_EFI_SECURE_BOOT) */ +#if IMAGE_ENABLE_FIT /** * fit_image_verify_required_sigs() - Verify signatures marked as 'required' *
@@ -1328,7 +1331,7 @@ static inline int fit_image_check_target_arch(const void *fdt, int node)#define fit_unsupported (msg)#define fit_unsupported_reset (msg)#endif /* CONFIG_FIT_VERBOSE */ -#endif /* CONFIG_FIT */ +#endif /* IMAGE_ENABLE_FIT */ #if defined(CONFIG_ANDROID_BOOT_IMAGE )struct andr_img_hdr ;
Signature · 1 line
2.21.0
RFC 5/15 include: image.h: export hash algorithm helper functions
Quoted 8 lines · AKASHI Takahiro
This commit allows us to use
common/image-sig.ceven ifCONFIG_FITis disabled butCONFIG_EFI_LOADERis enabled.Signed-off-by AKASHI Takahiro <[email protected]>--- include/image.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
BTW I think it should be possible to remove these things in the header file now. Please see below.
Quoted 15 lines
include/image.h +1
-1@@ -53,7 +53,7 @@ struct fdt_region;#endif /* USE_HOSTCC */ -#if IMAGE_ENABLE_FIT +#if IMAGE_ENABLE_FIT || defined(CONFIG_EFI_SECURE_BOOT )#include <hash.h> #include <linux/libfdt.h> #include <fdt_support.h>
include/image.h struct fdt_region; · line 94
Quoted 10 lines
include/image.h +2
-1@@ -86,13 +86,14 @@ struct fdt_region;#endif #if defined(CONFIG_FIT_ENABLE_SHA256_SUPPORT ) || \ - defined(CONFIG_SPL_SHA256_SUPPORT ) + defined(CONFIG_SPL_SHA256_SUPPORT ) || \ + defined(CONFIG_EFI_SECURE_BOOT )#define IMAGE_ENABLE_SHA256 1#else #define IMAGE_ENABLE_SHA256 0#endif
We can probably use (in the C file):
if (IS_ENABLED(CONFIG_...) || IS_ENABLED(CONFIG_...) ...
Quoted 51 lines
include/image.h +6
-5-#endif /* IMAGE_ENABLE_FIT */ +#endif /* IMAGE_ENABLE_FIT || defined(CONFIG_EFI_SECURE_BOOT) */ #ifdef CONFIG_SYS_BOOT_GET_CMDLINE # define IMAGE_BOOT_GET_CMDLINE 1@@ -1085,6 +1086,7 @@ int fit_conf_get_prop_node(const void *fit, int noffset,int fit_check_ramdisk (const void *fit,int os_noffset,uint8_t arch,int verify); +#endif /* IMAGE_ENABLE_FIT */ int calculate_hash (const void *data,int data_len,const char *algo,uint8_t *value,int *value_len);@@ -1143,7 +1145,6 @@ struct image_sign_info {const char *require_keys;/* Value for 'required' property */ const char *engine_id;/* Engine to use for signing */ }; -#endif /* Allow struct image_region to always be defined for rsa.h */ /* A part of an image, used for hashing */ struct image_region {@@ -1151,7 +1152,7 @@ struct image_region {int size; }; -#if IMAGE_ENABLE_FIT +#if IMAGE_ENABLE_FIT || defined(CONFIG_EFI_SECURE_BOOT )#if IMAGE_ENABLE_VERIFY # include <u-boot/rsa-checksum.h> @@ -1252,7 +1253,9 @@ struct crypto_algo *image_get_crypto_algo(const char *full_name);* @return pointer to algorithm information, or NULL if not found */ struct padding_algo *image_get_padding_algo (const char *name); +#endif /* IMAGE_ENABLE_FIT || defined(CONFIG_EFI_SECURE_BOOT) */ +#if IMAGE_ENABLE_FIT /** * fit_image_verify_required_sigs() - Verify signatures marked as 'required' * @@ -1328,7 +1331,7 @@ static inline int fit_image_check_target_arch(const void *fdt, int node)#define fit_unsupported (msg)#define fit_unsupported_reset (msg)#endif /* CONFIG_FIT_VERBOSE */ -#endif /* CONFIG_FIT */ +#endif /* IMAGE_ENABLE_FIT */ #if defined(CONFIG_ANDROID_BOOT_IMAGE )struct andr_img_hdr ; --
Quoted 2 lines
2.21.0
Regards,
Simon
RFC 6/15 secure boot: rename CONFIG_SECURE_BOOT
In reply to AKASHI TakahiroThe configuration, CONFIG_SECURE_BOOT, was scattered among different architecture directories for different implementation. This will prevent UEFI secure boot from being added later.
So let's rename them, giving each implementation to different configuration option. CONFIG_SECURE_BOOT still remains not to break existing implicit dependency.
--- Kconfig | 7 +++++++ arch/arm/cpu/armv7/ls102xa/Kconfig | 3 ++- arch/arm/cpu/armv8/fsl-layerscape/Kconfig | 3 ++- arch/arm/mach-imx/Kconfig | 3 ++- arch/powerpc/cpu/mpc85xx/Kconfig | 3 ++- 5 files changed, 15 insertions(+), 4 deletions(-)
Kconfig +7 -0
@@ -282,6 +282,13 @@ config SYS_LDSCRIPT endmenu # General setup +config SECURE_BOOT + bool "Secure Boot" + imply SHA256 + help + Enable Secure Boot feature. The actual behavior may vary + from architecture to architecture. + menu "Boot images" config ANDROID_BOOT_IMAGE
arch/arm/cpu/armv7/ls102xa/Kconfig +2 -1
@@ -50,8 +50,9 @@ config MAX_CPUS cores, count the reserved ports. This will allocate enough memory in spin table to properly handle all cores. -config SECURE_BOOT +config FSL_ARMV7_ENABLE_SECURE_BOOT bool "Secure Boot" + depends on SECURE_BOOT help Enable Freescale Secure Boot feature. Normally selected by defconfig. If unsure, do not change.
arch/arm/cpu/armv8/fsl-layerscape/Kconfig +2 -1
@@ -383,8 +383,9 @@ config EMC2305 Enable the EMC2305 fan controller for configuration of fan speed. -config SECURE_BOOT +config FSI_ARMV8_ENABLE_SECURE_BOOT bool "Secure Boot" + depends on SECURE_BOOT help Enable Freescale Secure Boot feature
arch/arm/mach-imx/Kconfig +2 -1
@@ -34,8 +34,9 @@ config USE_IMXIMG_PLUGIN i.MX6/7 supports DCD and Plugin. Enable this configuration to use Plugin, otherwise DCD will be used. -config SECURE_BOOT +config FSL_IMX_ENABLE_SECURE_BOOT bool "Support i.MX HAB features" + depends on SECURE_BOOT depends on ARCH_MX7 || ARCH_MX6 || ARCH_MX5 select FSL_CAAM if HAS_CAAM imply CMD_DEKBLOB
arch/powerpc/cpu/mpc85xx/Kconfig +2 -1
@@ -1208,8 +1208,9 @@ config FSL_LAW help Use Freescale common code for Local Access Window -config SECURE_BOOT +config FSL_MPC_ENABLE_SECURE_BOOT bool "Secure Boot" + depends on SECURE_BOOT help Enable Freescale Secure Boot feature. Normally selected by defconfig. If unsure, do not change.
Signature · 1 line
2.21.0
RFC 6/15 secure boot: rename CONFIG_SECURE_BOOT
Quoted 85 lines · AKASHI Takahiro
The configuration,
CONFIG_SECURE_BOOT, was scattered among different architecture directories for different implementation. This will prevent UEFI secure boot from being added later.So let's rename them, giving each implementation to different configuration option.
CONFIG_SECURE_BOOTstill remains not to break existing implicit dependency.Signed-off-by AKASHI Takahiro <[email protected]>--- Kconfig | 7 +++++++ arch/arm/cpu/armv7/ls102xa/Kconfig | 3 ++- arch/arm/cpu/armv8/fsl-layerscape/Kconfig | 3 ++- arch/arm/mach-imx/Kconfig | 3 ++- arch/powerpc/cpu/mpc85xx/Kconfig | 3 ++- 5 files changed, 15 insertions(+), 4 deletions(-)Kconfig +7
-0@@ -282,6 +282,13 @@ config SYS_LDSCRIPT endmenu # General setup +config SECURE_BOOT + bool "Secure Boot" + imply SHA256 + help + Enable Secure Boot feature. The actual behavior may vary + from architecture to architecture. + menu "Boot images" config ANDROID_BOOT_IMAGEarch/arm/cpu/armv7/ls102xa/Kconfig +2
-1@@ -50,8 +50,9 @@ config MAX_CPUS cores, count the reserved ports. This will allocate enough memory in spin table to properly handle all cores. -config SECURE_BOOT +config FSL_ARMV7_ENABLE_SECURE_BOOT bool "Secure Boot" + depends on SECURE_BOOT help Enable Freescale Secure Boot feature. Normally selected by defconfig. If unsure, do not change.arch/arm/cpu/armv8/fsl-layerscape/Kconfig +2
-1@@ -383,8 +383,9 @@ config EMC2305 Enable the EMC2305 fan controller for configuration of fan speed. -config SECURE_BOOT +config FSI_ARMV8_ENABLE_SECURE_BOOT bool "Secure Boot" + depends on SECURE_BOOT help Enable Freescale Secure Boot featurearch/arm/mach-imx/Kconfig +2
-1@@ -34,8 +34,9 @@ config USE_IMXIMG_PLUGIN i.MX6/7 supports DCD and Plugin. Enable this configuration to use Plugin, otherwise DCD will be used. -config SECURE_BOOT +config FSL_IMX_ENABLE_SECURE_BOOT bool "Support i.MX HAB features" + depends on SECURE_BOOT depends on ARCH_MX7 || ARCH_MX6 || ARCH_MX5 select FSL_CAAM if HAS_CAAM imply CMD_DEKBLOBarch/powerpc/cpu/mpc85xx/Kconfig +0
-0
arch/powerpc/cpu/mpc85xx/Kconfig config FSL_LAW · line 1216
Quoted 10 lines
arch/powerpc/cpu/mpc85xx/Kconfig +2
-1@@ -1208,8 +1208,9 @@ config FSL_LAW help Use Freescale common code for Local Access Window -config SECURE_BOOT +config FSL_MPC_ENABLE_SECURE_BOOT bool "Secure Boot" + depends on SECURE_BOOT help Enable Freescale Secure Boot feature. Normally selected by defconfig. If unsure, do not change.
I've added Priyanka Jain to the thread as the custodian for PowerPC and NXP stuff and Stefano Babic as the custodian for i.MX stuff. I don't want to see "CONFIG_SECURE_BOOT" continue on as a config option, it's too broad. Can we please rename and update the existing NXP CONFIG option (and I assume split it into a few ones to reflect better where things really changed fundamentally from one SoC/arch to the next) and update the help text? Thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190919/2861475d/attachment.sig>
RFC 6/15 secure boot: rename CONFIG_SECURE_BOOT
Quoted 90 lines · Tom Rini
Quoted 88 lines · AKASHI Takahiro
The configuration,
CONFIG_SECURE_BOOT, was scattered among different architecture directories for different implementation. This will prevent UEFI secure boot from being added later.So let's rename them, giving each implementation to different configuration option.
CONFIG_SECURE_BOOTstill remains not to break existing implicit dependency.Signed-off-by AKASHI Takahiro <[email protected]>--- Kconfig | 7 +++++++ arch/arm/cpu/armv7/ls102xa/Kconfig | 3 ++- arch/arm/cpu/armv8/fsl-layerscape/Kconfig | 3 ++- arch/arm/mach-imx/Kconfig | 3 ++- arch/powerpc/cpu/mpc85xx/Kconfig | 3 ++- 5 files changed, 15 insertions(+), 4 deletions(-)Kconfig +7
-0@@ -282,6 +282,13 @@ config SYS_LDSCRIPT endmenu # General setup +config SECURE_BOOT + bool "Secure Boot" + imply SHA256 + help + Enable Secure Boot feature. The actual behavior may vary + from architecture to architecture. + menu "Boot images" config ANDROID_BOOT_IMAGEarch/arm/cpu/armv7/ls102xa/Kconfig +2
-1@@ -50,8 +50,9 @@ config MAX_CPUS cores, count the reserved ports. This will allocate enough memory in spin table to properly handle all cores. -config SECURE_BOOT +config FSL_ARMV7_ENABLE_SECURE_BOOT bool "Secure Boot" + depends on SECURE_BOOT help Enable Freescale Secure Boot feature. Normally selected by defconfig. If unsure, do not change.arch/arm/cpu/armv8/fsl-layerscape/Kconfig +2
-1@@ -383,8 +383,9 @@ config EMC2305 Enable the EMC2305 fan controller for configuration of fan speed. -config SECURE_BOOT +config FSI_ARMV8_ENABLE_SECURE_BOOT bool "Secure Boot" + depends on SECURE_BOOT help Enable Freescale Secure Boot featurearch/arm/mach-imx/Kconfig +2
-1@@ -34,8 +34,9 @@ config USE_IMXIMG_PLUGIN i.MX6/7 supports DCD and Plugin. Enable this configuration to use Plugin, otherwise DCD will be used. -config SECURE_BOOT +config FSL_IMX_ENABLE_SECURE_BOOT bool "Support i.MX HAB features" + depends on SECURE_BOOT depends on ARCH_MX7 || ARCH_MX6 || ARCH_MX5 select FSL_CAAM if HAS_CAAM imply CMD_DEKBLOBarch/powerpc/cpu/mpc85xx/Kconfig +0
-0@@ -1208,8 +1208,9 @@ config FSL_LAW help Use Freescale common code for Local Access Window
Quoted 15 lines
arch/powerpc/cpu/mpc85xx/Kconfig config FSL_LAW · line 1216
Quoted 7 lines
arch/powerpc/cpu/mpc85xx/Kconfig +2
-1-config SECURE_BOOT +config FSL_MPC_ENABLE_SECURE_BOOT bool "Secure Boot" + depends on SECURE_BOOT help Enable Freescale Secure Boot feature. Normally selected by defconfig. If unsure, do not change.I've added Priyanka Jain to the thread as the custodian for PowerPC and NXP stuff and Stefano Babic as the custodian for i.MX stuff. I don't want to see "
CONFIG_SECURE_BOOT" continue on as a config option, it's too broad. Can we please rename and update the existing NXP CONFIG option (and I assume split it into a few ones to reflect better where things really changed fundamentally from one SoC/arch to the next) and update the help text? Thanks!
Sure - SECURE_BOOT for NXP means enabling HAB, a config can be rename to identify the component itself (CONFIG_HAB for example).
Regards,
Stefano
Signature · 5 lines
===================================================================== DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de =====================================================================
RFC 6/15 secure boot: rename CONFIG_SECURE_BOOT
Quoted 121 lines
-----Original Message-----
From: Stefano Babic <[email protected]>
Sent: Thursday, September 19, 2019 8:40 PM
To: Tom Rini <[email protected]>; AKASHI Takahiro <[email protected]>; Priyanka Jain <[email protected]>; Stefano Babic <[email protected]>
Cc: xypron.glpk at gmx.de; agraf at csgraf.de; u-boot at lists.denx.de
Subject: Re: [U-Boot] [RFC 06/15] secure boot: renameCONFIG_SECURE_BOOTQuoted 93 lines · Tom Rini
Quoted 91 lines · AKASHI Takahiro
The configuration,
CONFIG_SECURE_BOOT, was scattered among different architecture directories for different implementation. This will prevent UEFI secure boot from being added later.So let's rename them, giving each implementation to different configuration option.
CONFIG_SECURE_BOOTstill remains not to break existing implicit dependency.Signed-off-by AKASHI Takahiro <[email protected]>--- Kconfig | 7 +++++++ arch/arm/cpu/armv7/ls102xa/Kconfig | 3 ++- arch/arm/cpu/armv8/fsl-layerscape/Kconfig | 3 ++- arch/arm/mach-imx/Kconfig | 3 ++- arch/powerpc/cpu/mpc85xx/Kconfig | 3 ++- 5 files changed, 15 insertions(+), 4 deletions(-)Kconfig +7
-0@@ -282,6 +282,13 @@ config SYS_LDSCRIPT endmenu # General setup +config SECURE_BOOT + bool "Secure Boot" + imply SHA256 + help + Enable Secure Boot feature. The actual behavior may vary + from architecture to architecture. + menu "Boot images" config ANDROID_BOOT_IMAGEarch/arm/cpu/armv7/ls102xa/Kconfig +2
-1@@ -50,8 +50,9 @@ config MAX_CPUS cores, count the reserved ports. This will allocate enough memory in spin table to properly handle all cores. -config SECURE_BOOT +config FSL_ARMV7_ENABLE_SECURE_BOOT bool "Secure Boot" + depends on SECURE_BOOT help Enable Freescale Secure Boot feature. Normally selected by defconfig. If unsure, do not change.arch/arm/cpu/armv8/fsl-layerscape/Kconfig +2
-1@@ -383,8 +383,9 @@ config EMC2305 Enable the EMC2305 fan controller for configuration of fan speed. -config SECURE_BOOT +config FSI_ARMV8_ENABLE_SECURE_BOOT bool "Secure Boot" + depends on SECURE_BOOT help Enable Freescale Secure Boot featurearch/arm/mach-imx/Kconfig +2
-1@@ -34,8 +34,9 @@ config USE_IMXIMG_PLUGIN i.MX6/7 supports DCD and Plugin. Enable this configuration to use Plugin, otherwise DCD will be used. -config SECURE_BOOT +config FSL_IMX_ENABLE_SECURE_BOOT bool "Support i.MX HAB features" + depends on SECURE_BOOT depends on ARCH_MX7 || ARCH_MX6 || ARCH_MX5 select FSL_CAAM if HAS_CAAM imply CMD_DEKBLOBarch/powerpc/cpu/mpc85xx/Kconfig +0
-0@@ -1208,8 +1208,9 @@ config FSL_LAW help Use Freescale common code for Local Access WindowQuoted 15 lines
arch/powerpc/cpu/mpc85xx/Kconfig config FSL_LAW · line 1216
Quoted 7 lines
arch/powerpc/cpu/mpc85xx/Kconfig +2
-1-config SECURE_BOOT +config FSL_MPC_ENABLE_SECURE_BOOT bool "Secure Boot" + depends on SECURE_BOOT help Enable Freescale Secure Boot feature. Normally selected by defconfig. If unsure, do not change.I've added Priyanka Jain to the thread as the custodian for PowerPC and NXP stuff and Stefano Babic as the custodian for i.MX stuff. I don't want to see "
CONFIG_SECURE_BOOT" continue on as a config option, it's too broad. Can we please rename and update the existing NXP CONFIG option (and I assume split it into a few ones to reflect better where things really changed fundamentally from one SoC/arch to the next) and update the help text? Thanks!
Quoted 6 lines
Sure -
SECURE_BOOTfor NXP means enabling HAB, a config can be rename to identify the component itself (CONFIG_HABfor example).Regards,
Stefano
Sure, We will look into this and update NXP CONFIG_SECURE_BOOT option. Priyanka
Quoted 9 lines
--
================================================================
=====
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
================================================================
=====
RFC 6/15 secure boot: rename CONFIG_SECURE_BOOT
Priyanka, Stefano and Tom,
Quoted 121 lines · Priyanka Jain
Quoted 121 lines
-----Original Message-----
From: Stefano Babic <[email protected]>
Sent: Thursday, September 19, 2019 8:40 PM
To: Tom Rini <[email protected]>; AKASHI Takahiro <[email protected]>; Priyanka Jain <[email protected]>; Stefano Babic <[email protected]>
Cc: xypron.glpk at gmx.de; agraf at csgraf.de; u-boot at lists.denx.de
Subject: Re: [U-Boot] [RFC 06/15] secure boot: renameCONFIG_SECURE_BOOTQuoted 108 lines · Tom Rini
Quoted 88 lines · AKASHI Takahiro
The configuration,
CONFIG_SECURE_BOOT, was scattered among different architecture directories for different implementation. This will prevent UEFI secure boot from being added later.So let's rename them, giving each implementation to different configuration option.
CONFIG_SECURE_BOOTstill remains not to break existing implicit dependency.Signed-off-by AKASHI Takahiro <[email protected]>--- Kconfig | 7 +++++++ arch/arm/cpu/armv7/ls102xa/Kconfig | 3 ++- arch/arm/cpu/armv8/fsl-layerscape/Kconfig | 3 ++- arch/arm/mach-imx/Kconfig | 3 ++- arch/powerpc/cpu/mpc85xx/Kconfig | 3 ++- 5 files changed, 15 insertions(+), 4 deletions(-)Kconfig +7
-0@@ -282,6 +282,13 @@ config SYS_LDSCRIPT endmenu # General setup +config SECURE_BOOT + bool "Secure Boot" + imply SHA256 + help + Enable Secure Boot feature. The actual behavior may vary + from architecture to architecture. + menu "Boot images" config ANDROID_BOOT_IMAGEarch/arm/cpu/armv7/ls102xa/Kconfig +2
-1@@ -50,8 +50,9 @@ config MAX_CPUS cores, count the reserved ports. This will allocate enough memory in spin table to properly handle all cores. -config SECURE_BOOT +config FSL_ARMV7_ENABLE_SECURE_BOOT bool "Secure Boot" + depends on SECURE_BOOT help Enable Freescale Secure Boot feature. Normally selected by defconfig. If unsure, do not change.arch/arm/cpu/armv8/fsl-layerscape/Kconfig +2
-1@@ -383,8 +383,9 @@ config EMC2305 Enable the EMC2305 fan controller for configuration of fan speed. -config SECURE_BOOT +config FSI_ARMV8_ENABLE_SECURE_BOOT bool "Secure Boot" + depends on SECURE_BOOT help Enable Freescale Secure Boot featurearch/arm/mach-imx/Kconfig +2
-1@@ -34,8 +34,9 @@ config USE_IMXIMG_PLUGIN i.MX6/7 supports DCD and Plugin. Enable this configuration to use Plugin, otherwise DCD will be used. -config SECURE_BOOT +config FSL_IMX_ENABLE_SECURE_BOOT bool "Support i.MX HAB features" + depends on SECURE_BOOT depends on ARCH_MX7 || ARCH_MX6 || ARCH_MX5 select FSL_CAAM if HAS_CAAM imply CMD_DEKBLOBarch/powerpc/cpu/mpc85xx/Kconfig +0
-0arch/powerpc/cpu/mpc85xx/Kconfig config FSL_LAW · line 1216
Quoted 10 lines
arch/powerpc/cpu/mpc85xx/Kconfig +2
-1@@ -1208,8 +1208,9 @@ config FSL_LAW help Use Freescale common code for Local Access Window -config SECURE_BOOT +config FSL_MPC_ENABLE_SECURE_BOOT bool "Secure Boot" + depends on SECURE_BOOT help Enable Freescale Secure Boot feature. Normally selected by defconfig. If unsure, do not change.I've added Priyanka Jain to the thread as the custodian for PowerPC and NXP stuff and Stefano Babic as the custodian for i.MX stuff. I don't want to see "
CONFIG_SECURE_BOOT" continue on as a config option, it's too broad. Can we please rename and update the existing NXP CONFIG option (and I assume split it into a few ones to reflect better where things really changed fundamentally from one SoC/arch to the next) and update the help text? Thanks!
Quoted 8 lines
Quoted 6 lines
Sure -
SECURE_BOOTfor NXP means enabling HAB, a config can be rename to identify the component itself (CONFIG_HABfor example).Regards,
StefanoSure, We will look into this and update NXP
CONFIG_SECURE_BOOToption. Priyanka
Can we expect this re-work on NXP/Freescal platforms to be done in the current release cycle, that is v2020.01?
If not, can I continue to use my match[1] as part of my UEFI secure boot patch set for the time being?
[1] https://lists.denx.de/pipermail/u-boot/2019-September/383908.html
Thanks,
-Takahiro Akashi
Quoted 9 lines
Quoted 9 lines
--
================================================================
=====
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
================================================================
=====
RFC 6/15 secure boot: rename CONFIG_SECURE_BOOT
Quoted 139 lines
-----Original Message-----
From: AKASHI Takahiro <[email protected]>
Sent: Tuesday, October 29, 2019 10:49 AM
To: Priyanka Jain <[email protected]>; Stefano Babic <[email protected]>
Cc: Tom Rini <[email protected]>; Udit Agarwal <[email protected]>; xypron.glpk at gmx.de; agraf at csgraf.de; u-boot at lists.denx.de
Subject: Re: [U-Boot] [RFC 06/15] secure boot: renameCONFIG_SECURE_BOOTPriyanka, Stefano and Tom,
Quoted 126 lines · Priyanka Jain
Quoted 126 lines
-----Original Message-----
From: Stefano Babic <[email protected]>
Sent: Thursday, September 19, 2019 8:40 PM
To: Tom Rini <[email protected]>; AKASHI Takahiro <[email protected]>; Priyanka Jain <[email protected]>; Stefano Babic <[email protected]>
Cc: xypron.glpk at gmx.de; agraf at csgraf.de; u-boot at lists.denx.de
Subject: Re: [U-Boot] [RFC 06/15] secure boot: renameCONFIG_SECURE_BOOTQuoted 93 lines · Tom Rini
Quoted 91 lines · AKASHI Takahiro
The configuration,
CONFIG_SECURE_BOOT, was scattered among different architecture directories for different implementation. This will prevent UEFI secure boot from being added later.So let's rename them, giving each implementation to different configuration option.
CONFIG_SECURE_BOOTstill remains not to break existing implicit dependency.Signed-off-by AKASHI Takahiro <[email protected]>--- Kconfig | 7 +++++++ arch/arm/cpu/armv7/ls102xa/Kconfig | 3 ++- arch/arm/cpu/armv8/fsl-layerscape/Kconfig | 3 ++- arch/arm/mach-imx/Kconfig | 3 ++- arch/powerpc/cpu/mpc85xx/Kconfig | 3 ++- 5 files changed, 15 insertions(+), 4 deletions(-)Kconfig +7
-0@@ -282,6 +282,13 @@ config SYS_LDSCRIPT endmenu # General setup +config SECURE_BOOT + bool "Secure Boot" + imply SHA256 + help + Enable Secure Boot feature. The actual behavior may vary + from architecture to architecture. + menu "Boot images" config ANDROID_BOOT_IMAGEarch/arm/cpu/armv7/ls102xa/Kconfig +2
-1@@ -50,8 +50,9 @@ config MAX_CPUS cores, count the reserved ports. This will allocate enough memory in spin table to properly handle all cores. -config SECURE_BOOT +config FSL_ARMV7_ENABLE_SECURE_BOOT bool "Secure Boot" + depends on SECURE_BOOT help Enable Freescale Secure Boot feature. Normally selected by defconfig. If unsure, do not change.arch/arm/cpu/armv8/fsl-layerscape/Kconfig +2
-1@@ -383,8 +383,9 @@ config EMC2305 Enable the EMC2305 fan controller for configuration of fan speed. -config SECURE_BOOT +config FSI_ARMV8_ENABLE_SECURE_BOOT bool "Secure Boot" + depends on SECURE_BOOT help Enable Freescale Secure Boot featurearch/arm/mach-imx/Kconfig +2
-1@@ -34,8 +34,9 @@ config USE_IMXIMG_PLUGIN i.MX6/7 supports DCD and Plugin. Enable this configuration to use Plugin, otherwise DCD will be used. -config SECURE_BOOT +config FSL_IMX_ENABLE_SECURE_BOOT bool "Support i.MX HAB features" + depends on SECURE_BOOT depends on ARCH_MX7 || ARCH_MX6 || ARCH_MX5 select FSL_CAAM if HAS_CAAM imply CMD_DEKBLOBarch/powerpc/cpu/mpc85xx/Kconfig +0
-0@@ -1208,8 +1208,9 @@ config FSL_LAW help Use Freescale common code for Local Access WindowQuoted 16 lines
arch/powerpc/cpu/mpc85xx/Kconfig config FSL_LAW · line 1216
Quoted 7 lines
arch/powerpc/cpu/mpc85xx/Kconfig +2
-1-config SECURE_BOOT +config FSL_MPC_ENABLE_SECURE_BOOT bool "Secure Boot" + depends on SECURE_BOOT help Enable Freescale Secure Boot feature. Normally selected by defconfig. If unsure, do not change.I've added Priyanka Jain to the thread as the custodian for PowerPC and NXP stuff and Stefano Babic as the custodian for i.MX stuff. I don't want to see "
CONFIG_SECURE_BOOT" continue on as a config option, it's too broad. Can we please rename and update the existing NXP CONFIG option (and I assume split it into a few ones to reflect better where things really changed fundamentally from one SoC/arch to the
next) and update the help text? Thanks!Sure -
SECURE_BOOTfor NXP means enabling HAB, a config can be rename to identify the component itself (CONFIG_HABfor example).
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
Regards,
StefanoSure, We will look into this and update NXP
CONFIG_SECURE_BOOToption. PriyankaCan we expect this re-work on NXP/Freescal platforms to be done in the current release cycle, that is v2020.01?
Yes, we are working on the changes for NXP ARM and mpc85xx platforms.
Regards
Priyanka
Quoted 26 lines
If not, can I continue to use my match[1] as part of my UEFI secure boot patch set for the time being?
[1]
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.de
nx.de%2Fpipermail%2Fu-boot%2F2019- September%2F383908.html&data=02%7C01%7Cpriyanka.jain%40nxp.com %7C00a34480e43c4950cb0808d75c2f836b%7C686ea1d3bc2b4c6fa92cd99c5c30 1635%7C0%7C0%7C637079231443969244&sdata=gvOKFn6Rt7sgbmrbMo Vq2cawyetW5z6H50Qhv0aX0rA%3D&reserved=0Thanks,
-Takahiro AkashiQuoted 11 lines
Quoted 2 lines
--
================================================================
Quoted 4 lines
=====
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de================================================================
Quoted 1 line
=====
RFC 7/15 efi_loader: add signature verification functions
In reply to AKASHI TakahiroIn this commit, implemented are efi_signature_verify_with_db(), efi_signature_parse_sigdb() and a couple of helper functions which will be used for variable authentication as well as image authentication in UEFI secure boot.
efi_signature_verify_with_db() - authenticate an image with its hash value for unsigned image, and with its embedded pkcs7 signature with a given signature store if signed. This function will also be used to validate authentication data in authenticated variables.
efi_signature_parse_sigdb() - parse signature database variable and retrieve signature lists, which may consist of x509 certificates or message digests (SHA256 only for now).
--- include/efi_api.h | 47 +++ include/efi_loader.h | 47 +++ lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_signature.c | 602 +++++++++++++++++++++++++++++++++ 4 files changed, 697 insertions(+) create mode 100644 lib/efi_loader/efi_signature.c
include/efi_api.h +47 -0
@@ -18,6 +18,7 @@#include <efi.h> #include <charset.h> +#include <pe.h> #ifdef CONFIG_EFI_LOADER #include <asm/setjmp.h>
@@ -307,6 +308,10 @@ struct efi_runtime_services {EFI_GUID (0x8be4df61 ,0x93ca ,0x11d2 ,0xaa ,0x0d , \ 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c) +#define EFI_IMAGE_SECURITY_DATABASE_GUID \ + EFI_GUID(0xd719b2cb, 0x3d3a, 0x4596, 0xa3, 0xbc, \ + 0xda, 0xd0, 0x0e, 0x67, 0x65, 0x6f) +#define EFI_FDT_GUID \ EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5, \ 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0)
@@ -1597,4 +1602,46 @@ struct efi_unicode_collation_protocol {#define LOAD_OPTION_CATEGORY_BOOT 0x00000000#define LOAD_OPTION_CATEGORY_APP 0x00000100 +/* Secure boot */ +#define EFI_CERT_SHA256_GUID \ + EFI_GUID(0xc1c41626, 0x504c, 0x4092, 0xac, 0xa9, \ + 0x41, 0xf9, 0x36, 0x93, 0x43, 0x28) +#define EFI_CERT_RSA2048_GUID \ + EFI_GUID(0x3c5766e8, 0x269c, 0x4e34, 0xaa, 0x14, \ + 0xed, 0x77, 0x6e, 0x85, 0xb3, 0xb6) +#define EFI_CERT_X509_GUID \ + EFI_GUID(0xa5c059a1, 0x94e4, 0x4aa7, 0x87, 0xb5, \ + 0xab, 0x15, 0x5c, 0x2b, 0xf0, 0x72) +#define EFI_CERT_X509_SHA256_GUID \ + EFI_GUID(0x3bd2a492, 0x96c0, 0x4079, 0xb4, 0x20, \ + 0xfc, 0xf9, 0x8e, 0xf1, 0x03, 0xed) +#define EFI_CERT_TYPE_PKCS7_GUID \ + EFI_GUID(0x4aafd29d, 0x68df, 0x49ee, 0x8a, 0xa9, \ + 0x34, 0x7d, 0x37, 0x56, 0x65, 0xa7) + +struct win_certificate_uefi_guid { +WIN_CERTIFICATE hdr; +efi_guid_t cert_type; +u8 cert_data[]; +} __attribute__((__packed__ )); + +struct efi_variable_authentication_2 { +struct efi_time time_stamp; +struct win_certificate_uefi_guid auth_info; +} __attribute__((__packed__ )); + +struct efi_signature_data { +efi_guid_t signature_owner; +u8 signature_data[]; +} __attribute__((__packed__ )); + +struct efi_signature_list { +efi_guid_t signature_type; +u32 signature_list_size; +u32 signature_header_size; +u32 signature_size; +/* u8 signature_header[signature_header_size]; */ +/* struct efi_signature_data signatures[...][signature_size]; */ +} __attribute__((__packed__ )); +#endif
include/efi_loader.h +47 -0
65 lines not on this page · raw message
lib/efi_loader/Makefile +1 -0
@@ -39,3 +39,4 @@ obj-$(CONFIG_PARTITIONS) += efi_disk.o obj-$(CONFIG_NET) += efi_net.o obj-$(CONFIG_GENERATE_ACPI_TABLE) += efi_acpi.o obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += efi_smbios.o +obj-y += efi_signature.o
lib/efi_loader/efi_signature.c new file +602 -0
602 lines not on this page · raw message
Signature · 1 line
2.21.0
RFC 8/15 efi_loader: variable: support variable authentication
In reply to AKASHI TakahiroWith this commit, EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS is supported for authenticated variables and the system secure state will transfer between setup mode and user mode as UEFI specification section 32.3 describes.
Internally, authentication data is stored as part of authenticated variable's value. It is nothing but a pkcs7 message (but we need some wrapper, see efi_variable_parse_signature()) and will be validated by efi_variable_authenticate(), hence efi_signature_verify_with_db().
Associated time value will be encoded in "{...,time=...}" along with other UEFI variable's attributes.
--- include/efi_loader.h | 4 + lib/efi_loader/efi_variable.c | 855 ++++++++++++++++++++++++++++++---- 2 files changed, 757 insertions(+), 102 deletions(-)
include/efi_loader.h +4 -0
@@ -162,6 +162,7 @@ extern const efi_guid_t efi_guid_image_security_database;extern const efi_guid_t efi_guid_sha256;extern const efi_guid_t efi_guid_cert_x509;extern const efi_guid_t efi_guid_cert_x509_sha256; +extern const efi_guid_t efi_guid_cert_type_pkcs7;extern unsigned int __efi_runtime_start, __efi_runtime_stop;extern unsigned int __efi_runtime_rel_start, __efi_runtime_rel_stop;
@@ -699,6 +700,9 @@ efi_status_t efi_image_region_add(efi_image_regions *ctx,void efi_sigstore_free (efi_signature_store *ctx);efi_signature_store *efi_sigstore_parse_sigdb (u16 *name); + +bool efi_secure_boot_enabled (void ); +efi_status_t efi_init_secure_boot (void );#endif /* CONFIG_EFI_SECURE_BOOT */ #else /* CONFIG_IS_ENABLED(EFI_LOADER) */
lib/efi_loader/efi_variable.c +753 -102
1,014 lines not on this page · raw message
Signature · 1 line
2.21.0
RFC 9/15 efi_loader: variable: add VendorKeys and SignatureSupport variables
In reply to AKASHI TakahiroThose two variables are well defined UEFI variables:
SignatureSupport: array of GUIDs representing the type of signatures
supported by the platform firmware
VendorKeys: whether the system is configured to use only vendor-provided
keys or not
--- lib/efi_loader/efi_variable.c | 85 ++++++++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 6 deletions(-)
lib/efi_loader/efi_variable.c +79 -6
@@ -28,8 +28,14 @@ enum efi_secure_mode { EFI_MODE_DEPLOYED, }; +static const efi_guid_t signature_types[] = { +/* EFI_CERT_SHA256_GUID, */ +EFI_CERT_X509_GUID , +};const efi_guid_t efi_guid_cert_type_pkcs7 =EFI_CERT_TYPE_PKCS7_GUID ;static bool efi_secure_boot; +static int efi_secure_mode; +static u8 efi_vendor_keys;#define READ_ONLY BIT(31)
@@ -337,6 +343,8 @@ static efi_status_t efi_transfer_secure_state(enum efi_secure_mode mode)return EFI_INVALID_PARAMETER ; } + efi_secure_mode = mode; +return EFI_SUCCESS ; err:
@@ -347,16 +355,57 @@ err:efi_status_t efi_init_secure_boot (void ) { -efi_uintn_t size =0 ; +enum efi_secure_mode mode; +efi_uintn_t size;efi_status_t ret; + ret =efi_set_variable_internal (L"SignatureSupport" , + &efi_global_variable_guid, +EFI_VARIABLE_BOOTSERVICE_ACCESS + |EFI_VARIABLE_RUNTIME_ACCESS + |READ_ONLY , +sizeof (signature_types), + &signature_types, + false); +if (ret !=EFI_SUCCESS ) + goto err; + +/* +* TODO: +* Since there is currently no "platform-specific" installation +* method of Platform Key, we can't say if VendorKeys is 0 or 1 +* precisely. +*/ + + size =0 ; ret =EFI_CALL (efi_get_variable (L"PK" , &efi_global_variable_guid,NULL , &size,NULL )); -if (ret ==EFI_BUFFER_TOO_SMALL &&IS_ENABLED (CONFIG_EFI_SECURE_BOOT )) - ret =efi_transfer_secure_state (EFI_MODE_USER ); -else - ret =efi_transfer_secure_state (EFI_MODE_SETUP ); +if (ret ==EFI_BUFFER_TOO_SMALL ) { +if (IS_ENABLED (CONFIG_EFI_SECURE_BOOT )) + mode =EFI_MODE_USER ; +else + mode =EFI_MODE_SETUP ; + + efi_vendor_keys =0 ; + }else if (ret ==EFI_NOT_FOUND ) { + mode =EFI_MODE_SETUP ; + efi_vendor_keys =1 ; + }else { + goto err; + } + ret =efi_transfer_secure_state (mode); +if (ret ==EFI_SUCCESS ) + ret =efi_set_variable_internal (L"VendorKeys" , + &efi_global_variable_guid, +EFI_VARIABLE_BOOTSERVICE_ACCESS + |EFI_VARIABLE_RUNTIME_ACCESS + |READ_ONLY , +sizeof (efi_vendor_keys), + &efi_vendor_keys, + false); + +err:return ret; }
@@ -1086,6 +1135,8 @@ out:if (env_set (native_name, val)) { ret =EFI_DEVICE_ERROR ; }else { +bool vendor_keys_modified = false; +if ((u16_strcmp (variable_name,L"PK" ) ==0 &&guidcmp (vendor, &efi_global_variable_guid) ==0 )) { ret = efi_transfer_secure_state(
@@ -1093,8 +1144,30 @@ out: EFI_MODE_USER));if (ret !=EFI_SUCCESS ) goto err; + +if (efi_secure_mode !=EFI_MODE_SETUP ) + vendor_keys_modified = true; + }else if ((u16_strcmp (variable_name,L"KEK" ) ==0 && +guidcmp (vendor, &efi_global_variable_guid) ==0 )) { +if (efi_secure_mode !=EFI_MODE_SETUP ) + vendor_keys_modified = true; + } + +/* update VendorKeys */ +if (vendor_keys_modified & efi_vendor_keys) { + efi_vendor_keys =0 ; + ret =efi_set_variable_internal ( +L"VendorKeys" , + &efi_global_variable_guid, +EFI_VARIABLE_BOOTSERVICE_ACCESS + |EFI_VARIABLE_RUNTIME_ACCESS + |READ_ONLY , +sizeof (efi_vendor_keys), + &efi_vendor_keys, + false); + }else { + ret =EFI_SUCCESS ; } - ret =EFI_SUCCESS ; } err:
Signature · 1 line
2.21.0
RFC 10/15 efi_loader: image_loader: support image authentication
In reply to AKASHI TakahiroWith this commit, image validation can be enforced, as UEFI specification section 32.5 describes, if CONFIG_EFI_SECURE_BOOT is enabled.
Currently we support
* authentication based on db and dbx,
so dbx-validated image will always be rejected.
* following signature types:
EFI_CERT_SHA256_GUID (SHA256 digest for unsigned images) EFI_CERT_X509_GUID (x509 certificate for signed images)
Timestamp-based certifcate revocation is not supported here.
Internally, authentication data is stored in one of certificates tables of PE image (See efi_image_parse()) and will be verified by efi_image_authenticate(), hence efi_signature_verify_with_db(), before loading a given image.
--- include/efi_loader.h | 7 +- lib/efi_loader/efi_boottime.c | 2 +- lib/efi_loader/efi_image_loader.c | 364 +++++++++++++++++++++++++++++- 3 files changed, 366 insertions(+), 7 deletions(-)
include/efi_loader.h +6 -1
@@ -11,6 +11,7 @@#include <common.h> #include <part_efi.h> #include <efi_api.h> +#include <pe.h> /* No need for efi loader support in SPL */ #if CONFIG_IS_ENABLED (EFI_LOADER )
@@ -385,7 +386,8 @@ efi_status_t efi_set_watchdog(unsigned long timeout);/* Called from places to check whether a timer expired */ void efi_timer_check (void );/* PE loader implementation */ -efi_status_t efi_load_pe (struct efi_loaded_image_obj *handle,void *efi, +efi_status_t efi_load_pe (struct efi_loaded_image_obj *handle, +void *efi,size_t efi_size,struct efi_loaded_image *loaded_image_info);/* Called once to store the pristine gd pointer */ void efi_save_gd (void );
@@ -703,6 +705,9 @@ efi_signature_store *efi_sigstore_parse_sigdb(u16 *name);bool efi_secure_boot_enabled (void );efi_status_t efi_init_secure_boot (void ); + +bool efi_image_parse (void *efi,size_t len,efi_image_regions **regp, +WIN_CERTIFICATE **auth,size_t *auth_len);#endif /* CONFIG_EFI_SECURE_BOOT */ #else /* CONFIG_IS_ENABLED(EFI_LOADER) */
lib/efi_loader/efi_boottime.c +1 -1
@@ -1879,7 +1879,7 @@ efi_status_t EFIAPI efi_load_image(bool boot_policy,efi_dp_split_file_path (file_path, &dp, &fp); ret =efi_setup_loaded_image (dp, fp, image_obj, &info);if (ret ==EFI_SUCCESS ) - ret =efi_load_pe (*image_obj, dest_buffer, info); + ret =efi_load_pe (*image_obj, dest_buffer, source_size, info);if (!source_buffer)/* Release buffer to which file was loaded */ efi_free_pages((uintptr_t)dest_buffer,
lib/efi_loader/efi_image_loader.c +359 -5
439 lines not on this page · raw message
Signature · 1 line
2.21.0
RFC 11/15 efi_loader: initialize secure boot state
In reply to AKASHI TakahiroWe call efi_init_secure_boot() after loading saved UEFI variables so that the initial secure boot status will be initialized.
--- lib/efi_loader/efi_setup.c | 5 +++++ 1 file changed, 5 insertions(+)
lib/efi_loader/efi_setup.c +5 -0
@@ -132,6 +132,11 @@ efi_status_t efi_init_obj_list(void)if (ret !=EFI_SUCCESS ) goto out; +/* Secure boot */ + ret =efi_init_secure_boot (); +if (ret !=EFI_SUCCESS ) + goto out; +/* Indicate supported runtime services */ ret =efi_init_runtime_supported ();if (ret !=EFI_SUCCESS )
Signature · 1 line
2.21.0
RFC 12/15 efi_loader: add CONFIG_EFI_SECURE_BOOT
In reply to AKASHI TakahiroNow we can enable UEFI secure boot with this option.
--- lib/efi_loader/Kconfig | 13 +++++++++++++ 1 file changed, 13 insertions(+)
lib/efi_loader/Kconfig +13 -0
@@ -115,4 +115,17 @@ config EFI_GRUB_ARM32_WORKAROUND GRUB prior to version 2.04 requires U-Boot to disable caches. This workaround currently is also needed on systems with caches that cannot be managed via CP15. + +config EFI_SECURE_BOOT + bool "Enable EFI secure boot support" + depends on EFI_LOADER + depends on SECURE_BOOT + imply RSA_VERIFY_WITH_PKEY + default n + help + Select this option to enable EFI secure boot support. + Once SecureBoot mode is enforced, any EFI binary can run only if + it is signed with a trusted key. To do that, you need to install, + at least, PK, KEK and db. + endif
Signature · 1 line
2.21.0
RFC 13/15 cmd: env: provide appropriate guid for well-defined variable
In reply to AKASHI TakahiroAny signature database variable is associated with a specific guid. For convenience, if user doesn't supply any guid info, "env set|print -e" should complement it.
--- cmd/nvedit_efi.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-)
cmd/nvedit_efi.c +23 -8
@@ -41,6 +41,11 @@ static const struct { } efi_guid_text[] = { /* signature database */ {EFI_GLOBAL_VARIABLE_GUID, "EFI_GLOBAL_VARIABLE_GUID"}, + {EFI_IMAGE_SECURITY_DATABASE_GUID, "EFI_IMAGE_SECURITY_DATABASE_GUID"}, + /* certificate type */ + {EFI_CERT_SHA256_GUID, "EFI_CERT_SHA256_GUID"}, + {EFI_CERT_X509_GUID, "EFI_CERT_X509_GUID"}, + {EFI_CERT_TYPE_PKCS7_GUID, "EFI_CERT_TYPE_PKCS7_GUID"}, }; /* "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" */
@@ -135,6 +140,7 @@ static int efi_dump_vars(int argc, char * const argv[], bool verbose) {u16 *var_name16, *p;efi_uintn_t buf_size, size; +efi_guid_t *guid; buf_size =128 ; var_name16 =malloc (buf_size);
@@ -156,9 +162,13 @@ static int efi_dump_vars(int argc, char * const argv[], bool verbose) p = var_name16;utf8_utf16_strcpy (&p, argv[0 ]); -efi_dump_single_var (var_name16, - (efi_guid_t *)&efi_global_variable_guid, - verbose); +if (!strcmp (argv[0 ],"db" ) || !strcmp (argv[0 ],"dbx" ) || + !strcmp (argv[0 ],"dbt" )) + guid = (efi_guid_t *)&efi_guid_image_security_database; +else + guid = (efi_guid_t *)&efi_global_variable_guid; + +efi_dump_single_var (var_name16, guid, verbose); }free (var_name16);
@@ -167,7 +177,7 @@ static int efi_dump_vars(int argc, char * const argv[], bool verbose) }/** -* efi_dump_vars() - show information about all the UEFI variables +* efi_dump_var_all() - show information about all the UEFI variables * * @verbose: if true, dump data * Return: CMD_RET_SUCCESS on success, or CMD_RET_RET_FAILURE
@@ -463,9 +473,9 @@ int do_env_set_efi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])if (*ep !=',' )return CMD_RET_USAGE ; +/* 0 should be allowed for delete */ size =simple_strtoul (++ep,NULL ,16 ); -if (!size) -return CMD_RET_FAILURE ; + value_on_memory = true; }else if (!strcmp (argv[0 ],"-v" )) { verbose = true;
@@ -477,8 +487,13 @@ int do_env_set_efi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])return CMD_RET_USAGE ; var_name = argv[0 ]; -if (default_guid) - guid = efi_global_variable_guid; +if (default_guid) { +if (!strcmp (var_name,"db" ) || !strcmp (var_name,"dbx" ) || + !strcmp (var_name,"dbt" )) + guid = efi_guid_image_security_database; +else + guid = efi_global_variable_guid; + }if (verbose) {printf ("GUID: %s\n" ,efi_guid_to_str (&guid));
Signature · 1 line
2.21.0
RFC 14/15 efi_loader, pytest: add UEFI secure boot tests (image)
In reply to AKASHI Takahirotest_efi_secboot/test_signed.py: provide test cases of image authentication
for signed imagestest_efi_secboot/test_unsigned.py: provide test cases of image
authentication for unsigned images
This test relies on efitools and user should compile it on his own. (Currently some local change has been applied.)
--- test/py/tests/test_efi_secboot/conftest.py | 168 ++++++++++++++++++ test/py/tests/test_efi_secboot/defs.py | 7 + test/py/tests/test_efi_secboot/test_signed.py | 97 ++++++++++ .../tests/test_efi_secboot/test_unsigned.py | 126 +++++++++++++ 4 files changed, 398 insertions(+) create mode 100644 test/py/tests/test_efi_secboot/conftest.py create mode 100644 test/py/tests/test_efi_secboot/defs.py create mode 100644 test/py/tests/test_efi_secboot/test_signed.py create mode 100644 test/py/tests/test_efi_secboot/test_unsigned.py
test/py/tests/test_efi_secboot/conftest.py new file +168 -0
@@ -0,0 +1,168 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2019, Linaro Limited +# Author: AKASHI Takahiro <[email protected]> + +import os +import os.path +import pytest +import re +from subprocess import call, check_call, check_output, CalledProcessError +from defs import * + +# +# Helper functions +# +def mk_fs(config, fs_type, size, id): + """Create a file system volume. + + Args: + fs_type: File system type. + size: Size of file system in MiB. + id: Prefix string of volume's file name. + + Return: + Nothing. + """ + fs_img = '%s.%s.img' % (id, fs_type) + fs_img = config.persistent_data_dir + '/' + fs_img + + if fs_type == 'fat16': + mkfs_opt = '-F 16' + elif fs_type == 'fat32': + mkfs_opt = '-F 32' + elif fs_type == 'ext4': + mkfs_opt = '-O ^metadata_csum' + else: + mkfs_opt = '' + + if re.match('fat', fs_type): + fs_lnxtype = 'vfat' + else: + fs_lnxtype = fs_type + + count = (size + 1048576 - 1) / 1048576 + + try: + check_call('rm -f %s' % fs_img, shell=True) + check_call('dd if=/dev/zero of=%s bs=1M count=%d' + % (fs_img, count), shell=True) + check_call('mkfs.%s %s %s' + % (fs_lnxtype, mkfs_opt, fs_img), shell=True) + return fs_img + except CalledProcessError: + call('rm -f %s' % fs_img, shell=True) + raise + +# from test/py/conftest.py +def tool_is_in_path(tool): + """Check whether a given command is available on host. + + Args: + tool: Command name. + + Return: + True if available, False if not. + """ + for path in os.environ['PATH'].split(os.pathsep): + fn = os.path.join(path, tool) + if os.path.isfile(fn) and os.access(fn, os.X_OK): + return True + return False + +fuse_mounted = False + +def mount_fs(fs_type, device, mount_point): + """Mount a volume. + + Args: + fs_type: File system type. + device: Volume's file name. + mount_point: Mount point. + + Return: + Nothing. + """ + global fuse_mounted + + fuse_mounted = False + try: + if tool_is_in_path('guestmount'): + fuse_mounted = True + check_call('guestmount -a %s -m /dev/sda %s' + % (device, mount_point), shell=True) + else: + mount_opt = 'loop,rw' + if re.match('fat', fs_type): + mount_opt += ',umask=0000' + + check_call('sudo mount -o %s %s %s' + % (mount_opt, device, mount_point), shell=True) + + # may not be effective for some file systems + check_call('sudo chmod a+rw %s' % mount_point, shell=True) + except CalledProcessError: + raise + +def umount_fs(mount_point): + """Unmount a volume. + + Args: + mount_point: Mount point. + + Return: + Nothing. + """ + if fuse_mounted: + call('sync') + call('guestunmount %s' % mount_point, shell=True) + else: + call('sudo umount %s' % mount_point, shell=True) + +# +# Fixture for TestEfiSignedImage test +# +# NOTE: yield_fixture was deprecated since pytest-3.0 + at pytest.yield_fixture() +def efi_boot_env(request, u_boot_config): + """Set up a file system to be used in basic fs test. + + Args: + request: Pytest request object. + u_boot_config: U-boot configuration. + + Return: + A fixture for basic fs test, i.e. a triplet of file system type, + volume file name and a list of MD5 hashes. + """ + fs_type = 'fat32' + fs_img = '' + + mount_dir = u_boot_config.persistent_data_dir + '/mnt' + + try: + + # test volume + fs_img = mk_fs(u_boot_config, 'fat32', TEST_VOL_SIZE, 'test') + + # Mount the image so we can populate it. + check_output('mkdir -p %s' % mount_dir, shell=True) + mount_fs(fs_type, fs_img, mount_dir) + + # Copy files + check_output('cp %s/*.efi %s' % (EFITOOLS_PATH, mount_dir), shell=True) + check_output('cp %s/PK* %s' % (EFITOOLS_PATH, mount_dir), shell=True) + check_output('cp %s/noPK* %s' % (EFITOOLS_PATH, mount_dir), shell=True) + check_output('cp %s/KEK* %s' % (EFITOOLS_PATH, mount_dir), shell=True) + check_output('cp %s/DB* %s' % (EFITOOLS_PATH, mount_dir), shell=True) + + umount_fs(mount_dir) + except CalledProcessError as e: + pytest.skip('Setup failed: %s' % e.cmd) + return + else: + yield fs_img + finally: + umount_fs(mount_dir) + call('rmdir %s' % mount_dir, shell=True) + if fs_img: + call('rm -f %s' % fs_img, shell=True)
test/py/tests/test_efi_secboot/defs.py new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0+ + +# 64MiB +TEST_VOL_SIZE=0x4000000 + +# efitools build directory +EFITOOLS_PATH='/home/akashi/x86/efitools'
test/py/tests/test_efi_secboot/test_signed.py new file +97 -0
97 lines not on this page · raw message
test/py/tests/test_efi_secboot/test_unsigned.py new file +126 -0
126 lines not on this page · raw message
Signature · 1 line
2.21.0
RFC 15/15 efi_loader, pytest: add UEFI secure boot tests (authenticated variables)
In reply to AKASHI Takahirotest_efi_secboot/test_authvar.py: provide test cases of variable
authentication
This test relies on efitools and user should compile it on his own. (Currently some local change has been applied.)
--- .../py/tests/test_efi_secboot/test_authvar.py | 287 ++++++++++++++++++ 1 file changed, 287 insertions(+) create mode 100644 test/py/tests/test_efi_secboot/test_authvar.py
test/py/tests/test_efi_secboot/test_authvar.py new file +287 -0
@@ -0,0 +1,287 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2019, Linaro Limited +# Author: AKASHI Takahiro <[email protected]> +# +# U-Boot UEFI: Variable Authentication Test + +""" +This test verifies variable authentication +""" + +import pytest +import re +from defs import * + + at pytest.mark.boardspec('sandbox') + at pytest.mark.buildconfigspec('efi_secure_boot') + at pytest.mark.slow +class TestEfiAuthVar(object): + def test_efi_var_auth1(self, u_boot_console, efi_boot_env): + """ + Test Case 1 - Install signature database + """ + disk_img = efi_boot_env + with u_boot_console.log.section('Test Case 1a'): + # Test Case 1a, Initial secure state + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % disk_img, + 'printenv -e -v SecureBoot']) + assert(re.search('00000000: 00', ''.join(output))) + + output = u_boot_console.run_command( + 'printenv -e -v SecureBoot') + assert('00000000: 00' in output) + output = u_boot_console.run_command( + 'printenv -e -v SetupMode') + assert('00000000: 01' in output) + + with u_boot_console.log.section('Test Case 1b'): + # Test Case 1b, PK without AUTHENTICATED_WRITE_ACCESS + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % disk_img, + 'fatload host 0:0 4000000 PK.auth', + 'setenv -e -nv -bs -rt -i 4000000,$filesize PK']) + assert(re.search('Failed to set EFI variable', ''.join(output))) + + with u_boot_console.log.section('Test Case 1c'): + # Test Case 1c, install PK + output = u_boot_console.run_command_list([ + 'fatload host 0:0 4000000 PK.auth', + 'setenv -e -nv -bs -rt -at -i 4000000,$filesize PK', + 'printenv -e PK']) + assert(re.search('PK:', ''.join(output))) + + output = u_boot_console.run_command( + 'printenv -e -v SecureBoot') + assert('00000000: 01' in output) + output = u_boot_console.run_command( + 'printenv -e -v SetupMode') + assert('00000000: 00' in output) + + with u_boot_console.log.section('Test Case 1d'): + # Test Case 1d, db/dbx without KEK + output = u_boot_console.run_command_list([ + 'fatload host 0:0 4000000 DB.auth', + 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db']) + assert(re.search('Failed to set EFI variable', ''.join(output))) + + output = u_boot_console.run_command_list([ + 'fatload host 0:0 4000000 DB.auth', + 'setenv -e -nv -bs -rt -at -i 4000000,$filesize dbx']) + assert(re.search('Failed to set EFI variable', ''.join(output))) + + with u_boot_console.log.section('Test Case 1e'): + # Test Case 1e, install KEK + output = u_boot_console.run_command_list([ + 'fatload host 0:0 4000000 KEK.auth', + 'setenv -e -nv -bs -rt -i 4000000,$filesize KEK']) + assert(re.search('Failed to set EFI variable', ''.join(output))) + + output = u_boot_console.run_command_list([ + 'fatload host 0:0 4000000 KEK.auth', + 'setenv -e -nv -bs -rt -at -i 4000000,$filesize KEK', + 'printenv -e KEK']) + assert(re.search('KEK:', ''.join(output))) + + output = u_boot_console.run_command( + 'printenv -e -v SecureBoot') + assert('00000000: 01' in output) + + with u_boot_console.log.section('Test Case 1f'): + # Test Case 1f, install db + output = u_boot_console.run_command_list([ + 'fatload host 0:0 4000000 DB.auth', + 'setenv -e -nv -bs -rt -i 4000000,$filesize db']) + assert(re.search('Failed to set EFI variable', ''.join(output))) + + output = u_boot_console.run_command_list([ + 'fatload host 0:0 4000000 DB.auth', + 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db', + 'printenv -e db']) + assert(re.search('db:', ''.join(output))) + + output = u_boot_console.run_command( + 'printenv -e -v SecureBoot') + assert('00000000: 01' in output) + + with u_boot_console.log.section('Test Case 1g'): + # Test Case 1g, install dbx + output = u_boot_console.run_command_list([ + 'fatload host 0:0 4000000 DB1.auth', + 'setenv -e -nv -bs -rt -i 4000000,$filesize dbx']) + assert(re.search('Failed to set EFI variable', ''.join(output))) + + output = u_boot_console.run_command_list([ + 'fatload host 0:0 4000000 DB1.auth', + 'setenv -e -nv -bs -rt -at -i 4000000,$filesize dbx', + 'printenv -e dbx']) + # FIXME: currently failed + assert(not re.search('Failed to set EFI variable', ''.join(output))) + assert(re.search('dbx:', ''.join(output))) + + output = u_boot_console.run_command( + 'printenv -e -v SecureBoot') + assert('00000000: 01' in output) + + def test_efi_var_auth2(self, u_boot_console, efi_boot_env): + """ + Test Case 2 - Update database by overwriting + """ + disk_img = efi_boot_env + with u_boot_console.log.section('Test Case 2a'): + # Test Case 2a, update without AUTHENTICATED_WRITE_ACCESS + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % disk_img, + 'fatload host 0:0 4000000 PK.auth', + 'setenv -e -nv -bs -rt -at -i 4000000,$filesize PK', + 'fatload host 0:0 4000000 KEK.auth', + 'setenv -e -nv -bs -rt -at -i 4000000,$filesize KEK', + 'fatload host 0:0 4000000 DB.auth', + 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db', + 'printenv -e db']) + assert(not re.search('Failed to set EFI variable', ''.join(output))) + assert(re.search('db:', ''.join(output))) + assert(re.search('DataSize = 0x31d', ''.join(output))) + + output = u_boot_console.run_command_list([ + 'fatload host 0:0 4000000 DB1.auth', + 'setenv -e -nv -bs -rt -i 4000000,$filesize db']) + assert(re.search('Failed to set EFI variable', ''.join(output))) + + with u_boot_console.log.section('Test Case 2b'): + # Test Case 2b, update without correct signature + output = u_boot_console.run_command_list([ + 'fatload host 0:0 4000000 DB.esl', + 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db']) + assert(re.search('Failed to set EFI variable', ''.join(output))) + + with u_boot_console.log.section('Test Case 2c'): + # Test Case 2c, update with correct signature + output = u_boot_console.run_command_list([ + 'fatload host 0:0 4000000 DB1.auth', + 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db', + 'printenv -e db']) + assert(not re.search('Failed to set EFI variable', ''.join(output))) + assert(re.search('db:', ''.join(output))) + assert(re.search('DataSize = 0x31f', ''.join(output))) + + def test_efi_var_auth3(self, u_boot_console, efi_boot_env): + """ + Test Case 3 - Append database + """ + disk_img = efi_boot_env + with u_boot_console.log.section('Test Case 3a'): + # Test Case 3a, update without AUTHENTICATED_WRITE_ACCESS + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % disk_img, + 'fatload host 0:0 4000000 PK.auth', + 'setenv -e -nv -bs -rt -at -i 4000000,$filesize PK', + 'fatload host 0:0 4000000 KEK.auth', + 'setenv -e -nv -bs -rt -at -i 4000000,$filesize KEK', + 'fatload host 0:0 4000000 DB.auth', + 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db', + 'printenv -e db']) + assert(not re.search('Failed to set EFI variable', ''.join(output))) + assert(re.search('db:', ''.join(output))) + assert(re.search('DataSize = 0x31d', ''.join(output))) + + output = u_boot_console.run_command_list([ + 'fatload host 0:0 4000000 DB1.auth', + 'setenv -e -nv -bs -rt -a -i 4000000,$filesize db']) + assert(re.search('Failed to set EFI variable', ''.join(output))) + + with u_boot_console.log.section('Test Case 3b'): + # Test Case 3b, update without correct signature + output = u_boot_console.run_command_list([ + 'fatload host 0:0 4000000 DB.esl', + 'setenv -e -nv -bs -rt -at -a -i 4000000,$filesize db']) + assert(re.search('Failed to set EFI variable', ''.join(output))) + + with u_boot_console.log.section('Test Case 3c'): + # Test Case 3c, update with correct signature + output = u_boot_console.run_command_list([ + 'fatload host 0:0 4000000 DB1.auth', + 'setenv -e -nv -bs -rt -at -a -i 4000000,$filesize db', + 'printenv -e db']) + assert(not re.search('Failed to set EFI variable', ''.join(output))) + assert(re.search('db:', ''.join(output))) + assert(re.search('DataSize = 0x63c', ''.join(output))) + + def test_efi_var_auth4(self, u_boot_console, efi_boot_env): + """ + Test Case 4 - Delete database without authentication + """ + disk_img = efi_boot_env + with u_boot_console.log.section('Test Case 4a'): + # Test Case 4a, update without AUTHENTICATED_WRITE_ACCESS + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % disk_img, + 'fatload host 0:0 4000000 PK.auth', + 'setenv -e -nv -bs -rt -at -i 4000000,$filesize PK', + 'fatload host 0:0 4000000 KEK.auth', + 'setenv -e -nv -bs -rt -at -i 4000000,$filesize KEK', + 'fatload host 0:0 4000000 DB.auth', + 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db', + 'printenv -e db']) + assert(not re.search('Failed to set EFI variable', ''.join(output))) + assert(re.search('db:', ''.join(output))) + assert(re.search('DataSize = 0x31d', ''.join(output))) + + output = u_boot_console.run_command_list([ + 'setenv -e -nv -bs -rt db', + 'printenv -e db']) + assert(re.search('Failed to set EFI variable', ''.join(output))) + assert(re.search('db:', ''.join(output))) + assert(re.search('DataSize = 0x31d', ''.join(output))) + + with u_boot_console.log.section('Test Case 4b'): + # Test Case 4b, update without correct signature/data + output = u_boot_console.run_command_list([ + 'setenv -e -nv -bs -rt -at db', + 'printenv -e db']) + assert(re.search('Failed to set EFI variable', ''.join(output))) + assert(re.search('db:', ''.join(output))) + assert(re.search('DataSize = 0x31d', ''.join(output))) + + def test_efi_var_auth5(self, u_boot_console, efi_boot_env): + """ + Test Case 5 - Uninstall(delete) PK + """ + disk_img = efi_boot_env + with u_boot_console.log.section('Test Case 4a'): + # Test Case 5a, Uninstall PK without correct signature + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % disk_img, + 'fatload host 0:0 4000000 PK.auth', + 'setenv -e -nv -bs -rt -at -i 4000000,$filesize PK', + 'fatload host 0:0 4000000 KEK.auth', + 'setenv -e -nv -bs -rt -at -i 4000000,$filesize KEK', + 'fatload host 0:0 4000000 DB.auth', + 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db', + 'printenv -e PK']) + assert(not re.search('Failed to set EFI variable', ''.join(output))) + assert(re.search('PK:', ''.join(output))) +# assert(re.search('DataSize = 0x31d', ''.join(output))) + + output = u_boot_console.run_command_list([ + 'fatload host 0:0 4000000 noPK.esl', + 'setenv -e -nv -bs -rt -at -i 4000000,$filesize PK', + 'printenv -e PK']) + assert(re.search('Failed to set EFI variable', ''.join(output))) + assert(re.search('PK:', ''.join(output))) + + with u_boot_console.log.section('Test Case 5b'): + # Test Case 5b, Uninstall PK with correct signature + output = u_boot_console.run_command_list([ + 'fatload host 0:0 4000000 noPK.auth', + 'setenv -e -nv -bs -rt -at -i 4000000,$filesize PK', + 'printenv -e PK']) + assert(not re.search('Failed to set EFI variable', ''.join(output))) + assert(re.search('\"PK\" not defined', ''.join(output))) + + output = u_boot_console.run_command( + 'printenv -e -v SecureBoot') + assert('00000000: 00' in output) + output = u_boot_console.run_command( + 'printenv -e -v SetupMode') + assert('00000000: 01' in output)
Signature · 1 line
2.21.0