Skip to content

Commit 278311e

Browse files
ryncsnmimizohar
authored andcommitted
kexec, KEYS: Make use of platform keyring for signature verify
This patch allows the kexec_file_load syscall to verify the PE signed kernel image signature based on the preboot keys stored in the .platform keyring, as fall back, if the signature verification failed due to not finding the public key in the secondary or builtin keyrings. This commit adds a VERIFY_USE_PLATFORM_KEYRING similar to previous VERIFY_USE_SECONDARY_KEYRING indicating that verify_pkcs7_signature should verify the signature using platform keyring. Also, decrease the error message log level when verification failed with -ENOKEY, so that if called tried multiple time with different keyring it won't generate extra noises. Signed-off-by: Kairui Song <kasong@redhat.com> Cc: David Howells <dhowells@redhat.com> Acked-by: Dave Young <dyoung@redhat.com> (for kexec_file_load part) [zohar@linux.ibm.com: tweaked the first paragraph of the patch description, and fixed checkpatch warning.] Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
1 parent 219a3e8 commit 278311e

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

‎arch/x86/kernel/kexec-bzimage64.c‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,17 @@ static int bzImage64_cleanup(void *loader_data)
531531
#ifdef CONFIG_KEXEC_BZIMAGE_VERIFY_SIG
532532
static int bzImage64_verify_sig(const char *kernel, unsigned long kernel_len)
533533
{
534-
return verify_pefile_signature(kernel, kernel_len,
535-
VERIFY_USE_SECONDARY_KEYRING,
536-
VERIFYING_KEXEC_PE_SIGNATURE);
534+
int ret;
535+
536+
ret = verify_pefile_signature(kernel, kernel_len,
537+
VERIFY_USE_SECONDARY_KEYRING,
538+
VERIFYING_KEXEC_PE_SIGNATURE);
539+
if (ret == -ENOKEY && IS_ENABLED(CONFIG_INTEGRITY_PLATFORM_KEYRING)) {
540+
ret = verify_pefile_signature(kernel, kernel_len,
541+
VERIFY_USE_PLATFORM_KEYRING,
542+
VERIFYING_KEXEC_PE_SIGNATURE);
543+
}
544+
return ret;
537545
}
538546
#endif
539547

‎certs/system_keyring.c‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,22 @@ int verify_pkcs7_signature(const void *data, size_t len,
240240
#else
241241
trusted_keys = builtin_trusted_keys;
242242
#endif
243+
} else if (trusted_keys == VERIFY_USE_PLATFORM_KEYRING) {
244+
#ifdef CONFIG_INTEGRITY_PLATFORM_KEYRING
245+
trusted_keys = platform_trusted_keys;
246+
#else
247+
trusted_keys = NULL;
248+
#endif
249+
if (!trusted_keys) {
250+
ret = -ENOKEY;
251+
pr_devel("PKCS#7 platform keyring is not available\n");
252+
goto error;
253+
}
243254
}
244255
ret = pkcs7_validate_trust(pkcs7, trusted_keys);
245256
if (ret < 0) {
246257
if (ret == -ENOKEY)
247-
pr_err("PKCS#7 signature not signed with a trusted key\n");
258+
pr_devel("PKCS#7 signature not signed with a trusted key\n");
248259
goto error;
249260
}
250261

‎include/linux/verification.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* should be used.
1818
*/
1919
#define VERIFY_USE_SECONDARY_KEYRING ((struct key *)1UL)
20+
#define VERIFY_USE_PLATFORM_KEYRING ((struct key *)2UL)
2021

2122
/*
2223
* The use to which an asymmetric key is being put.

0 commit comments

Comments
 (0)