use more system keyrings to verify kdump kernel image signature
Subsystems (5)
cover use more system keyrings to verify 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.
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 | 15 +++++++++++++++ 4 files changed, 20 insertions(+), 15 deletions(-)
Signature · 7 lines
2.33.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH 1/2 kexec, KEYS: make the code in bzImage64_verify_sig public
From: Coiby Xu <[email protected]>
The 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. Move it to a public function.
--- arch/x86/kernel/kexec-bzimage64.c | 13 +------------ include/linux/kexec.h | 3 +++ kernel/kexec_file.c | 15 +++++++++++++++ 3 files changed, 19 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 +15 -0
@@ -106,6 +106,21 @@ int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, {return kexec_image_verify_sig_default (image, buf, buf_len); } + +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 /*
Signature · 7 lines
2.33.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH 2/2 arm64: kexec_file: use more system keyrings to verify kernel image signature
In reply to Coiby XuFrom: Coiby Xu <[email protected]>
This 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 · 7 lines
2.33.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 2/2] arm64: kexec_file: use more system keyrings to verify kernel image signature
Quoted 23 lines · Coiby Xu
From: Coiby Xu <[email protected]>
This allows to verify arm64 kernel image signature using not only .builtin_trusted_keys but also .secondary_trusted_keys and .platform keyring.
Signed-off-by Coiby Xu <[email protected]>--- arch/arm64/kernel/kexec_image.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)arch/arm64/kernel/kexec_image.c +0
-1@@ -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>
arch/arm64/kernel/kexec_image.c static void *image_load(struct kimage *image, · line 135
Quoted 6 lines
arch/arm64/kernel/kexec_image.c +1
-2@@ -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);
I'm fine with this in principle, but it looks like the first patch is the important one.
So for the arm64 bit:
Will
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 1/2] kexec, KEYS: make the code in bzImage64_verify_sig public
In reply to Coiby XuHi Coiby,
Quoted 78 lines · Coiby Xu
From: Coiby Xu <[email protected]>
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. Move it to a public function.Signed-off-by Coiby Xu <[email protected]>--- arch/x86/kernel/kexec-bzimage64.c | 13 +------------ include/linux/kexec.h | 3 +++ kernel/kexec_file.c | 15 +++++++++++++++ 3 files changed, 19 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 +5
-0@@ -106,6 +106,21 @@ int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, {return kexec_image_verify_sig_default (image, buf, buf_len); } + +int arch_kexec_kernel_verify_pe_sig (const char *kernel,unsigned long kernel_len) +{ +int ret; +
kernel/kexec_file.c int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, · line 123
Quoted 10 lines
kernel/kexec_file.c +10
-0+ 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; +}
Since the function is moved as generic code, the kconfig option CONFIG_KEXEC_BZIMAGE_VERIFY_SIG can be removed.
Instead a CONFIG_KEXEC_PEFILE_VERIFY_SIG can be added so that it does not need to be compiled for only platform which support UEFI pefile signature verification. And the related arch kexec_file kconfig can just select it.
Coiby, can you try above?
Quoted 13 lines
kernel/kexec_file.c +0
-0#endif /* Signature · 7 lines
2.33.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Thanks
Dave
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 1/2] kexec, KEYS: make the code in bzImage64_verify_sig public
Quoted 94 lines · Dave Young
Hi Coiby,
Quoted 78 lines · Coiby Xu
From: Coiby Xu <[email protected]>
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. Move it to a public function.Signed-off-by Coiby Xu <[email protected]>--- arch/x86/kernel/kexec-bzimage64.c | 13 +------------ include/linux/kexec.h | 3 +++ kernel/kexec_file.c | 15 +++++++++++++++ 3 files changed, 19 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 +5
-0@@ -106,6 +106,21 @@ int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, {return kexec_image_verify_sig_default (image, buf, buf_len); } + +int arch_kexec_kernel_verify_pe_sig (const char *kernel,unsigned long kernel_len) +{ +int ret; +kernel/kexec_file.c int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, · line 123
Quoted 10 lines
kernel/kexec_file.c +10
-0+ 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; +}Since the function is moved as generic code, the kconfig option
CONFIG_KEXEC_BZIMAGE_VERIFY_SIGcan be removed.
Quoted 2 lines
Instead a
CONFIG_KEXEC_PEFILE_VERIFY_SIGcan be added so that it does not need to be compiled for only platform which support UEFI pefile
Fix the sick sentence: I means only to compile for x86_64 and arm64..
Quoted 19 lines
signature verification. And the related arch
kexec_filekconfig can just select it.Coiby, can you try above?
Quoted 13 lines
kernel/kexec_file.c +0
-0#endif /* Signature · 7 lines
2.33.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Quoted 3 lines
Thanks
Dave
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 1/2] kexec, KEYS: make the code in bzImage64_verify_sig public
In reply to Dave YoungHi Dave,
Quoted 95 lines · Dave Young
Hi Coiby,
Quoted 78 lines · Coiby Xu
From: Coiby Xu <[email protected]>
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. Move it to a public function.Signed-off-by Coiby Xu <[email protected]>--- arch/x86/kernel/kexec-bzimage64.c | 13 +------------ include/linux/kexec.h | 3 +++ kernel/kexec_file.c | 15 +++++++++++++++ 3 files changed, 19 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 +5
-0@@ -106,6 +106,21 @@ int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, {return kexec_image_verify_sig_default (image, buf, buf_len); } + +int arch_kexec_kernel_verify_pe_sig (const char *kernel,unsigned long kernel_len) +{ +int ret; +kernel/kexec_file.c int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, · line 123
Quoted 10 lines
kernel/kexec_file.c +10
-0+ 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; +}Since the function is moved as generic code, the kconfig option
CONFIG_KEXEC_BZIMAGE_VERIFY_SIGcan be removed.
Quoted 4 lines
Instead a
CONFIG_KEXEC_PEFILE_VERIFY_SIGcan be added so that it does not need to be compiled for only platform which support UEFI pefile signature verification. And the related archkexec_filekconfig can just select it.
Thanks for the suggestion! I notice KEXEC_BZIMAGE_VERIFY_SIG depends on SIGNED_PE_FILE_VERIFICATION and selects SYSTEM_TRUSTED_KEYRING. So maybe SIGNED_PE_FILE_VERIFICATION could do the job of CONFIG_KEXEC_PEFILE_VERIFY_SIG. And arch/arm64/Kconfig also have KEXEC_IMAGE_VERIFY_SIG. So maybe it's better we don't keep CONFIG_KEXEC_BZIMAGE_VERIFY_SIG.
Quoted 20 lines
Coiby, can you try above?
Quoted 7 lines
kernel/kexec_file.c +0
-1#endif /* -- 2.33.0
Quoted 6 lines
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexecThanks
Dave
Signature · 7 lines
Best regards, Coiby _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec