keys: Add EFI_CERT_X509_GUID support for dbx/mokx entries
Subsystems (7)
David Howells
maintainercover keys: Add EFI_CERT_X509_GUID support for dbx/mokx entries
Here's my take on v5 of Eric Snowberg's patches[1]:
This series of patches adds support for EFI_CERT_X509_GUID entries [2]. It has been expanded to not only include dbx entries but also entries in the mokx. Additionally Eric included his patches to preload these certificate [3].
The patches can be found on the following branch:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=keys-cve-2020-26541-branch
Changes:
- I've modified the first patch in the series to fix a configuration problem[4][5], to move the added functions to a more logical place within the file and to add kerneldoc comments.
David
---
Eric Snowberg (4):
certs: Add EFI_CERT_X509_GUID support for dbx entries
certs: Move load_system_certificate_list to a common function
certs: Add ability to preload revocation certs
integrity: Load mokx variables into the blacklist keyring
certs/Kconfig | 8 +++ certs/Makefile | 20 ++++++- certs/blacklist.c | 17 ++++++ certs/common.c | 56 +++++++++++++++++++ certs/common.h | 9 +++ certs/revocation_certificates.S | 21 +++++++ certs/system_keyring.c | 49 +--------------- scripts/Makefile | 1 + security/integrity/platform_certs/load_uefi.c | 20 ++++++- 9 files changed, 150 insertions(+), 51 deletions(-) create mode 100644 certs/common.c create mode 100644 certs/common.h create mode 100644 certs/revocation_certificates.S
David Howells
maintainerPATCH 1/4 certs: Add EFI_CERT_X509_GUID support for dbx entries
From: Eric Snowberg <[email protected]>
This fixes CVE-2020-26541.
The Secure Boot Forbidden Signature Database, dbx, contains a list of now revoked signatures and keys previously approved to boot with UEFI Secure Boot enabled. The dbx is capable of containing any number of EFI_CERT_X509_SHA256_GUID, EFI_CERT_SHA256_GUID, and EFI_CERT_X509_GUID entries.
Currently when EFI_CERT_X509_GUID are contained in the dbx, the entries are skipped.
Add support for EFI_CERT_X509_GUID dbx entries. When a EFI_CERT_X509_GUID is found, it is added as an asymmetrical key to the .blacklist keyring. Anytime the .platform keyring is used, the keys in the .blacklist keyring are referenced, if a matching key is found, the key will be rejected.
[DH: Made the following changes:
- Added to have a config option to enable the facility. This allows a Kconfig solution to make sure that pkcs7_validate_trust() is enabled.
- Moved the functions out from the middle of the blacklist functions.
- Added kerneldoc comments.]
---
certs/Kconfig | 9 ++++ certs/blacklist.c | 43 ++++++++++++++++++++ certs/blacklist.h | 2 + certs/system_keyring.c | 6 +++ include/keys/system_keyring.h | 15 +++++++ .../integrity/platform_certs/keyring_handler.c | 11 +++++ 6 files changed, 86 insertions(+)
certs/Kconfig +9 -0
@@ -83,4 +83,13 @@ config SYSTEM_BLACKLIST_HASH_LIST wrapper to incorporate the list into the kernel. Each <hash> should be a string of hex digits. +config SYSTEM_REVOCATION_LIST + bool "Provide system-wide ring of revocation certificates" + depends on SYSTEM_BLACKLIST_KEYRING + depends on PKCS7_MESSAGE_PARSER=y + help + If set, this allows revocation certificates to be stored in the + blacklist keyring and implements a hook whereby a PKCS#7 message can + be checked to see if it matches such a certificate. + endmenu
certs/blacklist.c +43 -0
49 lines not on this page · raw message
certs/blacklist.h +2 -0
@@ -1,3 +1,5 @@#include <linux/kernel.h> +#include <linux/errno.h> +#include <crypto/pkcs7.h> extern const char __initconst *const blacklist_hashes[];
certs/system_keyring.c +6 -0
@@ -242,6 +242,12 @@ int verify_pkcs7_message_sig(const void *data, size_t len,pr_devel ("PKCS#7 platform keyring is not available\n" ); goto error; } + + ret =is_key_on_revocation_list (pkcs7); +if (ret != -ENOKEY ) { +pr_devel ("PKCS#7 platform key is on revocation list\n" ); + goto error; + } } ret =pkcs7_validate_trust (pkcs7, trusted_keys);if (ret <0 ) {
include/keys/system_keyring.h +15 -0
@@ -31,6 +31,7 @@ extern int restrict_link_by_builtin_and_secondary_trusted(#define restrict_link_by_builtin_and_secondary_trusted restrict_link_by_builtin_trusted#endif +extern struct pkcs7_message *pkcs7;#ifdef CONFIG_SYSTEM_BLACKLIST_KEYRING extern int mark_hash_blacklisted (const char *hash); extern int is_hash_blacklisted(const u8 *hash, size_t hash_len,
@@ -49,6 +50,20 @@ static inline int is_binary_blacklisted(const u8 *hash, size_t hash_len) }#endif +#ifdef CONFIG_SYSTEM_REVOCATION_LIST +extern int add_key_to_revocation_list (const char *data,size_t size); +extern int is_key_on_revocation_list (struct pkcs7_message *pkcs7); +#else +static inline int add_key_to_revocation_list (const char *data,size_t size) +{ +return 0 ; +} +static inline int is_key_on_revocation_list (struct pkcs7_message *pkcs7) +{ +return -ENOKEY ; +} +#endif +#ifdef CONFIG_IMA_BLACKLIST_KEYRING extern struct key *ima_blacklist_keyring;
security/integrity/platform_certs/keyring_handler.c +11 -0
@@ -55,6 +55,15 @@ static __init void uefi_blacklist_binary(const char *source,uefi_blacklist_hash (source, data, len,"bin:" ,4 ); } +/* +* Add an X509 cert to the revocation list. +*/ +static __init void uefi_revocation_list_x509 (const char *source, +const void *data,size_t len) +{ +add_key_to_revocation_list (data, len); +} +/* * Return the appropriate handler for particular signature list types found in * the UEFI db and MokListRT tables.
@@ -76,5 +85,7 @@ __init efi_element_handler_t get_handler_for_dbx(const efi_guid_t *sig_type)return uefi_blacklist_x509_tbs;if (efi_guidcmp (*sig_type, efi_cert_sha256_guid) ==0 )return uefi_blacklist_binary; +if (efi_guidcmp (*sig_type, efi_cert_x509_guid) ==0 ) +return uefi_revocation_list_x509;return 0 ; }
David Howells
maintainerPATCH 2/4 certs: Move load_system_certificate_list to a common function
In reply to David HowellsFrom: Eric Snowberg <[email protected]>
Move functionality within load_system_certificate_list to a common function, so it can be reused in the future.
---
certs/Makefile | 2 +- certs/common.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ certs/common.h | 9 ++++++++ certs/system_keyring.c | 49 +++--------------------------------------- 4 files changed, 69 insertions(+), 47 deletions(-) create mode 100644 certs/common.c create mode 100644 certs/common.h
certs/Makefile +1 -1
@@ -3,7 +3,7 @@ # Makefile for the linux kernel signature checking certificates. # -obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o +obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o common.o obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o ifneq ($(CONFIG_SYSTEM_BLACKLIST_HASH_LIST),"") obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_hashes.o
certs/common.c new file +56 -0
56 lines not on this page · raw message
certs/common.h new file +9 -0
@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef _CERT_COMMON_H +#define _CERT_COMMON_H + +int load_certificate_list (const u8 cert_list[],const unsigned long list_size, +const struct key *keyring); + +#endif
certs/system_keyring.c +3 -46
63 lines not on this page · raw message
David Howells
maintainerPATCH 3/4 certs: Add ability to preload revocation certs
In reply to David HowellsFrom: Eric Snowberg <[email protected]>
Add a new Kconfig option called SYSTEM_REVOCATION_KEYS. If set, this option should be the filename of a PEM-formated file containing X.509 certificates to be included in the default blacklist keyring.
[DH: Changed this to make the new Kconfig option depend on the option to enable the facility.]
---
certs/Kconfig | 8 ++++++++ certs/Makefile | 18 ++++++++++++++++-- certs/blacklist.c | 17 +++++++++++++++++ certs/revocation_certificates.S | 21 +++++++++++++++++++++ scripts/Makefile | 1 + 5 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 certs/revocation_certificates.S
certs/Kconfig +8 -0
@@ -92,4 +92,12 @@ config SYSTEM_REVOCATION_LIST blacklist keyring and implements a hook whereby a PKCS#7 message can be checked to see if it matches such a certificate. +config SYSTEM_REVOCATION_KEYS + string "X.509 certificates to be preloaded into the system blacklist keyring" + depends on SYSTEM_REVOCATION_LIST + help + If set, this option should be the filename of a PEM-formatted file + containing X.509 certificates to be included in the default blacklist + keyring. + endmenu
certs/Makefile +16 -2
@@ -4,7 +4,7 @@ # obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o common.o -obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o +obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o revocation_certificates.o common.o ifneq ($(CONFIG_SYSTEM_BLACKLIST_HASH_LIST),"") obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_hashes.o else
@@ -29,7 +29,7 @@ $(obj)/x509_certificate_list: scripts/extract-cert $(SYSTEM_TRUSTED_KEYS_SRCPREF $(call if_changed,extract_certs,$(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_TRUSTED_KEYS)) endif # CONFIG_SYSTEM_TRUSTED_KEYRING -clean-files := x509_certificate_list .x509.list +clean-files := x509_certificate_list .x509.list x509_revocation_list ifeq ($(CONFIG_MODULE_SIG),y) ###############################################################################
@@ -104,3 +104,17 @@ targets += signing_key.x509 $(obj)/signing_key.x509: scripts/extract-cert $(X509_DEP) FORCE $(call if_changed,extract_certs,$(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY)) endif # CONFIG_MODULE_SIG + +ifeq ($(CONFIG_SYSTEM_BLACKLIST_KEYRING),y) + +$(eval $(call config_filename,SYSTEM_REVOCATION_KEYS)) + +$(obj)/revocation_certificates.o: $(obj)/x509_revocation_list + +quiet_cmd_extract_certs = EXTRACT_CERTS $(patsubst "%",%,$(2)) + cmd_extract_certs = scripts/extract-cert $(2) $@ + +targets += x509_revocation_list +$(obj)/x509_revocation_list: scripts/extract-cert $(SYSTEM_REVOCATION_KEYS_SRCPREFIX)$(SYSTEM_REVOCATION_KEYS_FILENAME) FORCE + $(call if_changed,extract_certs,$(SYSTEM_REVOCATION_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_REVOCATION_KEYS)) +endif
certs/blacklist.c +17 -0
@@ -17,9 +17,13 @@#include <linux/uidgid.h> #include <keys/system_keyring.h> #include "blacklist.h" +#include "common.h" static struct key *blacklist_keyring; +extern __initconst const u8 revocation_certificate_list[]; +extern __initconst const unsigned long revocation_certificate_list_size; +/* * The description must be a type prefix, a colon and then an even number of * hex digits. The hash is kept in the description.
@@ -220,3 +224,16 @@ static int __init blacklist_init(void)* Must be initialised before we try and load the keys into the keyring. */ device_initcall (blacklist_init); + +/* +* Load the compiled-in list of revocation X.509 certificates. +*/ +static __init int load_revocation_certificate_list (void ) +{ +if (revocation_certificate_list_size) +pr_notice ("Loading compiled-in revocation X.509 certificates\n" ); + +return load_certificate_list (revocation_certificate_list, revocation_certificate_list_size, + blacklist_keyring); +} +late_initcall (load_revocation_certificate_list);
certs/revocation_certificates.S new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include <linux/export.h> +#include <linux/init.h> + + __INITRODATA + + .align 8 + .globl revocation_certificate_list +revocation_certificate_list: +__revocation_list_start: + .incbin "certs/x509_revocation_list" +__revocation_list_end: + + .align 8 + .globl revocation_certificate_list_size +revocation_certificate_list_size: +#ifdef CONFIG_64BIT + .quad __revocation_list_end - __revocation_list_start +#else + .long __revocation_list_end - __revocation_list_start +#endif
scripts/Makefile +1 -0
@@ -11,6 +11,7 @@ hostprogs-always-$(CONFIG_ASN1) += asn1_compiler hostprogs-always-$(CONFIG_MODULE_SIG_FORMAT) += sign-file hostprogs-always-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += extract-cert hostprogs-always-$(CONFIG_SYSTEM_EXTRA_CERTIFICATE) += insert-sys-cert + hostprogs-always-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += extract-cert HOSTCFLAGS_sorttable.o = -I$(srctree)/tools/include HOSTCFLAGS_asn1_compiler.o = -I$(srctree)/include
Nathan Chancellor
maintainerRe: [PATCH 3/4] certs: Add ability to preload revocation certs
Quoted 150 lines · David Howells
From: Eric Snowberg <[email protected]>
Add a new
Kconfigoption calledSYSTEM_REVOCATION_KEYS. If set, this option should be the filename of a PEM-formated file containing X.509 certificates to be included in the default blacklist keyring.[DH: Changed this to make the new
Kconfigoption depend on the option to enable the facility.]Signed-off-by Eric Snowberg <[email protected]>Acked-by Jarkko Sakkinen <[email protected]>Signed-off-by David Howells <[email protected]>---
certs/Kconfig | 8 ++++++++ certs/Makefile | 18 ++++++++++++++++-- certs/blacklist.c | 17 +++++++++++++++++ certs/revocation_certificates.S | 21 +++++++++++++++++++++ scripts/Makefile | 1 + 5 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 certs/revocation_certificates.Scerts/Kconfig +8
-0@@ -92,4 +92,12 @@ config SYSTEM_REVOCATION_LIST blacklist keyring and implements a hook whereby a PKCS#7 message can be checked to see if it matches such a certificate. +config SYSTEM_REVOCATION_KEYS + string "X.509 certificates to be preloaded into the system blacklist keyring" + depends on SYSTEM_REVOCATION_LIST + help + If set, this option should be the filename of a PEM-formatted file + containing X.509 certificates to be included in the default blacklist + keyring. + endmenucerts/Makefile +16
-2@@ -4,7 +4,7 @@ # obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o common.o -obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o +obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o revocation_certificates.o common.o ifneq ($(CONFIG_SYSTEM_BLACKLIST_HASH_LIST),"") obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_hashes.o else@@ -29,7 +29,7 @@ $(obj)/x509_certificate_list: scripts/extract-cert $(SYSTEM_TRUSTED_KEYS_SRCPREF $(call if_changed,extract_certs,$(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_TRUSTED_KEYS)) endif # CONFIG_SYSTEM_TRUSTED_KEYRING -clean-files := x509_certificate_list .x509.list +clean-files := x509_certificate_list .x509.list x509_revocation_list ifeq ($(CONFIG_MODULE_SIG),y) ###############################################################################@@ -104,3 +104,17 @@ targets += signing_key.x509 $(obj)/signing_key.x509: scripts/extract-cert $(X509_DEP) FORCE $(call if_changed,extract_certs,$(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY)) endif # CONFIG_MODULE_SIG + +ifeq ($(CONFIG_SYSTEM_BLACKLIST_KEYRING),y) + +$(eval $(call config_filename,SYSTEM_REVOCATION_KEYS)) + +$(obj)/revocation_certificates.o: $(obj)/x509_revocation_list + +quiet_cmd_extract_certs = EXTRACT_CERTS $(patsubst "%",%,$(2)) + cmd_extract_certs = scripts/extract-cert $(2) $@ + +targets += x509_revocation_list +$(obj)/x509_revocation_list: scripts/extract-cert $(SYSTEM_REVOCATION_KEYS_SRCPREFIX)$(SYSTEM_REVOCATION_KEYS_FILENAME) FORCE + $(call if_changed,extract_certs,$(SYSTEM_REVOCATION_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_REVOCATION_KEYS)) +endifcerts/blacklist.c +17
-0@@ -17,9 +17,13 @@#include <linux/uidgid.h> #include <keys/system_keyring.h> #include "blacklist.h" +#include "common.h" static struct key *blacklist_keyring; +extern __initconst const u8 revocation_certificate_list[]; +extern __initconst const unsigned long revocation_certificate_list_size; +/* * The description must be a type prefix, a colon and then an even number of * hex digits. The hash is kept in the description. @@ -220,3 +224,16 @@ static int __init blacklist_init(void)* Must be initialised before we try and load the keys into the keyring. */ device_initcall (blacklist_init); + +/* +* Load the compiled-in list of revocation X.509 certificates. +*/ +static __init int load_revocation_certificate_list (void ) +{ +if (revocation_certificate_list_size) +pr_notice ("Loading compiled-in revocation X.509 certificates\n" ); + +return load_certificate_list (revocation_certificate_list, revocation_certificate_list_size, + blacklist_keyring); +} +late_initcall (load_revocation_certificate_list);certs/revocation_certificates.S new file +21
-0@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include <linux/export.h> +#include <linux/init.h> + + __INITRODATA + + .align 8 + .globl revocation_certificate_list +revocation_certificate_list: +__revocation_list_start: + .incbin "certs/x509_revocation_list" +__revocation_list_end: + + .align 8 + .globl revocation_certificate_list_size +revocation_certificate_list_size: +#ifdef CONFIG_64BIT + .quad __revocation_list_end - __revocation_list_start +#else + .long __revocation_list_end - __revocation_list_start +#endifscripts/Makefile +0
-0
scripts/Makefile hostprogs-always-$(CONFIG_ASN1) += asn1_compiler · line 17
Quoted 7 lines
scripts/Makefile +1
-0@@ -11,6 +11,7 @@ hostprogs-always-$(CONFIG_ASN1) += asn1_compiler hostprogs-always-$(CONFIG_MODULE_SIG_FORMAT) += sign-file hostprogs-always-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += extract-cert hostprogs-always-$(CONFIG_SYSTEM_EXTRA_CERTIFICATE) += insert-sys-cert + hostprogs-always-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += extract-cert HOSTCFLAGS_sorttable.o = -I$(srctree)/tools/include HOSTCFLAGS_asn1_compiler.o = -I$(srctree)/include
This patch is broken when CONFIG_SYSTEM_BLACKLIST_KEYRING is set but CONFIG_SYSTEM_REVOCATION_LIST is unset, meaning that CONFIG_SYSTEM_REVOCATION_KEYS is not defined at all. This is very easy to reproduce with x86_64_defconfig.
$ make -skj"$(nproc)" O=build/x86_64 defconfig
$ scripts/config --file build/x86_64/.config -e SYSTEM_BLACKLIST_KEYRING
$ make -skj"$(nproc)" O=build/x86_64 olddefconfig certs/ At main.c:154: - SSL error:0909006C:PEM routines:get_name:no start line: crypto/pem/pem_lib.c:745 extract-cert: /home/nathan/cbl/src/linux-next/: Is a directory make[3]: *** [/home/nathan/cbl/src/linux-next/certs/Makefile:119: certs/x509_revocation_list] Error 1 ...
This happens with every single distribution configuration that I test.
Cheers,
Nathan
David Howells
maintainerPATCH 4/4 integrity: Load mokx variables into the blacklist keyring
In reply to David HowellsFrom: Eric Snowberg <[email protected]>
During boot the Secure Boot Forbidden Signature Database, dbx, is loaded into the blacklist keyring. Systems booted with shim have an equivalent Forbidden Signature Database called mokx. Currently mokx is only used by shim and grub, the contents are ignored by the kernel.
Add the ability to load mokx into the blacklist keyring during boot.
---
security/integrity/platform_certs/load_uefi.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
security/integrity/platform_certs/load_uefi.c +18 -2
@@ -132,8 +132,9 @@ static int __init load_moklist_certs(void)static int __init load_uefi_certs (void ) {efi_guid_t secure_var =EFI_IMAGE_SECURITY_DATABASE_GUID ; -void *db =NULL , *dbx =NULL ; -unsigned long dbsize =0 , dbxsize =0 ; +efi_guid_t mok_var =EFI_SHIM_LOCK_GUID ; +void *db =NULL , *dbx =NULL , *mokx =NULL ; +unsigned long dbsize =0 , dbxsize =0 , mokxsize =0 ;efi_status_t status;int rc =0 ;
@@ -175,6 +176,21 @@ static int __init load_uefi_certs(void)kfree (dbx); } + mokx =get_cert_list (L"MokListXRT" , &mok_var, &mokxsize, &status); +if (!mokx) { +if (status ==EFI_NOT_FOUND ) +pr_debug ("mokx variable wasn't found\n" ); +else +pr_info ("Couldn't get mokx list\n" ); + }else { + rc =parse_efi_signature_list ("UEFI:MokListXRT" , + mokx, mokxsize, + get_handler_for_dbx); +if (rc) +pr_err ("Couldn't parse mokx signatures %d\n" , rc); +kfree (mokx); + } +/* Load the MokListRT certs */ rc =load_moklist_certs ();
Re: [PATCH 4/4] integrity: Load mokx variables into the blacklist keyring
Quoted 46 lines · David Howells
From: Eric Snowberg <[email protected]>
During boot the Secure Boot Forbidden Signature Database, dbx, is loaded into the blacklist keyring. Systems booted with shim have an equivalent Forbidden Signature Database called mokx. Currently mokx is only used by shim and grub, the contents are ignored by the kernel.
Add the ability to load mokx into the blacklist keyring during boot.
Signed-off-by Eric Snowberg <[email protected]>Suggested-by James Bottomley <[email protected]>Signed-off-by David Howells <[email protected]>cc Jarkko Sakkinen <[email protected]>---
security/integrity/platform_certs/load_uefi.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)security/integrity/platform_certs/load_uefi.c +8
-2@@ -132,8 +132,9 @@ static int __init load_moklist_certs(void)static int __init load_uefi_certs (void ) {efi_guid_t secure_var =EFI_IMAGE_SECURITY_DATABASE_GUID ; -void *db =NULL , *dbx =NULL ; -unsigned long dbsize =0 , dbxsize =0 ; +efi_guid_t mok_var =EFI_SHIM_LOCK_GUID ; +void *db =NULL , *dbx =NULL , *mokx =NULL ; +unsigned long dbsize =0 , dbxsize =0 , mokxsize =0 ;efi_status_t status;int rc =0 ;@@ -175,6 +176,21 @@ static int __init load_uefi_certs(void)kfree (dbx); } + mokx =get_cert_list (L"MokListXRT" , &mok_var, &mokxsize, &status); +if (!mokx) { +if (status ==EFI_NOT_FOUND ) +pr_debug ("mokx variable wasn't found\n" ); +else
security/integrity/platform_certs/load_uefi.c static int __init load_uefi_certs(void) · line 193
Quoted 10 lines
security/integrity/platform_certs/load_uefi.c +10
-0+pr_info ("Couldn't get mokx list\n" ); + }else { + rc =parse_efi_signature_list ("UEFI:MokListXRT" , + mokx, mokxsize, + get_handler_for_dbx); +if (rc) +pr_err ("Couldn't parse mokx signatures %d\n" , rc); +kfree (mokx); + } +
My preference would be if the above hunk was moved into the load_moklist_certs() function which is called just below. Such that loading of MokListRT & MOkListXRT are done next to each other.
And also implement loading the same way it is done for MokListRT - specifically via the EFI MOKvar config table & then via a variable.
See 726bd8965a5f112d9601f7ce68effa1e46e02bf2 otherwise large MokListXRT will fail to parse.
Quoted 6 lines
security/integrity/platform_certs/load_uefi.c +0
-0/* Load the MokListRT certs */ rc =load_moklist_certs ();
Eric Snowberg
reviewerRe: [PATCH 4/4] integrity: Load mokx variables into the blacklist keyring
Quoted 66 lines · Dimitri John Ledkov
Quoted 46 lines · David Howells
From: Eric Snowberg <[email protected]>
During boot the Secure Boot Forbidden Signature Database, dbx, is loaded into the blacklist keyring. Systems booted with shim have an equivalent Forbidden Signature Database called mokx. Currently mokx is only used by shim and grub, the contents are ignored by the kernel.
Add the ability to load mokx into the blacklist keyring during boot.
Signed-off-by Eric Snowberg <[email protected]>Suggested-by James Bottomley <[email protected]>Signed-off-by David Howells <[email protected]>cc Jarkko Sakkinen <[email protected]>---
security/integrity/platform_certs/load_uefi.c| 20 ++++++++++++++++++--1 file changed, 18 insertions(+), 2 deletions(-)security/integrity/platform_certs/load_uefi.c +8
-2@@ -132,8 +132,9 @@ static int __init load_moklist_certs(void)static int __init load_uefi_certs (void ) {efi_guid_t secure_var =EFI_IMAGE_SECURITY_DATABASE_GUID ; -void *db =NULL , *dbx =NULL ; -unsigned long dbsize =0 , dbxsize =0 ; +efi_guid_t mok_var =EFI_SHIM_LOCK_GUID ; +void *db =NULL , *dbx =NULL , *mokx =NULL ; +unsigned long dbsize =0 , dbxsize =0 , mokxsize =0 ;efi_status_t status;int rc =0 ;@@ -175,6 +176,21 @@ static int __init load_uefi_certs(void)kfree (dbx); } + mokx =get_cert_list (L"MokListXRT" , &mok_var, &mokxsize, &status); +if (!mokx) { +if (status ==EFI_NOT_FOUND ) +pr_debug ("mokx variable wasn't found\n" ); +else security/integrity/platform_certs/load_uefi.c static int __init load_uefi_certs(void) · line 193
Quoted 10 lines
security/integrity/platform_certs/load_uefi.c +10
-0+pr_info ("Couldn't get mokx list\n" ); + }else { + rc =parse_efi_signature_list ("UEFI:MokListXRT" , + mokx, mokxsize, + get_handler_for_dbx); +if (rc) +pr_err ("Couldn't parse mokx signatures %d\n" , rc); +kfree (mokx); + } +My preference would be if the above hunk was moved into the
load_moklist_certs()function which is called just below. Such that loading of MokListRT & MOkListXRT are done next to each other.
Quoted 5 lines
And also implement loading the same way it is done for MokListRT - specifically via the EFI MOKvar config table & then via a variable.
See
726bd8965a5f112d9601f7ce68effa1e46e02bf2otherwise large MokListXRT will fail to parse.
Is this support available from shim now? Previously I thought only MOK could be loaded from the config table, not MOKx.
Re: [PATCH 4/4] integrity: Load mokx variables into the blacklist keyring
Quoted 66 lines · Eric Snowberg
Quoted 66 lines · Dimitri John Ledkov
Quoted 46 lines · David Howells
From: Eric Snowberg <[email protected]>
During boot the Secure Boot Forbidden Signature Database, dbx, is loaded into the blacklist keyring. Systems booted with shim have an equivalent Forbidden Signature Database called mokx. Currently mokx is only used by shim and grub, the contents are ignored by the kernel.
Add the ability to load mokx into the blacklist keyring during boot.
Signed-off-by Eric Snowberg <[email protected]>Suggested-by James Bottomley <[email protected]>Signed-off-by David Howells <[email protected]>cc Jarkko Sakkinen <[email protected]>---
security/integrity/platform_certs/load_uefi.c| 20 ++++++++++++++++++--1 file changed, 18 insertions(+), 2 deletions(-)security/integrity/platform_certs/load_uefi.c +8
-2@@ -132,8 +132,9 @@ static int __init load_moklist_certs(void)static int __init load_uefi_certs (void ) {efi_guid_t secure_var =EFI_IMAGE_SECURITY_DATABASE_GUID ; -void *db =NULL , *dbx =NULL ; -unsigned long dbsize =0 , dbxsize =0 ; +efi_guid_t mok_var =EFI_SHIM_LOCK_GUID ; +void *db =NULL , *dbx =NULL , *mokx =NULL ; +unsigned long dbsize =0 , dbxsize =0 , mokxsize =0 ;efi_status_t status;int rc =0 ;@@ -175,6 +176,21 @@ static int __init load_uefi_certs(void)kfree (dbx); } + mokx =get_cert_list (L"MokListXRT" , &mok_var, &mokxsize, &status); +if (!mokx) { +if (status ==EFI_NOT_FOUND ) +pr_debug ("mokx variable wasn't found\n" ); +else security/integrity/platform_certs/load_uefi.c static int __init load_uefi_certs(void) · line 193
Quoted 10 lines
security/integrity/platform_certs/load_uefi.c +10
-0+pr_info ("Couldn't get mokx list\n" ); + }else { + rc =parse_efi_signature_list ("UEFI:MokListXRT" , + mokx, mokxsize, + get_handler_for_dbx); +if (rc) +pr_err ("Couldn't parse mokx signatures %d\n" , rc); +kfree (mokx); + } +My preference would be if the above hunk was moved into the
load_moklist_certs()function which is called just below. Such that loading of MokListRT & MOkListXRT are done next to each other.
Quoted 9 lines
Quoted 5 lines
And also implement loading the same way it is done for MokListRT - specifically via the EFI MOKvar config table & then via a variable.
See
726bd8965a5f112d9601f7ce68effa1e46e02bf2otherwise large MokListXRT will fail to parse.Is this support available from shim now? Previously I thought only MOK could be loaded from the config table, not MOKx.
It is about to become available across all distributions with the next shim as everyone is about to ship SBAT capable shims.
From my system with the next shim & 5.10 kernel I have:
$ ls /sys/firmware/efi/mok-variables/ MokIgnoreDB MokListRT MokListXRT MokSBStateRT SbatRT
It's not just a single Mok variable, but _all_ mok variables are available from the mok-table that are used to determine mok state. Including whether or not db should be ignored, whether or not signature verification is turned off, and what are the SBAT generation revocations are, in addition to MokListRT & MokListXRT.
For example, kernel could gain further functionality to honor the user choices and disable loading db controlled by MokIgnoreDB especially since shim chooses to not consider db certificates & hashes as trust-worthy.
Regards,
Dimitri.
Eric Snowberg
reviewerRe: [PATCH 4/4] integrity: Load mokx variables into the blacklist keyring
Quoted 76 lines · Dimitri John Ledkov
Quoted 72 lines · Eric Snowberg
Quoted 71 lines · Dimitri John Ledkov
Quoted 46 lines · David Howells
From: Eric Snowberg <[email protected]>
During boot the Secure Boot Forbidden Signature Database, dbx, is loaded into the blacklist keyring. Systems booted with shim have an equivalent Forbidden Signature Database called mokx. Currently mokx is only used by shim and grub, the contents are ignored by the kernel.
Add the ability to load mokx into the blacklist keyring during boot.
Signed-off-by Eric Snowberg <[email protected]>Suggested-by James Bottomley <[email protected]>Signed-off-by David Howells <[email protected]>cc Jarkko Sakkinen <[email protected]>---
security/integrity/platform_certs/load_uefi.c| 20 ++++++++++++++++++--1 file changed, 18 insertions(+), 2 deletions(-)security/integrity/platform_certs/load_uefi.c +8
-2@@ -132,8 +132,9 @@ static int __init load_moklist_certs(void)static int __init load_uefi_certs (void ) {efi_guid_t secure_var =EFI_IMAGE_SECURITY_DATABASE_GUID ; -void *db =NULL , *dbx =NULL ; -unsigned long dbsize =0 , dbxsize =0 ; +efi_guid_t mok_var =EFI_SHIM_LOCK_GUID ; +void *db =NULL , *dbx =NULL , *mokx =NULL ; +unsigned long dbsize =0 , dbxsize =0 , mokxsize =0 ;efi_status_t status;int rc =0 ;@@ -175,6 +176,21 @@ static int __init load_uefi_certs(void)kfree (dbx); } + mokx =get_cert_list (L"MokListXRT" , &mok_var, &mokxsize, &status); +if (!mokx) { +if (status ==EFI_NOT_FOUND ) +pr_debug ("mokx variable wasn't found\n" ); +else security/integrity/platform_certs/load_uefi.c static int __init load_uefi_certs(void) · line 193
Quoted 10 lines
security/integrity/platform_certs/load_uefi.c +10
-0+pr_info ("Couldn't get mokx list\n" ); + }else { + rc =parse_efi_signature_list ("UEFI:MokListXRT" , + mokx, mokxsize, + get_handler_for_dbx); +if (rc) +pr_err ("Couldn't parse mokx signatures %d\n" , rc); +kfree (mokx); + } +My preference would be if the above hunk was moved into the
load_moklist_certs()function which is called just below. Such that loading of MokListRT & MOkListXRT are done next to each other.And also implement loading the same way it is done for MokListRT - specifically via the EFI MOKvar config table & then via a variable.
See
726bd8965a5f112d9601f7ce68effa1e46e02bf2otherwise large MokListXRT will fail to parse.
Quoted 6 lines
Quoted 3 lines
Is this support available from shim now? Previously I thought only MOK could be loaded from the config table, not MOKx.
It is about to become available across all distributions with the next shim as everyone is about to ship SBAT capable shims.
When I tested this change, I thought it was around 25+ certs and hundreds of hashes before shim started having problems. Someone needing the config list must really have a large list. It would be nice of the MOKx in shim would support a TBS certificate hash, it would really save space.
If MOKx will be available thru a config table in the next shim, I’ll prepare a follow on patch to add this support.
Quoted 11 lines
From my system with the next shim & 5.10 kernel I have:
$ ls /sys/firmware/efi/mok-variables/ MokIgnoreDB MokListRT MokListXRT MokSBStateRT SbatRTIt's not just a single Mok variable, but _all_ mok variables are available from the mok-table that are used to determine mok state. Including whether or not db should be ignored, whether or not signature verification is turned off, and what are the SBAT generation revocations are, in addition to MokListRT & MokListXRT.
Quoted 3 lines
For example, kernel could gain further functionality to honor the user choices and disable loading db controlled by MokIgnoreDB especially since shim chooses to not consider db certificates & hashes as trust-worthy.
Isn’t this already handled by uefi_check_ignore_db()?
David Howells
maintainerRe: [PATCH 4/4] integrity: Load mokx variables into the blacklist keyring
Quoted 2 lines · Eric Snowberg
If MOKx will be available thru a config table in the next shim, I'll prepare a follow on patch to add this support.
Can this go separately, or would it be better rolled into the existing patchset?
David
Eric Snowberg
reviewerRe: [PATCH 4/4] integrity: Load mokx variables into the blacklist keyring
Quoted 10 lines · David Howells
Quoted 2 lines · Eric Snowberg
If MOKx will be available thru a config table in the next shim, I'll prepare a follow on patch to add this support.
Can this go separately, or would it be better rolled into the existing patchset?
IMHO, since you have already sent a pull request and this is not available yet in shim, it seems save to have it go separately. I should have time to send something out next week to address this change.
David Howells
maintainerRe: [PATCH 4/4] integrity: Load mokx variables into the blacklist keyring
Quoted 6 lines · Eric Snowberg
Quoted 2 lines
Can this go separately, or would it be better rolled into the existing patchset?
IMHO, since you have already sent a pull request and this is not available yet in shim, it seems save to have it go separately. I should have time to send something out next week to address this change.
Ok, thanks.
David
Re: [PATCH 4/4] integrity: Load mokx variables into the blacklist keyring
In reply to Eric SnowbergQuoted 9 lines · Eric Snowberg
Quoted 9 lines · David Howells
Quoted 2 lines · Eric Snowberg
If MOKx will be available thru a config table in the next shim, I'll prepare a follow on patch to add this support.
Quoted 7 lines
Quoted 2 lines
Can this go separately, or would it be better rolled into the existing patchset?
IMHO, since you have already sent a pull request and this is not available yet in shim, it seems save to have it go separately. I should have time to send something out next week to address this change.
I don't think that was correct to call it "not available yet in shim". Shim has always exported all the variables, it's just at the time most shims from most distros did not have any contents in MokX. And as usual with all EFI variables, empty ones do not exist.
The shim from Ubuntu which is now public contains 1 cert & 378 on x86_64 and 1 cert & 170 hashes. Thus it is likely to fail to be read by kernel correctly unless it uses efi_mokvar_entry_find(). These patches are tagged with CVE number which it does not address completely in some configurations. Are you working on a patch to add efi_mokvar_entry_find() or do you want me to write it / test it / submit it for review?
Signature · 3 lines
Regards, Dimitri.
Eric Snowberg
reviewerQuoted 10 lines · David Howells
Here's my take on v5 of Eric Snowberg's patches[1]:
This series of patches adds support for
EFI_CERT_X509_GUIDentries [2]. It has been expanded to not only include dbx entries but also entries in the mokx. Additionally Eric included his patches to preload these certificate [3].
Quoted 8 lines
The patches can be found on the following branch:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=keys-cve-2020-26541-branchChanges:
- I've modified the first patch in the series to fix a configuration problem[4][5], to move the added functions to a more logical place within the file and to add kerneldoc comments.
Thanks for making these changes. I reviewed and tested the series again. The only thing I found is we may want to fold in this patch [1] too. Other than that, everything LGTM.
[1] https://patchwork.kernel.org/project/keyrings/patch/[email protected]/
Quoted 31 lines
David
---
Eric Snowberg (4):
certs: AddEFI_CERT_X509_GUIDsupport for dbx entries
certs: Moveload_system_certificate_listto a common function
certs: Add ability to preload revocation certs
integrity: Load mokx variables into the blacklist keyringcerts/Kconfig | 8 +++ certs/Makefile | 20 ++++++- certs/blacklist.c | 17 ++++++ certs/common.c | 56 +++++++++++++++++++ certs/common.h | 9 +++ certs/revocation_certificates.S | 21 +++++++ certs/system_keyring.c | 49 +--------------- scripts/Makefile | 1 + security/integrity/platform_certs/load_uefi.c | 20 ++++++- 9 files changed, 150 insertions(+), 51 deletions(-)create mode 100644
certs/common.c
create mode 100644certs/common.h
create mode 100644certs/revocation_certificates.S