Skip to content

Commit 44e69ea

Browse files
naynajainjarkkojs
authored andcommitted
integrity: PowerVM support for loading third party code signing keys
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>
1 parent d7d91c4 commit 44e69ea

5 files changed

Lines changed: 64 additions & 0 deletions

File tree

certs/system_keyring.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,36 @@ static __init struct key_restriction *get_builtin_and_secondary_restriction(void
152152

153153
return restriction;
154154
}
155+
156+
/**
157+
* add_to_secondary_keyring - Add to secondary keyring.
158+
* @source: Source of key
159+
* @data: The blob holding the key
160+
* @len: The length of the data blob
161+
*
162+
* Add a key to the secondary keyring. The key must be vouched for by a key in the builtin,
163+
* machine or secondary keyring itself.
164+
*/
165+
void __init add_to_secondary_keyring(const char *source, const void *data, size_t len)
166+
{
167+
key_ref_t key;
168+
key_perm_t perm;
169+
170+
perm = (KEY_POS_ALL & ~KEY_POS_SETATTR) | KEY_USR_VIEW;
171+
172+
key = key_create_or_update(make_key_ref(secondary_trusted_keys, 1),
173+
"asymmetric",
174+
NULL, data, len, perm,
175+
KEY_ALLOC_NOT_IN_QUOTA);
176+
if (IS_ERR(key)) {
177+
pr_err("Problem loading X.509 certificate from %s to secondary keyring %ld\n",
178+
source, PTR_ERR(key));
179+
return;
180+
}
181+
182+
pr_notice("Loaded X.509 cert '%s'\n", key_ref_to_ptr(key)->description);
183+
key_ref_put(key);
184+
}
155185
#endif
156186
#ifdef CONFIG_INTEGRITY_MACHINE_KEYRING
157187
void __init set_machine_trusted_keys(struct key *keyring)

include/keys/system_keyring.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ int restrict_link_by_digsig_builtin_and_secondary(struct key *keyring,
5050
const struct key_type *type,
5151
const union key_payload *payload,
5252
struct key *restriction_key);
53+
void __init add_to_secondary_keyring(const char *source, const void *data, size_t len);
5354
#else
5455
#define restrict_link_by_builtin_and_secondary_trusted restrict_link_by_builtin_trusted
5556
#define restrict_link_by_digsig_builtin_and_secondary restrict_link_by_digsig_builtin
57+
static inline void __init add_to_secondary_keyring(const char *source, const void *data, size_t len)
58+
{
59+
}
5660
#endif
5761

5862
#ifdef CONFIG_INTEGRITY_MACHINE_KEYRING

security/integrity/platform_certs/keyring_handler.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ __init efi_element_handler_t get_handler_for_ca_keys(const efi_guid_t *sig_type)
7878
return NULL;
7979
}
8080

81+
__init efi_element_handler_t get_handler_for_code_signing_keys(const efi_guid_t *sig_type)
82+
{
83+
if (efi_guidcmp(*sig_type, efi_cert_x509_guid) == 0)
84+
return add_to_secondary_keyring;
85+
86+
return NULL;
87+
}
88+
8189
/*
8290
* Return the appropriate handler for particular signature list types found in
8391
* the UEFI dbx and MokListXRT tables.

security/integrity/platform_certs/keyring_handler.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ efi_element_handler_t get_handler_for_mok(const efi_guid_t *sig_type);
3434
*/
3535
efi_element_handler_t get_handler_for_ca_keys(const efi_guid_t *sig_type);
3636

37+
/*
38+
* Return the handler for particular signature list types for code signing keys.
39+
*/
40+
efi_element_handler_t get_handler_for_code_signing_keys(const efi_guid_t *sig_type);
41+
3742
/*
3843
* Return the handler for particular signature list types found in the dbx.
3944
*/

security/integrity/platform_certs/load_powerpc.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ static int __init load_powerpc_certs(void)
6060
{
6161
void *db = NULL, *dbx = NULL, *data = NULL;
6262
void *trustedca;
63+
void *moduledb;
6364
u64 dsize = 0;
6465
u64 offset = 0;
6566
int rc = 0;
@@ -137,6 +138,22 @@ static int __init load_powerpc_certs(void)
137138
kfree(data);
138139
}
139140

141+
data = get_cert_list("moduledb", 9, &dsize);
142+
if (!data) {
143+
pr_info("Couldn't get moduledb list from firmware\n");
144+
} else if (IS_ERR(data)) {
145+
rc = PTR_ERR(data);
146+
pr_err("Error reading moduledb from firmware: %d\n", rc);
147+
} else {
148+
extract_esl(moduledb, data, dsize, offset);
149+
150+
rc = parse_efi_signature_list("powerpc:moduledb", moduledb, dsize,
151+
get_handler_for_code_signing_keys);
152+
if (rc)
153+
pr_err("Couldn't parse moduledb signatures: %d\n", rc);
154+
kfree(data);
155+
}
156+
140157
return rc;
141158
}
142159
late_initcall(load_powerpc_certs);

0 commit comments

Comments
 (0)