let kexec_file_load use platform keyring to verify the kernel image
Subsystems (10)
v2 cover let kexec_file_load use platform keyring to verify the kernel image
Hi,
This patch series adds a .platform_trusted_keys in system_keyring as the reference to .platform keyring in integrity subsystem, when platform keyring is being initialized it will be updated. So other component could use this keyring as well.
This patch series also let kexec_file_load use platform keyring as fall back if it failed to verify the image against secondary keyring, make it possible to load kernel signed by third part key if third party key is imported in the firmware.
After this patch kexec_file_load will be able to verify a signed PE bzImage using keys in platform keyring.
Tested in a VM with locally signed kernel with pesign and imported the cert to EFI's MokList variable.
Kairui Song (2):
integrity, KEYS: add a reference to platform keyring kexec, KEYS: Make use of platform keyring for signature verify
Update from V1:
- Make platform_trusted_keys static, and update commit message as suggested by Mimi Zohar
- Always check if platform keyring is initialized before use it
arch/x86/kernel/kexec-bzimage64.c | 15 ++++++++++++--- certs/system_keyring.c | 20 +++++++++++++++++++- include/keys/system_keyring.h | 5 +++++ include/linux/verification.h | 3 +++ security/integrity/digsig.c | 6 ++++++ 5 files changed, 45 insertions(+), 4 deletions(-)
Signature · 1 line
2.20.1
RFC PATCH v2 1/2 integrity, KEYS: add a reference to platform keyring
Currently when loading new kernel via kexec_file_load syscall, it is able to verify the signed PE bzimage against .builtin_trusted_keys or .secondary_trusted_keys. But the image could be signed with third part keys which will be provided by platform or firmware as EFI variable (eg. stored in MokListRT EFI variable), and the keys won't be available in keyrings mentioned above.
After commit 9dc92c45177a ('integrity: Define a trusted platform keyring') a .platform keyring is introduced to store the keys provided by platform or firmware, this keyring is intended to be used for verifying kernel images being loaded by kexec_file_load syscall. And with a few following up commits, keys provided by firmware is being loaded into this keyring, and IMA-appraisal is able to use the keyring to verify kernel images. IMA is the currently the only user of that keyring.
This patch exposes the .platform, and makes it useable for other components. For example, kexec_file_load could use this .platform keyring to verify the kernel image's image.
--- certs/system_keyring.c | 9 +++++++++ include/keys/system_keyring.h | 5 +++++ security/integrity/digsig.c | 6 ++++++ 3 files changed, 20 insertions(+)
certs/system_keyring.c +9 -0
@@ -24,6 +24,9 @@ static struct key *builtin_trusted_keys;#ifdef CONFIG_SECONDARY_TRUSTED_KEYRING static struct key *secondary_trusted_keys;#endif +#ifdef CONFIG_INTEGRITY_PLATFORM_KEYRING +static struct key *platform_trusted_keys; +#endif extern __initconst const u8 system_certificate_list[];extern __initconst const unsigned long system_certificate_list_size;
@@ -265,4 +268,10 @@ int verify_pkcs7_signature(const void *data, size_t len, }EXPORT_SYMBOL_GPL (verify_pkcs7_signature); +#ifdef CONFIG_INTEGRITY_PLATFORM_KEYRING +void __init set_platform_trusted_keys (struct key *keyring) { + platform_trusted_keys = keyring; +} +#endif +#endif /* CONFIG_SYSTEM_DATA_VERIFICATION */
include/keys/system_keyring.h +5 -0
@@ -61,5 +61,10 @@ static inline struct key *get_ima_blacklist_keyring(void) }#endif /* CONFIG_IMA_BLACKLIST_KEYRING */ +#ifdef CONFIG_INTEGRITY_PLATFORM_KEYRING + +extern void __init set_platform_trusted_keys (struct key * keyring); + +#endif /* CONFIG_INTEGRITY_PLATFORM_KEYRING */ #endif /* _KEYS_SYSTEM_KEYRING_H */
security/integrity/digsig.c +6 -0
@@ -89,6 +89,12 @@ static int __integrity_init_keyring(const unsigned int id, key_perm_t perm, keyring[id] =NULL ; } +#ifdef CONFIG_INTEGRITY_PLATFORM_KEYRING +if (id =INTEGRITY_KEYRING_PLATFORM ) { +set_platform_trusted_keys (keyring[id]); + } +#endif +return err; }
Signature · 1 line
2.20.1
Mimi Zohar
maintainerRe: [RFC PATCH v2 1/2] integrity, KEYS: add a reference to platform keyring
On Tue, 2019-01-15 at 17:45 +0800, Kairui Song wrote:
[snip]
Quoted 7 lines
security/integrity/digsig.c +0
-0@@ -89,6 +89,12 @@ static int __integrity_init_keyring(const unsigned int id, key_perm_t perm, keyring[id] =NULL ; }
security/integrity/digsig.c static int __integrity_init_keyring(const unsigned int id, key_perm_t perm, · line 100
Quoted 10 lines
security/integrity/digsig.c +6
-0+#ifdef CONFIG_INTEGRITY_PLATFORM_KEYRING +if (id =INTEGRITY_KEYRING_PLATFORM ) { +set_platform_trusted_keys (keyring[id]); + } +#endif +return err; }
Any reason for setting it here as opposed to in the caller platform_keyring_init()?
Mimi
Re: [RFC PATCH v2 1/2] integrity, KEYS: add a reference to platform keyring
Quoted 25 lines · Mimi Zohar
On Tue, 2019-01-15 at 17:45 +0800, Kairui Song wrote:
[snip]Quoted 7 lines
security/integrity/digsig.c +0
-0@@ -89,6 +89,12 @@ static int __integrity_init_keyring(const unsigned int id, key_perm_t perm, keyring[id] =NULL ; }security/integrity/digsig.c static int __integrity_init_keyring(const unsigned int id, key_perm_t perm, · line 100
Quoted 10 lines
security/integrity/digsig.c +6
-0+#ifdef CONFIG_INTEGRITY_PLATFORM_KEYRING +if (id =INTEGRITY_KEYRING_PLATFORM ) { +set_platform_trusted_keys (keyring[id]); + } +#endif +return err; }Any reason for setting it here as opposed to in the caller
platform_keyring_init()?
Quoted 2 lines
Mimi
Yes, "keyring" is static so unless I expose it to other files, it is only accessible here. And I think there should be no problem to put the set_platform_trusted_keys here.
Signature · 2 lines
Best Regards, Kairui Song
Mimi Zohar
maintainerRe: [RFC PATCH v2 1/2] integrity, KEYS: add a reference to platform keyring
Quoted 26 lines · Kairui Song
Quoted 25 lines · Mimi Zohar
On Tue, 2019-01-15 at 17:45 +0800, Kairui Song wrote:
[snip]Quoted 7 lines
security/integrity/digsig.c +0
-0@@ -89,6 +89,12 @@ static int __integrity_init_keyring(const unsigned int id, key_perm_t perm, keyring[id] =NULL ; }security/integrity/digsig.c static int __integrity_init_keyring(const unsigned int id, key_perm_t perm, · line 100
Quoted 10 lines
security/integrity/digsig.c +6
-0+#ifdef CONFIG_INTEGRITY_PLATFORM_KEYRING +if (id =INTEGRITY_KEYRING_PLATFORM ) { +set_platform_trusted_keys (keyring[id]); + } +#endif +return err; }Any reason for setting it here as opposed to in the caller
platform_keyring_init()?
Quoted 6 lines
Quoted 2 lines
Mimi
Yes, "keyring" is static so unless I expose it to other files, it is only accessible here. And I think there should be no problem to put the
set_platform_trusted_keyshere.
Right, that's a really good reason.
Mimi
RFC PATCH v2 2/2 kexec, KEYS: Make use of platform keyring for signature verify
In reply to Kairui SongWith KEXEC_BZIMAGE_VERIFY_SIG enabled, kexec_file_load will need to verify the kernel image. The image might be signed with third part keys, and the keys could be stored in firmware, then got loaded into the .platform keyring. Now we have a symbol .platform_trusted_keyring as the reference to .platform keyring, this patch makes use if it and allow kexec_file_load to verify the image against keys in .platform keyring.
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.
--- arch/x86/kernel/kexec-bzimage64.c | 15 ++++++++++++--- certs/system_keyring.c | 11 ++++++++++- include/linux/verification.h | 3 +++ 3 files changed, 25 insertions(+), 4 deletions(-)
arch/x86/kernel/kexec-bzimage64.c +12 -3
@@ -534,9 +534,18 @@ static int bzImage64_cleanup(void *loader_data)#ifdef CONFIG_KEXEC_BZIMAGE_VERIFY_SIG static int bzImage64_verify_sig (const char *kernel,unsigned long kernel_len) { -return verify_pefile_signature (kernel, kernel_len, -VERIFY_USE_SECONDARY_KEYRING , -VERIFYING_KEXEC_PE_SIGNATURE ); +int ret; + ret =verify_pefile_signature (kernel, kernel_len, +VERIFY_USE_SECONDARY_KEYRING , +VERIFYING_KEXEC_PE_SIGNATURE ); +#ifdef CONFIG_INTEGRITY_PLATFORM_KEYRING +if (ret = -ENOKEY ) { + ret =verify_pefile_signature (kernel, kernel_len, +VERIFY_USE_PLATFORM_KEYRING , +VERIFYING_KEXEC_PE_SIGNATURE ); + } +#endif +return ret; }#endif
certs/system_keyring.c +10 -1
@@ -239,12 +239,21 @@ int verify_pkcs7_signature(const void *data, size_t len, trusted_keys = secondary_trusted_keys;#else trusted_keys = builtin_trusted_keys; +#endif +#ifdef CONFIG_INTEGRITY_PLATFORM_KEYRING + }else if (trusted_keys =VERIFY_USE_PLATFORM_KEYRING ) { + trusted_keys = platform_trusted_keys; +if (!trusted_keys) { + ret = -ENOKEY ; +pr_devel ("PKCS#7 platform keyring is not available\n" ); + goto error; + }#endif } ret =pkcs7_validate_trust (pkcs7, trusted_keys);if (ret <0 ) {if (ret = -ENOKEY ) -pr_err ("PKCS#7 signature not signed with a trusted key\n" ); +pr_devel ("PKCS#7 signature not signed with a trusted key\n" ); goto error; }
include/linux/verification.h +3 -0
@@ -17,6 +17,9 @@* should be used. */ #define VERIFY_USE_SECONDARY_KEYRING ((struct key *)1UL) +#ifdef CONFIG_INTEGRITY_PLATFORM_KEYRING +#define VERIFY_USE_PLATFORM_KEYRING ((struct key *)2UL) +#endif /* * The use to which an asymmetric key is being put.
Signature · 1 line
2.20.1
Mimi Zohar
maintainerRe: [RFC PATCH v2 2/2] kexec, KEYS: Make use of platform keyring for signature verify
Quoted 6 lines · Kairui Song
arch/x86/kernel/kexec-bzimage64.c +0
-0@@ -534,9 +534,18 @@ static int bzImage64_cleanup(void *loader_data)#ifdef CONFIG_KEXEC_BZIMAGE_VERIFY_SIG
arch/x86/kernel/kexec-bzimage64.c static int bzImage64_cleanup(void *loader_data) · line 541
Quoted 10 lines
arch/x86/kernel/kexec-bzimage64.c +5
-3static int bzImage64_verify_sig (const char *kernel,unsigned long kernel_len) { -return verify_pefile_signature (kernel, kernel_len, -VERIFY_USE_SECONDARY_KEYRING , -VERIFYING_KEXEC_PE_SIGNATURE ); +int ret; + ret =verify_pefile_signature (kernel, kernel_len, +VERIFY_USE_SECONDARY_KEYRING , +VERIFYING_KEXEC_PE_SIGNATURE ); +#ifdef CONFIG_INTEGRITY_PLATFORM_KEYRING
Consider using IS_ENABLED() or IS_BUILTIN().
Mimi
Quoted 9 lines
arch/x86/kernel/kexec-bzimage64.c +7
-0+if (ret = -ENOKEY ) { + ret =verify_pefile_signature (kernel, kernel_len, +VERIFY_USE_PLATFORM_KEYRING , +VERIFYING_KEXEC_PE_SIGNATURE ); + } +#endif + return ret; }#endif
Re: [RFC PATCH v2 2/2] kexec, KEYS: Make use of platform keyring for signature verify
Quoted 22 lines · Mimi Zohar
Quoted 6 lines · Kairui Song
arch/x86/kernel/kexec-bzimage64.c +0
-0@@ -534,9 +534,18 @@ static int bzImage64_cleanup(void *loader_data)#ifdef CONFIG_KEXEC_BZIMAGE_VERIFY_SIG arch/x86/kernel/kexec-bzimage64.c static int bzImage64_cleanup(void *loader_data) · line 541
Quoted 10 lines
arch/x86/kernel/kexec-bzimage64.c +5
-3static int bzImage64_verify_sig (const char *kernel,unsigned long kernel_len) { -return verify_pefile_signature (kernel, kernel_len, -VERIFY_USE_SECONDARY_KEYRING , -VERIFYING_KEXEC_PE_SIGNATURE ); +int ret; + ret =verify_pefile_signature (kernel, kernel_len, +VERIFY_USE_SECONDARY_KEYRING , +VERIFYING_KEXEC_PE_SIGNATURE ); +#ifdef CONFIG_INTEGRITY_PLATFORM_KEYRING Consider using
IS_ENABLED()orIS_BUILTIN().
Quoted 1 line
Mimi
Thanks for the suggestion, will update the patch later if there are no other comments.
Quoted 11 lines
arch/x86/kernel/kexec-bzimage64.c static int bzImage64_cleanup(void *loader_data) · line 550
Quoted 10 lines
arch/x86/kernel/kexec-bzimage64.c +7
-0+if (ret = -ENOKEY ) { + ret =verify_pefile_signature (kernel, kernel_len, +VERIFY_USE_PLATFORM_KEYRING , +VERIFYING_KEXEC_PE_SIGNATURE ); + } +#endif + return ret; }#endif
--
Best Regards,
Kairui Song