use more system keyrings to verify arm64 and s390 kexec kernel image signature
Subsystems (8)
v6 cover use more system keyrings to verify arm64 and s390 kexec kernel image signature
Currently, a problem faced by arm64 is if a kernel image is signed by a MOK key, loading it via the kexec_file_load() system call would be rejected with the error "Lockdown: kexec: kexec of unsigned images is restricted; see man kernel_lockdown.7". This happens because arm64 uses only the primary keyring that contains only kernel built-in keys to verify the kexec image.
Similarly, s390 only uses platform keyring for kernel image signature verification and built-in keys and secondary keyring are not used.
This patch set allows arm64 and s390 to use more system keyrings to verify kexec kernel image signature as x86 does.
v6:
- integrate the first three patches of "[PATCH 0/4] Unifrom keyring support across architectures and functions" from Michal [1]
- improve commit message [Baoquan, Michal]
- directly assign kexec_kernel_verify_pe_sig to kexec_file_ops->verify_sig [Michal]
v5:
- improve commit message [Baoquan]
v4:
- fix commit reference format issue and other checkpatch.pl warnings [Baoquan]
v3:
- s/arch_kexec_kernel_verify_pe_sig/kexec_kernel_verify_pe_sig [Eric]
- clean up arch_kexec_kernel_verify_sig [Eric]
v2:
- only x86_64 and arm64 need to enable PE file signature check [Dave]
[1] https://lore.kernel.org/lkml/cover.1644953683.git.msuchanek at suse.de/
Coiby Xu (3):
kexec: clean up arch_kexec_kernel_verify_sig
kexec, KEYS: make the code in bzImage64_verify_sig generic
arm64: kexec_file: use more system keyrings to verify kernel image
signature
Michal Suchanek (1):
kexec, KEYS, s390: Make use of built-in and secondary keyring for
signature verification
arch/arm64/kernel/kexec_image.c | 11 +----- arch/s390/kernel/machine_kexec_file.c | 18 +++++++--- arch/x86/kernel/kexec-bzimage64.c | 20 +---------- include/linux/kexec.h | 7 ++-- kernel/kexec_file.c | 51 ++++++++++++++++----------- 5 files changed, 50 insertions(+), 57 deletions(-)
Signature · 1 line
2.34.1
PATCH v6 1/4 kexec: clean up arch_kexec_kernel_verify_sig
Currently there is no arch-specific implementation of arch_kexec_kernel_verify_sig. Even if we want to add an implementation for an architecture in the future, we can simply use "(struct kexec_file_ops*)->verify_sig". So clean it up.
--- include/linux/kexec.h | 4 ---- kernel/kexec_file.c | 34 +++++++++++++--------------------- 2 files changed, 13 insertions(+), 25 deletions(-)
include/linux/kexec.h +0 -4
@@ -202,10 +202,6 @@ int arch_kexec_apply_relocations(struct purgatory_info *pi,const Elf_Shdr *relsec, const Elf_Shdr *symtab);int arch_kimage_file_post_load_cleanup (struct kimage *image); -#ifdef CONFIG_KEXEC_SIG -int arch_kexec_kernel_verify_sig (struct kimage *image,void *buf, -unsigned long buf_len); -#endif int arch_kexec_locate_mem_hole (struct kexec_buf *kbuf);extern int kexec_add_buffer (struct kexec_buf *kbuf);
kernel/kexec_file.c +13 -21
@@ -89,25 +89,6 @@ int __weak arch_kimage_file_post_load_cleanup(struct kimage *image)return kexec_image_post_load_cleanup_default (image); } -#ifdef CONFIG_KEXEC_SIG -static int kexec_image_verify_sig_default (struct kimage *image,void *buf, -unsigned long buf_len) -{ -if (!image->fops || !image->fops->verify_sig) { -pr_debug ("kernel loader does not support signature verification.\n" ); -return -EKEYREJECTED ; - } - -return image->fops->verify_sig (buf, buf_len); -} - -int __weak arch_kexec_kernel_verify_sig (struct kimage *image,void *buf, -unsigned long buf_len) -{ -return kexec_image_verify_sig_default (image, buf, buf_len); -} -#endif -/* * arch_kexec_apply_relocations_add - apply relocations of type RELA * @pi: Purgatory to be relocated.
@@ -184,13 +165,24 @@ void kimage_file_post_load_cleanup(struct kimage *image) }#ifdef CONFIG_KEXEC_SIG +static int kexec_image_verify_sig (struct kimage *image,void *buf, +unsigned long buf_len) +{ +if (!image->fops || !image->fops->verify_sig) { +pr_debug ("kernel loader does not support signature verification.\n" ); +return -EKEYREJECTED ; + } + +return image->fops->verify_sig (buf, buf_len); +} +static int kimage_validate_signature (struct kimage *image) {int ret; - ret =arch_kexec_kernel_verify_sig (image, image->kernel_buf, - image->kernel_buf_len); + ret =kexec_image_verify_sig (image, image->kernel_buf, + image->kernel_buf_len);if (ret) {if (IS_ENABLED (CONFIG_KEXEC_SIG_FORCE )) {
Signature · 1 line
2.34.1
Re: [PATCH v6 1/4] kexec: clean up arch_kexec_kernel_verify_sig
Quoted 7 lines · Coiby Xu
Currently there is no arch-specific implementation of
arch_kexec_kernel_verify_sig. Even if we want to add an implementation for an architecture in the future, we can simply use "(struct kexec_file_ops*)->verify_sig". So clean it up.Suggested-by Eric W. Biederman <[email protected]>Cc stable at kernel.org
It should be not worth noticing stable kernel that a clean up patch need be back ported.
Otherwise this looks good to me,
Quoted 82 lines
Reviewed-by Michal Suchanek <[email protected]>Signed-off-by Coiby Xu <[email protected]>--- include/linux/kexec.h | 4 ---- kernel/kexec_file.c | 34 +++++++++++++--------------------- 2 files changed, 13 insertions(+), 25 deletions(-)include/linux/kexec.h +0
-4@@ -202,10 +202,6 @@ int arch_kexec_apply_relocations(struct purgatory_info *pi,const Elf_Shdr *relsec, const Elf_Shdr *symtab);int arch_kimage_file_post_load_cleanup (struct kimage *image); -#ifdef CONFIG_KEXEC_SIG -int arch_kexec_kernel_verify_sig (struct kimage *image,void *buf, -unsigned long buf_len); -#endif int arch_kexec_locate_mem_hole (struct kexec_buf *kbuf);extern int kexec_add_buffer (struct kexec_buf *kbuf);kernel/kexec_file.c +13
-21@@ -89,25 +89,6 @@ int __weak arch_kimage_file_post_load_cleanup(struct kimage *image)return kexec_image_post_load_cleanup_default (image); } -#ifdef CONFIG_KEXEC_SIG -static int kexec_image_verify_sig_default (struct kimage *image,void *buf, -unsigned long buf_len) -{ -if (!image->fops || !image->fops->verify_sig) { -pr_debug ("kernel loader does not support signature verification.\n" ); -return -EKEYREJECTED ; - } - -return image->fops->verify_sig (buf, buf_len); -} - -int __weak arch_kexec_kernel_verify_sig (struct kimage *image,void *buf, -unsigned long buf_len) -{ -return kexec_image_verify_sig_default (image, buf, buf_len); -} -#endif -/* * arch_kexec_apply_relocations_add - apply relocations of type RELA * @pi: Purgatory to be relocated. @@ -184,13 +165,24 @@ void kimage_file_post_load_cleanup(struct kimage *image) }#ifdef CONFIG_KEXEC_SIG +static int kexec_image_verify_sig (struct kimage *image,void *buf, +unsigned long buf_len) +{ +if (!image->fops || !image->fops->verify_sig) { +pr_debug ("kernel loader does not support signature verification.\n" ); +return -EKEYREJECTED ; + } + +return image->fops->verify_sig (buf, buf_len); +} +static int kimage_validate_signature (struct kimage *image) {int ret; - ret =arch_kexec_kernel_verify_sig (image, image->kernel_buf, - image->kernel_buf_len); + ret =kexec_image_verify_sig (image, image->kernel_buf, + image->kernel_buf_len);if (ret) {if (IS_ENABLED (CONFIG_KEXEC_SIG_FORCE )) {Signature · 1 line
2.34.1
Re: [PATCH v6 1/4] kexec: clean up arch_kexec_kernel_verify_sig
Quoted 11 lines · Baoquan He
Quoted 7 lines · Coiby Xu
Currently there is no arch-specific implementation of
arch_kexec_kernel_verify_sig. Even if we want to add an implementation for an architecture in the future, we can simply use "(struct kexec_file_ops*)->verify_sig". So clean it up.Suggested-by Eric W. Biederman <[email protected]>Cc stable at kernel.orgIt should be not worth noticing stable kernel that a clean up patch need be back ported.
Thanks for the suggestion! For the 2nd and 3rd patch, I'll add prerequisite info,
and
respectively.
Quoted 4 lines
Otherwise this looks good to me,
Acked-by Baoquan He <[email protected]>
Thanks for reviewing the patch!
Quoted 84 lines
Quoted 83 lines
Reviewed-by Michal Suchanek <[email protected]>Signed-off-by Coiby Xu <[email protected]>--- include/linux/kexec.h | 4 ---- kernel/kexec_file.c | 34 +++++++++++++--------------------- 2 files changed, 13 insertions(+), 25 deletions(-)include/linux/kexec.h +0
-4@@ -202,10 +202,6 @@ int arch_kexec_apply_relocations(struct purgatory_info *pi,const Elf_Shdr *relsec, const Elf_Shdr *symtab);int arch_kimage_file_post_load_cleanup (struct kimage *image); -#ifdef CONFIG_KEXEC_SIG -int arch_kexec_kernel_verify_sig (struct kimage *image,void *buf, -unsigned long buf_len); -#endif int arch_kexec_locate_mem_hole (struct kexec_buf *kbuf);extern int kexec_add_buffer (struct kexec_buf *kbuf);kernel/kexec_file.c +13
-22@@ -89,25 +89,6 @@ int __weak arch_kimage_file_post_load_cleanup(struct kimage *image)return kexec_image_post_load_cleanup_default (image); } -#ifdef CONFIG_KEXEC_SIG -static int kexec_image_verify_sig_default (struct kimage *image,void *buf, -unsigned long buf_len) -{ -if (!image->fops || !image->fops->verify_sig) { -pr_debug ("kernel loader does not support signature verification.\n" ); -return -EKEYREJECTED ; - } - -return image->fops->verify_sig (buf, buf_len); -} - -int __weak arch_kexec_kernel_verify_sig (struct kimage *image,void *buf, -unsigned long buf_len) -{ -return kexec_image_verify_sig_default (image, buf, buf_len); -} -#endif -/* * arch_kexec_apply_relocations_add - apply relocations of type RELA * @pi: Purgatory to be relocated. @@ -184,13 +165,24 @@ void kimage_file_post_load_cleanup(struct kimage *image) }#ifdef CONFIG_KEXEC_SIG +static int kexec_image_verify_sig (struct kimage *image,void *buf, +unsigned long buf_len) +{ +if (!image->fops || !image->fops->verify_sig) { +pr_debug ("kernel loader does not support signature verification.\n" ); +return -EKEYREJECTED ; + } + +return image->fops->verify_sig (buf, buf_len); +} +static int kimage_validate_signature (struct kimage *image) {int ret; - ret =arch_kexec_kernel_verify_sig (image, image->kernel_buf, - image->kernel_buf_len); + ret =kexec_image_verify_sig (image, image->kernel_buf, + image->kernel_buf_len);if (ret) {if (IS_ENABLED (CONFIG_KEXEC_SIG_FORCE )) { --2.34.1
Signature · 2 lines
Best regards, Coiby
Re: [PATCH v6 1/4] kexec: clean up arch_kexec_kernel_verify_sig
Quoted 16 lines · Coiby Xu
Quoted 11 lines · Baoquan He
Quoted 7 lines · Coiby Xu
Currently there is no arch-specific implementation of
arch_kexec_kernel_verify_sig. Even if we want to add an implementation for an architecture in the future, we can simply use "(struct kexec_file_ops*)->verify_sig". So clean it up.Suggested-by Eric W. Biederman <[email protected]>Cc stable at kernel.orgIt should be not worth noticing stable kernel that a clean up patch need be back ported.
Thanks for the suggestion! For the 2nd and 3rd patch, I'll add prerequisite info,
Quoted 8 lines
Cc stable at kernel.org # 34d5960af253: kexec: clean up arch_kexec_kernel_verify_sigand
Cc stable at kernel.org # 34d5960af253: kexec: clean up arch_kexec_kernel_verify_sigCc stable at kernel.org # 83b7bb2d49ae: kexec, KEYS: make the code in bzImage64_verify_sig genericrespectively.
That sounds good, thx.
PATCH v6 2/4 kexec, KEYS: make the code in bzImage64_verify_sig generic
In reply to Coiby Xucommit 278311e417be ("kexec, KEYS: Make use of platform keyring for signature verify") adds platform keyring support on x86 kexec but not arm64.
The code in bzImage64_verify_sig makes use of system keyrings including .buitin_trusted_keys, .secondary_trusted_keys and .platform keyring to verify signed kernel image as PE file. Make it generic so both x86_64 and arm64 can use it.
--- arch/x86/kernel/kexec-bzimage64.c | 20 +------------------- include/linux/kexec.h | 7 +++++++ kernel/kexec_file.c | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 19 deletions(-)
arch/x86/kernel/kexec-bzimage64.c +1 -19
@@ -17,7 +17,6 @@#include <linux/kernel.h> #include <linux/mm.h> #include <linux/efi.h> -#include <linux/verification.h> #include <asm/bootparam.h> #include <asm/setup.h>
@@ -528,28 +527,11 @@ static int bzImage64_cleanup(void *loader_data)return 0 ; } -#ifdef CONFIG_KEXEC_BZIMAGE_VERIFY_SIG -static int bzImage64_verify_sig (const char *kernel,unsigned long kernel_len) -{ -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 -const struct kexec_file_ops kexec_bzImage64_ops = { .probe = bzImage64_probe, .load = bzImage64_load, .cleanup = bzImage64_cleanup, #ifdef CONFIG_KEXEC_BZIMAGE_VERIFY_SIG - .verify_sig = bzImage64_verify_sig, + .verify_sig = kexec_kernel_verify_pe_sig, #endif };
include/linux/kexec.h +7 -0
@@ -19,6 +19,7 @@#include <asm/io.h> #include <uapi/linux/kexec.h> +#include <linux/verification.h> /* Location of a reserved region to hold the crash kernel. */
@@ -202,6 +203,12 @@ int arch_kexec_apply_relocations(struct purgatory_info *pi,const Elf_Shdr *relsec, const Elf_Shdr *symtab);int arch_kimage_file_post_load_cleanup (struct kimage *image); +#ifdef CONFIG_KEXEC_SIG +#ifdef CONFIG_SIGNED_PE_FILE_VERIFICATION +int kexec_kernel_verify_pe_sig (const char *kernel, +unsigned long kernel_len); +#endif +#endif int arch_kexec_locate_mem_hole (struct kexec_buf *kbuf);extern int kexec_add_buffer (struct kexec_buf *kbuf);
kernel/kexec_file.c +17 -0
@@ -165,6 +165,23 @@ void kimage_file_post_load_cleanup(struct kimage *image) }#ifdef CONFIG_KEXEC_SIG +#ifdef CONFIG_SIGNED_PE_FILE_VERIFICATION +int kexec_kernel_verify_pe_sig (const char *kernel,unsigned long kernel_len) +{ +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 +static int kexec_image_verify_sig (struct kimage *image,void *buf,unsigned long buf_len) {
Signature · 1 line
2.34.1
Re: [PATCH v6 2/4] kexec, KEYS: make the code in bzImage64_verify_sig generic
Quoted 10 lines · Coiby Xu
commit
278311e417be("kexec, KEYS: Make use of platform keyring for signature verify") adds platform keyring support on x86 kexec but not arm64.The code in
bzImage64_verify_sigmakes use of system keyrings including .buitin_trusted_keys, .secondary_trusted_keys and .platform keyring to verify signed kernel image as PE file. Make it generic so bothx86_64and arm64 can use it.Fixes 278311e417be ("kexec, KEYS: Make use of platform keyring for signature verify")
Will the code in bzImage64_verify_sig generic not being genric cause any issue? Asking this because I don't get why making code generic need add 'Fixes' tag.
Quoted 110 lines
Cc kexec at lists.infradead.orgCc keyrings at vger.kernel.orgCc linux-security-module at vger.kernel.orgCc stable at kernel.orgReviewed-by Michal Suchanek <[email protected]>Signed-off-by Coiby Xu <[email protected]>--- arch/x86/kernel/kexec-bzimage64.c | 20 +------------------- include/linux/kexec.h | 7 +++++++ kernel/kexec_file.c | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 19 deletions(-)arch/x86/kernel/kexec-bzimage64.c +1
-19@@ -17,7 +17,6 @@#include <linux/kernel.h> #include <linux/mm.h> #include <linux/efi.h> -#include <linux/verification.h> #include <asm/bootparam.h> #include <asm/setup.h> @@ -528,28 +527,11 @@ static int bzImage64_cleanup(void *loader_data)return 0 ; } -#ifdef CONFIG_KEXEC_BZIMAGE_VERIFY_SIG -static int bzImage64_verify_sig (const char *kernel,unsigned long kernel_len) -{ -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 -const struct kexec_file_ops kexec_bzImage64_ops = { .probe = bzImage64_probe, .load = bzImage64_load, .cleanup = bzImage64_cleanup, #ifdef CONFIG_KEXEC_BZIMAGE_VERIFY_SIG - .verify_sig = bzImage64_verify_sig, + .verify_sig = kexec_kernel_verify_pe_sig, #endif };include/linux/kexec.h +7
-0@@ -19,6 +19,7 @@#include <asm/io.h> #include <uapi/linux/kexec.h> +#include <linux/verification.h> /* Location of a reserved region to hold the crash kernel. */ @@ -202,6 +203,12 @@ int arch_kexec_apply_relocations(struct purgatory_info *pi,const Elf_Shdr *relsec, const Elf_Shdr *symtab);int arch_kimage_file_post_load_cleanup (struct kimage *image); +#ifdef CONFIG_KEXEC_SIG +#ifdef CONFIG_SIGNED_PE_FILE_VERIFICATION +int kexec_kernel_verify_pe_sig (const char *kernel, +unsigned long kernel_len); +#endif +#endif int arch_kexec_locate_mem_hole (struct kexec_buf *kbuf);extern int kexec_add_buffer (struct kexec_buf *kbuf);kernel/kexec_file.c +17
-0@@ -165,6 +165,23 @@ void kimage_file_post_load_cleanup(struct kimage *image) }#ifdef CONFIG_KEXEC_SIG +#ifdef CONFIG_SIGNED_PE_FILE_VERIFICATION +int kexec_kernel_verify_pe_sig (const char *kernel,unsigned long kernel_len) +{ +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 +static int kexec_image_verify_sig (struct kimage *image,void *buf,unsigned long buf_len) {Signature · 1 line
2.34.1
Re: [PATCH v6 2/4] kexec, KEYS: make the code in bzImage64_verify_sig generic
Quoted 10 lines · Baoquan He
Quoted 9 lines · Coiby Xu
commit
278311e417be("kexec, KEYS: Make use of platform keyring for signature verify") adds platform keyring support on x86 kexec but not arm64.The code in
bzImage64_verify_sigmakes use of system keyrings including .buitin_trusted_keys, .secondary_trusted_keys and .platform keyring to verify signed kernel image as PE file. Make it generic so bothx86_64and arm64 can use it.
Quoted 5 lines
Quoted 1 line
Fixes 278311e417be ("kexec, KEYS: Make use of platform keyring for signature verify")Will the code in
bzImage64_verify_siggeneric not being genric cause any issue? Asking this because I don't get why making code generic need add 'Fixes' tag.
Thanks for raising this question! This Fixes tag is for the problem as described in the 1st paragraph of the commit message and making the code generic is the solution. But if I misuse the Fixes tag, I can drop it.
Quoted 112 lines
Quoted 111 lines
Cc kexec at lists.infradead.orgCc keyrings at vger.kernel.orgCc linux-security-module at vger.kernel.orgCc stable at kernel.orgReviewed-by Michal Suchanek <[email protected]>Signed-off-by Coiby Xu <[email protected]>--- arch/x86/kernel/kexec-bzimage64.c | 20 +------------------- include/linux/kexec.h | 7 +++++++ kernel/kexec_file.c | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 19 deletions(-)arch/x86/kernel/kexec-bzimage64.c +1
-19@@ -17,7 +17,6 @@#include <linux/kernel.h> #include <linux/mm.h> #include <linux/efi.h> -#include <linux/verification.h> #include <asm/bootparam.h> #include <asm/setup.h> @@ -528,28 +527,11 @@ static int bzImage64_cleanup(void *loader_data)return 0 ; } -#ifdef CONFIG_KEXEC_BZIMAGE_VERIFY_SIG -static int bzImage64_verify_sig (const char *kernel,unsigned long kernel_len) -{ -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 -const struct kexec_file_ops kexec_bzImage64_ops = { .probe = bzImage64_probe, .load = bzImage64_load, .cleanup = bzImage64_cleanup, #ifdef CONFIG_KEXEC_BZIMAGE_VERIFY_SIG - .verify_sig = bzImage64_verify_sig, + .verify_sig = kexec_kernel_verify_pe_sig, #endif };include/linux/kexec.h +7
-0@@ -19,6 +19,7 @@#include <asm/io.h> #include <uapi/linux/kexec.h> +#include <linux/verification.h> /* Location of a reserved region to hold the crash kernel. */ @@ -202,6 +203,12 @@ int arch_kexec_apply_relocations(struct purgatory_info *pi,const Elf_Shdr *relsec, const Elf_Shdr *symtab);int arch_kimage_file_post_load_cleanup (struct kimage *image); +#ifdef CONFIG_KEXEC_SIG +#ifdef CONFIG_SIGNED_PE_FILE_VERIFICATION +int kexec_kernel_verify_pe_sig (const char *kernel, +unsigned long kernel_len); +#endif +#endif int arch_kexec_locate_mem_hole (struct kexec_buf *kbuf);extern int kexec_add_buffer (struct kexec_buf *kbuf);kernel/kexec_file.c +17
-1@@ -165,6 +165,23 @@ void kimage_file_post_load_cleanup(struct kimage *image) }#ifdef CONFIG_KEXEC_SIG +#ifdef CONFIG_SIGNED_PE_FILE_VERIFICATION +int kexec_kernel_verify_pe_sig (const char *kernel,unsigned long kernel_len) +{ +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 +static int kexec_image_verify_sig (struct kimage *image,void *buf,unsigned long buf_len) { --2.34.1
Signature · 2 lines
Best regards, Coiby
PATCH v6 3/4 arm64: kexec_file: use more system keyrings to verify kernel image signature
In reply to Coiby XuCurrently, a problem faced by arm64 is if a kernel image is signed by a MOK key, loading it via the kexec_file_load() system call would be rejected with the error "Lockdown: kexec: kexec of unsigned images is restricted; see man kernel_lockdown.7".
This happens because image_verify_sig uses only the primary keyring that contains only kernel built-in keys to verify the kexec image.
This patch allows to verify arm64 kernel image signature using not only .builtin_trusted_keys but also .platform and .secondary_trusted_keys keyring.
--- arch/arm64/kernel/kexec_image.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)
arch/arm64/kernel/kexec_image.c +1 -10
@@ -14,7 +14,6 @@#include <linux/kexec.h> #include <linux/pe.h> #include <linux/string.h> -#include <linux/verification.h> #include <asm/byteorder.h> #include <asm/cpufeature.h> #include <asm/image.h>
@@ -130,18 +129,10 @@ static void *image_load(struct kimage *image,return NULL ; } -#ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG -static int image_verify_sig (const char *kernel,unsigned long kernel_len) -{ -return verify_pefile_signature (kernel, kernel_len,NULL , -VERIFYING_KEXEC_PE_SIGNATURE ); -} -#endif -const struct kexec_file_ops kexec_image_ops = { .probe = image_probe, .load = image_load, #ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG - .verify_sig = image_verify_sig, + .verify_sig = kexec_kernel_verify_pe_sig, #endif };
Signature · 1 line
2.34.1
Re: [PATCH v6 3/4] arm64: kexec_file: use more system keyrings to verify kernel image signature
Quoted 5 lines · Coiby Xu
Currently, a problem faced by arm64 is if a kernel image is signed by a MOK key, loading it via the
kexec_file_load()system call would be rejected with the error "Lockdown: kexec: kexec of unsigned images is restricted; see man kernel_lockdown.7".
Quoted 8 lines
This happens because
image_verify_siguses only the primary keyring that contains only kernel built-in keys to verify the kexec image.This patch allows to verify arm64 kernel image signature using not only .builtin_trusted_keys but also .platform and .secondary_trusted_keys keyring.
Fixes 732b7b93d849 ("arm64: kexec_file: add kernel signature verification support")
Cc stable?
Otherwise, LGTM,
Quoted 48 lines
Cc kexec at lists.infradead.orgCc keyrings at vger.kernel.orgCc linux-security-module at vger.kernel.orgCc stable at kernel.orgCo-developed-by Michal Suchanek <[email protected]>Signed-off-by Michal Suchanek <[email protected]>Acked-by Will Deacon <[email protected]>Signed-off-by Coiby Xu <[email protected]>--- arch/arm64/kernel/kexec_image.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)arch/arm64/kernel/kexec_image.c +1
-10@@ -14,7 +14,6 @@#include <linux/kexec.h> #include <linux/pe.h> #include <linux/string.h> -#include <linux/verification.h> #include <asm/byteorder.h> #include <asm/cpufeature.h> #include <asm/image.h> @@ -130,18 +129,10 @@ static void *image_load(struct kimage *image,return NULL ; } -#ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG -static int image_verify_sig (const char *kernel,unsigned long kernel_len) -{ -return verify_pefile_signature (kernel, kernel_len,NULL , -VERIFYING_KEXEC_PE_SIGNATURE ); -} -#endif -const struct kexec_file_ops kexec_image_ops = { .probe = image_probe, .load = image_load, #ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG - .verify_sig = image_verify_sig, + .verify_sig = kexec_kernel_verify_pe_sig, #endif };Signature · 1 line
2.34.1
Re: [PATCH v6 3/4] arm64: kexec_file: use more system keyrings to verify kernel image signature
Quoted 9 lines · Baoquan He
Quoted 8 lines · Coiby Xu
Currently, a problem faced by arm64 is if a kernel image is signed by a MOK key, loading it via the
kexec_file_load()system call would be rejected with the error "Lockdown: kexec: kexec of unsigned images is restricted; see man kernel_lockdown.7".This happens because
image_verify_siguses only the primary keyring that contains only kernel built-in keys to verify the kexec image.
Quoted 7 lines
Quoted 5 lines
This patch allows to verify arm64 kernel image signature using not only .builtin_trusted_keys but also .platform and .secondary_trusted_keys keyring.
Fixes 732b7b93d849 ("arm64: kexec_file: add kernel signature verification support")Cc stable?
Thanks for the reminder! I've added "Cc stable at kernel.org". But it seems I should Cc stable at vger.kernel.org instead.
Quoted 54 lines
Otherwise, LGTM,
Acked-by Baoquan He <[email protected]>Quoted 48 lines
Cc kexec at lists.infradead.orgCc keyrings at vger.kernel.orgCc linux-security-module at vger.kernel.orgCc stable at kernel.orgCo-developed-by Michal Suchanek <[email protected]>Signed-off-by Michal Suchanek <[email protected]>Acked-by Will Deacon <[email protected]>Signed-off-by Coiby Xu <[email protected]>--- arch/arm64/kernel/kexec_image.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)arch/arm64/kernel/kexec_image.c +1
-11@@ -14,7 +14,6 @@#include <linux/kexec.h> #include <linux/pe.h> #include <linux/string.h> -#include <linux/verification.h> #include <asm/byteorder.h> #include <asm/cpufeature.h> #include <asm/image.h> @@ -130,18 +129,10 @@ static void *image_load(struct kimage *image,return NULL ; } -#ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG -static int image_verify_sig (const char *kernel,unsigned long kernel_len) -{ -return verify_pefile_signature (kernel, kernel_len,NULL , -VERIFYING_KEXEC_PE_SIGNATURE ); -} -#endif -const struct kexec_file_ops kexec_image_ops = { .probe = image_probe, .load = image_load, #ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG - .verify_sig = image_verify_sig, + .verify_sig = kexec_kernel_verify_pe_sig, #endif }; --2.34.1
Signature · 2 lines
Best regards, Coiby
PATCH v6 4/4 kexec, KEYS, s390: Make use of built-in and secondary keyring for signature verification
In reply to Coiby XuA non-text attachment was scrubbed...
Name: not available
Type: application/octet-stream
Size: 2160 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/kexec/attachments/20220414/3510b445/attachment.obj>
Re: [PATCH v6 4/4] kexec, KEYS, s390: Make use of built-in and secondary keyring for signature verification
Quoted 9 lines · Coiby Xu
From: Michal Suchanek <[email protected]>
commit
e23a8020ce4e("s390/kexec_file: Signature verification prototype") adds support forKEXEC_SIGverification with keys from platform keyring but the built-in keys and secondary keyring are not used.Add support for the built-in keys and secondary keyring as x86 does.
Fixes e23a8020ce4e ("s390/kexec_file: Signature verification prototype")
Should Cc stable kernel?
Otherwise, LGTM,
Quoted 52 lines
Cc Philipp Rudo <[email protected]>Cc kexec at lists.infradead.orgCc keyrings at vger.kernel.orgCc linux-security-module at vger.kernel.orgCc stable at kernel.orgSigned-off-by Michal Suchanek <[email protected]>Reviewed-by "Lee, Chun-Yi" <[email protected]>Signed-off-by Coiby Xu <[email protected]>--- arch/s390/kernel/machine_kexec_file.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)arch/s390/kernel/machine_kexec_file.c +13
-5@@ -31,6 +31,7 @@ int s390_verify_sig(const char *kernel, unsigned long kernel_len)const unsigned long marker_len =sizeof (MODULE_SIG_STRING ) -1 ;struct module_signature *ms;unsigned long sig_len; +int ret;/* Skip signature verification when not secure IPLed. */ if (!ipl_secure_flag)@@ -65,11 +66,18 @@ int s390_verify_sig(const char *kernel, unsigned long kernel_len) return -EBADMSG; } -return verify_pkcs7_signature (kernel, kernel_len, - kernel + kernel_len, sig_len, -VERIFY_USE_PLATFORM_KEYRING , -VERIFYING_MODULE_SIGNATURE , -NULL ,NULL ); + ret =verify_pkcs7_signature (kernel, kernel_len, + kernel + kernel_len, sig_len, +VERIFY_USE_SECONDARY_KEYRING , +VERIFYING_MODULE_SIGNATURE , +NULL ,NULL ); +if (ret == -ENOKEY &&IS_ENABLED (CONFIG_INTEGRITY_PLATFORM_KEYRING )) + ret =verify_pkcs7_signature (kernel, kernel_len, + kernel + kernel_len, sig_len, +VERIFY_USE_PLATFORM_KEYRING , +VERIFYING_MODULE_SIGNATURE , +NULL ,NULL ); +return ret; }#endif /* CONFIG_KEXEC_SIG */ Signature · 1 line
2.34.1