integrity: add new keyring handler for mok keys
authorEric Snowberg <eric.snowberg@oracle.com>
Wed, 26 Jan 2022 02:58:29 +0000 (21:58 -0500)
committerJarkko Sakkinen <jarkko@kernel.org>
Tue, 8 Mar 2022 11:55:52 +0000 (13:55 +0200)
Currently both Secure Boot DB and Machine Owner Keys (MOK) go through
the same keyring handler (get_handler_for_db). With the addition of the
new machine keyring, the end-user may choose to trust MOK keys.

Introduce a new keyring handler specific for MOK keys.  If MOK keys are
trusted by the end-user, use the new keyring handler instead.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Tested-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
security/integrity/platform_certs/keyring_handler.c
security/integrity/platform_certs/keyring_handler.h
security/integrity/platform_certs/load_uefi.c

index e9791be98fd9602285637ab0b953e1da3643448f..4872850d081fe4d635a87cea579ed7df8afbfe0c 100644 (file)
@@ -67,7 +67,7 @@ static __init void uefi_revocation_list_x509(const char *source,
 
 /*
  * Return the appropriate handler for particular signature list types found in
- * the UEFI db and MokListRT tables.
+ * the UEFI db tables.
  */
 __init efi_element_handler_t get_handler_for_db(const efi_guid_t *sig_type)
 {
@@ -76,6 +76,21 @@ __init efi_element_handler_t get_handler_for_db(const efi_guid_t *sig_type)
        return 0;
 }
 
+/*
+ * Return the appropriate handler for particular signature list types found in
+ * the MokListRT tables.
+ */
+__init efi_element_handler_t get_handler_for_mok(const efi_guid_t *sig_type)
+{
+       if (efi_guidcmp(*sig_type, efi_cert_x509_guid) == 0) {
+               if (IS_ENABLED(CONFIG_INTEGRITY_MACHINE_KEYRING))
+                       return add_to_machine_keyring;
+               else
+                       return add_to_platform_keyring;
+       }
+       return 0;
+}
+
 /*
  * Return the appropriate handler for particular signature list types found in
  * the UEFI dbx and MokListXRT tables.
index 2462bfa08fe3418cf81b9722908987943067d465..284558f30411eb25004500bc96a49f8a51b3bb5a 100644 (file)
@@ -24,6 +24,11 @@ void blacklist_binary(const char *source, const void *data, size_t len);
  */
 efi_element_handler_t get_handler_for_db(const efi_guid_t *sig_type);
 
+/*
+ * Return the handler for particular signature list types found in the mok.
+ */
+efi_element_handler_t get_handler_for_mok(const efi_guid_t *sig_type);
+
 /*
  * Return the handler for particular signature list types found in the dbx.
  */
index 08b6d12f99b4fd7abcff197dada5c448569a0f1c..5f45c3c07dbd481ed087f878a1f286652e6fd235 100644 (file)
@@ -95,7 +95,7 @@ static int __init load_moklist_certs(void)
                rc = parse_efi_signature_list("UEFI:MokListRT (MOKvar table)",
                                              mokvar_entry->data,
                                              mokvar_entry->data_size,
-                                             get_handler_for_db);
+                                             get_handler_for_mok);
                /* All done if that worked. */
                if (!rc)
                        return rc;
@@ -110,7 +110,7 @@ static int __init load_moklist_certs(void)
        mok = get_cert_list(L"MokListRT", &mok_var, &moksize, &status);
        if (mok) {
                rc = parse_efi_signature_list("UEFI:MokListRT",
-                                             mok, moksize, get_handler_for_db);
+                                             mok, moksize, get_handler_for_mok);
                kfree(mok);
                if (rc)
                        pr_err("Couldn't parse MokListRT signatures: %d\n", rc);