use more system keyrings to verify arm64 kdump kernel image signature
Subsystems (5)
PATCH v2 1/2 kexec, KEYS: make the code in bzImage64_verify_sig generic
In reply to Coiby XuThe code in bzImage64_verify_sig could make 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 | 13 +------------ include/linux/kexec.h | 3 +++ kernel/kexec_file.c | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 12 deletions(-)
arch/x86/kernel/kexec-bzimage64.c +1 -12
@@ -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>
@@ -531,17 +530,7 @@ 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) { -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; +return arch_kexec_kernel_verify_pe_sig (kernel, kernel_len); }#endif
include/linux/kexec.h +3 -0
@@ -19,6 +19,7 @@#include <asm/io.h> #include <uapi/linux/kexec.h> +#include <linux/verification.h> #ifdef CONFIG_KEXEC_CORE #include <linux/list.h>
@@ -199,6 +200,8 @@ 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); +int arch_kexec_kernel_verify_pe_sig (const char *kernel, +unsigned long kernel_len);#endif int arch_kexec_locate_mem_hole (struct kexec_buf *kbuf);
kernel/kexec_file.c +17 -0
@@ -106,6 +106,23 @@ int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, {return kexec_image_verify_sig_default (image, buf, buf_len); } + +#ifdef CONFIG_SIGNED_PE_FILE_VERIFICATION +int arch_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 #endif /*
Signature · 1 line
2.31.1
PATCH v2 2/2 arm64: kexec_file: use more system keyrings to verify kernel image signature
In reply to Coiby XuThis allows to verify arm64 kernel image signature using not only .builtin_trusted_keys but also .secondary_trusted_keys and .platform keyring.
--- arch/arm64/kernel/kexec_image.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
arch/arm64/kernel/kexec_image.c +1 -3
@@ -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>
@@ -133,8 +132,7 @@ static void *image_load(struct kimage *image,#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 ); +return arch_kexec_kernel_verify_pe_sig (kernel, kernel_len); }#endif
Signature · 1 line
2.31.1
v2 cover use more system keyrings to verify arm64 kdump kernel image signature
This patch set allows arm64 to use more system keyrings to verify kdump kernel image signature by making the existing code in x64 public.
v2:
- only x86_64 and arm64 need to enable PE file signature check [Dave]
Coiby Xu (2):
kexec, KEYS: make the code in bzImage64_verify_sig public
arm64: kexec_file: use more system keyrings to verify kernel image
signature
arch/arm64/kernel/kexec_image.c | 4 +--- arch/x86/kernel/kexec-bzimage64.c | 13 +------------ include/linux/kexec.h | 3 +++ kernel/kexec_file.c | 17 +++++++++++++++++ 4 files changed, 22 insertions(+), 15 deletions(-)
Signature · 7 lines
2.31.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v2 1/2] kexec, KEYS: make the code in bzImage64_verify_sig generic
In reply to Coiby XuQuoted 4 lines · Coiby Xu
The code in
bzImage64_verify_sigcould make 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.
The naming is problematic.
At a minimum please name the new function kexec_kernel_verify_pe_sig. AKA what you named it without the "arch_" prefix. A function named with an "arch_" prefix implies that it has an architecture specific implementation.
It looks like arch_kexec_kernel_verify_sig should be killed as well as it only has one implementation in the generic code. And the code should always call kexec_image_verify_sig_default. Not that you should do that but I am pointing it out as it seems that is the bad example you are copying.
Eric
Quoted 77 lines
Signed-off-by Coiby Xu <[email protected]>--- arch/x86/kernel/kexec-bzimage64.c | 13 +------------ include/linux/kexec.h | 3 +++ kernel/kexec_file.c | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 12 deletions(-)arch/x86/kernel/kexec-bzimage64.c +1
-12@@ -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> @@ -531,17 +530,7 @@ 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) { -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; +return arch_kexec_kernel_verify_pe_sig (kernel, kernel_len); }#endif include/linux/kexec.h +3
-0@@ -19,6 +19,7 @@#include <asm/io.h> #include <uapi/linux/kexec.h> +#include <linux/verification.h> #ifdef CONFIG_KEXEC_CORE #include <linux/list.h> @@ -199,6 +200,8 @@ 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); +int arch_kexec_kernel_verify_pe_sig (const char *kernel, +unsigned long kernel_len);#endif int arch_kexec_locate_mem_hole (struct kexec_buf *kbuf);kernel/kexec_file.c +10
-0@@ -106,6 +106,23 @@ int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, {return kexec_image_verify_sig_default (image, buf, buf_len); } + +#ifdef CONFIG_SIGNED_PE_FILE_VERIFICATION +int arch_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 )) {
kernel/kexec_file.c int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, · line 128
Quoted 10 lines
kernel/kexec_file.c +7
-0+ ret =verify_pefile_signature (kernel, kernel_len, +VERIFY_USE_PLATFORM_KEYRING , +VERIFYING_KEXEC_PE_SIGNATURE ); + } +return ret; +} +#endif #endif /*
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v2 1/2] kexec, KEYS: make the code in bzImage64_verify_sig generic
Quoted 7 lines · Eric W. Biederman
Quoted 4 lines · Coiby Xu
The code in
bzImage64_verify_sigcould make 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 6 lines
The naming is problematic.
At a minimum please name the new function
kexec_kernel_verify_pe_sig. AKA what you named it without the "arch_" prefix. A function named with an "arch_" prefix implies that it has an architecture specific implementation.
Thanks for bringing up this issue and providing the fix and the explanation.
Quoted 6 lines
It looks like
arch_kexec_kernel_verify_sigshould be killed as well as it only has one implementation in the generic code. And the code should always callkexec_image_verify_sig_default. Not that you should do that but I am pointing it out as it seems that is the bad example you are copying.
Yes, you are right about it. This is a leftover issue of commit 9ec4ecef0af7790551109283ca039a7c52de343c ("kexec_file,x86,powerpc: factor out kexec_file_ops functions"),
As arch_kexec_kernel_image_{probe,load}(), arch_kimage_file_post_load_cleanup() and arch_kexec_kernel_verify_sig() are almost duplicated among architectures, they can be commonalized with an architecture-defined kexec_file_ops array. So let's factor them out.
That commit moves the architecture specific implementation of arch_kexec_kernel_verify_sig to kexec_file_ops->verify_sig. So actually arch_kexec_kernel_verify_sig should be removed. Then we rename kexec_image_verify_sig_default to kimage_validate_signature and call it in kimage_validate_signature directly. I'll include a new patch to do the clean-up work in v3.
Quoted 91 lines
Eric
Quoted 87 lines
Signed-off-by Coiby Xu <[email protected]>--- arch/x86/kernel/kexec-bzimage64.c | 13 +------------ include/linux/kexec.h | 3 +++ kernel/kexec_file.c | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 12 deletions(-)arch/x86/kernel/kexec-bzimage64.c +1
-12@@ -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> @@ -531,17 +530,7 @@ 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) { -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; +return arch_kexec_kernel_verify_pe_sig (kernel, kernel_len); }#endif include/linux/kexec.h +3
-0@@ -19,6 +19,7 @@#include <asm/io.h> #include <uapi/linux/kexec.h> +#include <linux/verification.h> #ifdef CONFIG_KEXEC_CORE #include <linux/list.h> @@ -199,6 +200,8 @@ 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); +int arch_kexec_kernel_verify_pe_sig (const char *kernel, +unsigned long kernel_len);#endif int arch_kexec_locate_mem_hole (struct kexec_buf *kbuf);kernel/kexec_file.c +17
-0@@ -106,6 +106,23 @@ int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, {return kexec_image_verify_sig_default (image, buf, buf_len); } + +#ifdef CONFIG_SIGNED_PE_FILE_VERIFICATION +int arch_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 #endif /*
Signature · 2 lines
Best regards, Coiby