]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
integrity: PowerVM support for loading third party code signing keys
authorNayna Jain <nayna@linux.ibm.com>
Tue, 15 Aug 2023 11:27:22 +0000 (07:27 -0400)
committerJarkko Sakkinen <jarkko@kernel.org>
Thu, 17 Aug 2023 20:12:35 +0000 (20:12 +0000)
On secure boot enabled PowerVM LPAR, third party code signing keys are
needed during early boot to verify signed third party modules. These
third party keys are stored in moduledb object in the Platform
KeyStore (PKS).

Load third party code signing keys onto .secondary_trusted_keys keyring.

Signed-off-by: Nayna Jain <nayna@linux.ibm.com>
Reviewed-and-tested-by: Mimi Zohar <zohar@linux.ibm.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Tested-by: Nageswara R Sastry <rnsastry@linux.ibm.com>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
certs/system_keyring.c
include/keys/system_keyring.h
security/integrity/platform_certs/keyring_handler.c
security/integrity/platform_certs/keyring_handler.h
security/integrity/platform_certs/load_powerpc.c

index b348e0898d34a251ddff092b07b15a5b8f0e0795..33841c91f12cc88d12080b39636d539e57b1014f 100644 (file)
@@ -152,6 +152,36 @@ static __init struct key_restriction *get_builtin_and_secondary_restriction(void
 
        return restriction;
 }
+
+/**
+ * add_to_secondary_keyring - Add to secondary keyring.
+ * @source: Source of key
+ * @data: The blob holding the key
+ * @len: The length of the data blob
+ *
+ * Add a key to the secondary keyring. The key must be vouched for by a key in the builtin,
+ * machine or secondary keyring itself.
+ */
+void __init add_to_secondary_keyring(const char *source, const void *data, size_t len)
+{
+       key_ref_t key;
+       key_perm_t perm;
+
+       perm = (KEY_POS_ALL & ~KEY_POS_SETATTR) | KEY_USR_VIEW;
+
+       key = key_create_or_update(make_key_ref(secondary_trusted_keys, 1),
+                                  "asymmetric",
+                                  NULL, data, len, perm,
+                                  KEY_ALLOC_NOT_IN_QUOTA);
+       if (IS_ERR(key)) {
+               pr_err("Problem loading X.509 certificate from %s to secondary keyring %ld\n",
+                      source, PTR_ERR(key));
+               return;
+       }
+
+       pr_notice("Loaded X.509 cert '%s'\n", key_ref_to_ptr(key)->description);
+       key_ref_put(key);
+}
 #endif
 #ifdef CONFIG_INTEGRITY_MACHINE_KEYRING
 void __init set_machine_trusted_keys(struct key *keyring)
index 7e2583208820118aba2bf4f08a749bde98b5ccd6..8365adf842ef7a8dbd67ebd8a0d82e5249f25e35 100644 (file)
@@ -50,9 +50,13 @@ int restrict_link_by_digsig_builtin_and_secondary(struct key *keyring,
                                                  const struct key_type *type,
                                                  const union key_payload *payload,
                                                  struct key *restriction_key);
+void __init add_to_secondary_keyring(const char *source, const void *data, size_t len);
 #else
 #define restrict_link_by_builtin_and_secondary_trusted restrict_link_by_builtin_trusted
 #define restrict_link_by_digsig_builtin_and_secondary restrict_link_by_digsig_builtin
+static inline void __init add_to_secondary_keyring(const char *source, const void *data, size_t len)
+{
+}
 #endif
 
 #ifdef CONFIG_INTEGRITY_MACHINE_KEYRING
index 586027b9a3f57005521e3ac744a25039c26060ea..13ea1720790293eb56401ec9119852075e4ae97d 100644 (file)
@@ -78,6 +78,14 @@ __init efi_element_handler_t get_handler_for_ca_keys(const efi_guid_t *sig_type)
        return NULL;
 }
 
+__init efi_element_handler_t get_handler_for_code_signing_keys(const efi_guid_t *sig_type)
+{
+       if (efi_guidcmp(*sig_type, efi_cert_x509_guid) == 0)
+               return add_to_secondary_keyring;
+
+       return NULL;
+}
+
 /*
  * Return the appropriate handler for particular signature list types found in
  * the UEFI dbx and MokListXRT tables.
index 6f15bb4cc8dcb1e88ecdeed9a7d135da2c223c12..f92895cc50f6870ed43dfb3f7b19f2538defb225 100644 (file)
@@ -34,6 +34,11 @@ efi_element_handler_t get_handler_for_mok(const efi_guid_t *sig_type);
  */
 efi_element_handler_t get_handler_for_ca_keys(const efi_guid_t *sig_type);
 
+/*
+ * Return the handler for particular signature list types for code signing keys.
+ */
+efi_element_handler_t get_handler_for_code_signing_keys(const efi_guid_t *sig_type);
+
 /*
  * Return the handler for particular signature list types found in the dbx.
  */
index 339053d9726d3ed48038919111674c1602ea9fc6..c85febca3343e5470d9aab524f972ec50547f384 100644 (file)
@@ -60,6 +60,7 @@ static int __init load_powerpc_certs(void)
 {
        void *db = NULL, *dbx = NULL, *data = NULL;
        void *trustedca;
+       void *moduledb;
        u64 dsize = 0;
        u64 offset = 0;
        int rc = 0;
@@ -137,6 +138,22 @@ static int __init load_powerpc_certs(void)
                kfree(data);
        }
 
+       data = get_cert_list("moduledb", 9,  &dsize);
+       if (!data) {
+               pr_info("Couldn't get moduledb list from firmware\n");
+       } else if (IS_ERR(data)) {
+               rc = PTR_ERR(data);
+               pr_err("Error reading moduledb from firmware: %d\n", rc);
+       } else {
+               extract_esl(moduledb, data, dsize, offset);
+
+               rc = parse_efi_signature_list("powerpc:moduledb", moduledb, dsize,
+                                             get_handler_for_code_signing_keys);
+               if (rc)
+                       pr_err("Couldn't parse moduledb signatures: %d\n", rc);
+               kfree(data);
+       }
+
        return rc;
 }
 late_initcall(load_powerpc_certs);