let kexec_file_load use platform keyring to verify the kernel image
Subsystems (10)
v5 cover let kexec_file_load use platform keyring to verify the kernel image
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 it will be accessable for verifying PE signed kernel image.
This patch series let kexec_file_load use platform keyring as fall back if it failed to verify the image against secondary keyring, so the actually PE signature verify process will use keys provides by 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.
To test this patch series on latest kernel, you need to ensure this commit is applied as there is an regression bug in sanity_check_segment_list():
Update from V4:
- Drop ifdef in security/integrity/digsig.c to make code clearer
- Fix a potential issue, set_platform_trusted_keys should not be called when keyring initialization failed
Update from V3:
- Tweak and simplify commit message as suggested by Mimi Zohar
Update from V2:
- Use IS_ENABLED in kexec_file_load to judge if platform_trusted_keys should be used for verifying image as suggested by Mimi Zohar
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
Kairui Song (2):
integrity, KEYS: add a reference to platform keyring kexec, KEYS: Make use of platform keyring for signature verify
arch/x86/kernel/kexec-bzimage64.c | 13 ++++++++++--- certs/system_keyring.c | 22 +++++++++++++++++++++- include/keys/system_keyring.h | 9 +++++++++ include/linux/verification.h | 1 + security/integrity/digsig.c | 3 +++ 5 files changed, 44 insertions(+), 4 deletions(-)
Signature · 1 line
2.20.1
PATCH v5 1/2 integrity, KEYS: add a reference to platform keyring
commit 9dc92c45177a ('integrity: Define a trusted platform keyring') introduced a .platform keyring for storing preboot keys, used for verifying kernel images' signature. Currently only IMA-appraisal is able to use the keyring to verify kernel images that have their signature stored in xattr.
This patch exposes the .platform keyring, making it accessible for verifying PE signed kernel images as well.
--- certs/system_keyring.c | 9 +++++++++ include/keys/system_keyring.h | 9 +++++++++ security/integrity/digsig.c | 3 +++ 3 files changed, 21 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 +9 -0
@@ -61,5 +61,14 @@ 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); + +#else + +static inline void set_platform_trusted_keys (struct key * keyring) { }; + +#endif /* CONFIG_INTEGRITY_PLATFORM_KEYRING */ #endif /* _KEYS_SYSTEM_KEYRING_H */
security/integrity/digsig.c +3 -0
@@ -87,6 +87,9 @@ static int __integrity_init_keyring(const unsigned int id, key_perm_t perm,pr_info ("Can't allocate %s keyring (%d)\n" , keyring_name[id], err); keyring[id] =NULL ; + }else { +if (id =INTEGRITY_KEYRING_PLATFORM ) +set_platform_trusted_keys (keyring[id]); }return err;
Signature · 1 line
2.20.1
Mimi Zohar
maintainerRe: [PATCH v5 1/2] integrity, KEYS: add a reference to platform keyring
Quoted 11 lines · Kairui Song
commit
9dc92c45177a('integrity: Define a trusted platform keyring') introduced a .platform keyring for storing preboot keys, used for verifying kernel images' signature. Currently only IMA-appraisal is able to use the keyring to verify kernel images that have their signature stored in xattr.This patch exposes the .platform keyring, making it accessible for verifying PE signed kernel images as well.
Suggested-by Mimi Zohar <[email protected]>Signed-off-by Kairui Song <[email protected]>
Reviewed/Tested-by: Mimi Zohar <[email protected]>
Quoted 64 lines
--- certs/system_keyring.c | 9 +++++++++ include/keys/system_keyring.h | 9 +++++++++ security/integrity/digsig.c | 3 +++ 3 files changed, 21 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 +9
-0@@ -61,5 +61,14 @@ 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); + +#else + +static inline void set_platform_trusted_keys (struct key * keyring) { }; + +#endif /* CONFIG_INTEGRITY_PLATFORM_KEYRING */ #endif /* _KEYS_SYSTEM_KEYRING_H */ security/integrity/digsig.c +3
-0@@ -87,6 +87,9 @@ static int __integrity_init_keyring(const unsigned int id, key_perm_t perm,pr_info ("Can't allocate %s keyring (%d)\n" , keyring_name[id], err); keyring[id] =NULL ; + }else { +if (id =INTEGRITY_KEYRING_PLATFORM ) +set_platform_trusted_keys (keyring[id]); }return err;
PATCH v5 2/2 kexec, KEYS: Make use of platform keyring for signature verify
In reply to Kairui SongThis patch let kexec_file_load makes use of .platform keyring as fall back if it failed to verify a PE signed image against secondary or builtin key ring, make it possible to verify kernel image signed with preboot keys as well.
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 | 13 ++++++++++--- certs/system_keyring.c | 13 ++++++++++++- include/linux/verification.h | 1 + 3 files changed, 23 insertions(+), 4 deletions(-)
arch/x86/kernel/kexec-bzimage64.c +10 -3
@@ -534,9 +534,16 @@ 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 ); +if (ret = -ENOKEY &&IS_ENABLED (CONFIG_INTEGRITY_PLATFORM_KEYRING )) { + ret =verify_pefile_signature (kernel, kernel_len, +VERIFY_USE_PLATFORM_KEYRING , +VERIFYING_KEXEC_PE_SIGNATURE ); + } +return ret; }#endif
certs/system_keyring.c +12 -1
@@ -240,11 +240,22 @@ int verify_pkcs7_signature(const void *data, size_t len,#else trusted_keys = builtin_trusted_keys;#endif + }else if (trusted_keys =VERIFY_USE_PLATFORM_KEYRING ) { +#ifdef CONFIG_INTEGRITY_PLATFORM_KEYRING + trusted_keys = platform_trusted_keys; +#else + trusted_keys =NULL ; +#endif +if (!trusted_keys) { + ret = -ENOKEY ; +pr_devel ("PKCS#7 platform keyring is not available\n" ); + goto error; + } } 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 +1 -0
@@ -17,6 +17,7 @@* should be used. */ #define VERIFY_USE_SECONDARY_KEYRING ((struct key *)1UL) +#define VERIFY_USE_PLATFORM_KEYRING ((struct key *)2UL)/* * The use to which an asymmetric key is being put.
Signature · 1 line
2.20.1
Mimi Zohar
maintainerRe: [PATCH v5 2/2] kexec, KEYS: Make use of platform keyring for signature verify
Quoted 5 lines · Kairui Song
This patch let
kexec_file_loadmakes use of .platform keyring as fall back if it failed to verify a PE signed image against secondary or builtin key ring, make it possible to verify kernel image signed with preboot keys as well.
Quoted 8 lines
This commit adds a
VERIFY_USE_PLATFORM_KEYRINGsimilar to previousVERIFY_USE_SECONDARY_KEYRINGindicating thatverify_pkcs7_signatureshould 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 <[email protected]>
Reviewed/Tested-by: Mimi Zohar <[email protected]>
Quoted 70 lines
--- arch/x86/kernel/kexec-bzimage64.c | 13 ++++++++++--- certs/system_keyring.c | 13 ++++++++++++- include/linux/verification.h | 1 + 3 files changed, 23 insertions(+), 4 deletions(-)arch/x86/kernel/kexec-bzimage64.c +10
-3@@ -534,9 +534,16 @@ 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 ); +if (ret = -ENOKEY &&IS_ENABLED (CONFIG_INTEGRITY_PLATFORM_KEYRING )) { + ret =verify_pefile_signature (kernel, kernel_len, +VERIFY_USE_PLATFORM_KEYRING , +VERIFYING_KEXEC_PE_SIGNATURE ); + } +return ret; }#endif certs/system_keyring.c +12
-1@@ -240,11 +240,22 @@ int verify_pkcs7_signature(const void *data, size_t len,#else trusted_keys = builtin_trusted_keys;#endif + }else if (trusted_keys =VERIFY_USE_PLATFORM_KEYRING ) { +#ifdef CONFIG_INTEGRITY_PLATFORM_KEYRING + trusted_keys = platform_trusted_keys; +#else + trusted_keys =NULL ; +#endif +if (!trusted_keys) { + ret = -ENOKEY ; +pr_devel ("PKCS#7 platform keyring is not available\n" ); + goto error; + } } 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 +1
-0@@ -17,6 +17,7 @@* should be used. */ #define VERIFY_USE_SECONDARY_KEYRING ((struct key *)1UL) +#define VERIFY_USE_PLATFORM_KEYRING ((struct key *)2UL)/* * The use to which an asymmetric key is being put.
Re: [PATCH v5 2/2] kexec, KEYS: Make use of platform keyring for signature verify
In reply to Kairui SongQuoted 86 lines · Kairui Song
This patch let
kexec_file_loadmakes use of .platform keyring as fall back if it failed to verify a PE signed image against secondary or builtin key ring, make it possible to verify kernel image signed with preboot keys as well.This commit adds a
VERIFY_USE_PLATFORM_KEYRINGsimilar to previousVERIFY_USE_SECONDARY_KEYRINGindicating thatverify_pkcs7_signatureshould 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 <[email protected]>--- arch/x86/kernel/kexec-bzimage64.c | 13 ++++++++++--- certs/system_keyring.c | 13 ++++++++++++- include/linux/verification.h | 1 + 3 files changed, 23 insertions(+), 4 deletions(-)arch/x86/kernel/kexec-bzimage64.c +10
-3@@ -534,9 +534,16 @@ 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 ); +if (ret = -ENOKEY &&IS_ENABLED (CONFIG_INTEGRITY_PLATFORM_KEYRING )) { + ret =verify_pefile_signature (kernel, kernel_len, +VERIFY_USE_PLATFORM_KEYRING , +VERIFYING_KEXEC_PE_SIGNATURE ); + } +return ret; }#endif certs/system_keyring.c +12
-1@@ -240,11 +240,22 @@ int verify_pkcs7_signature(const void *data, size_t len,#else trusted_keys = builtin_trusted_keys;#endif + }else if (trusted_keys =VERIFY_USE_PLATFORM_KEYRING ) { +#ifdef CONFIG_INTEGRITY_PLATFORM_KEYRING + trusted_keys = platform_trusted_keys; +#else + trusted_keys =NULL ; +#endif +if (!trusted_keys) { + ret = -ENOKEY ; +pr_devel ("PKCS#7 platform keyring is not available\n" ); + goto error; + } } 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 +1
-0@@ -17,6 +17,7 @@* should be used. */ #define VERIFY_USE_SECONDARY_KEYRING ((struct key *)1UL) +#define VERIFY_USE_PLATFORM_KEYRING ((struct key *)2UL)/* * The use to which an asymmetric key is being put. Signature · 1 line
2.20.1
For kexec_file part
Thanks
Dave
Quoted 50 lines · Kairui Song
This patch series adds a .platform_trusted_keys in
system_keyringas the reference to .platform keyring in integrity subsystem, when platform keyring is being initialized it will be updated, so it will be accessable for verifying PE signed kernel image.This patch series let
kexec_file_loaduse platform keyring as fall back if it failed to verify the image against secondary keyring, so the actually PE signature verify process will use keys provides by firmware.After this patch
kexec_file_loadwill 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.
To test this patch series on latest kernel, you need to ensure this commit is applied as there is an regression bug in
sanity_check_segment_list():Update from V4:
- Drop ifdef insecurity/integrity/digsig.cto make code clearer
- Fix a potential issue,set_platform_trusted_keysshould not be called when keyring initialization failedUpdate from V3:
- Tweak and simplify commit message as suggested by Mimi ZoharUpdate from V2:
- UseIS_ENABLEDinkexec_file_loadto judge ifplatform_trusted_keysshould be used for verifying image as suggested by Mimi ZoharUpdate from V1:
- Makeplatform_trusted_keysstatic, and update commit message as suggested by Mimi Zohar
- Always check if platform keyring is initialized before use itKairui Song (2):
integrity, KEYS: add a reference to platform keyring kexec, KEYS: Make use of platform keyring for signature verifyarch/x86/kernel/kexec-bzimage64.c | 13 ++++++++++--- certs/system_keyring.c | 22 +++++++++++++++++++++- include/keys/system_keyring.h | 9 +++++++++ include/linux/verification.h | 1 + security/integrity/digsig.c | 3 +++ 5 files changed, 44 insertions(+), 4 deletions(-)
Quoted 3 lines
--
2.20.1
Hi Mimi,
I've updated the patch series again and as the code changed a bit I didn't include previous Reviewd-by / Tested-by, it worked with no problem, could you help have a review again? Thank you.
Signature · 2 lines
Best Regards, Kairui Song
Mimi Zohar
maintainerQuoted 4 lines · Kairui Song
This patch series adds a .platform_trusted_keys in
system_keyringas the reference to .platform keyring in integrity subsystem, when platform keyring is being initialized it will be updated, so it will be accessable for verifying PE signed kernel image.
There were some scripts/checkpatch.pl errors/warnings emitted on these patches. I've fixed them, but in the future please follow the guidelines in Documentation/process/submitting-patches.rst.
These patches are now queued in the next-integrity branch of
https://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity.git
Mimi