The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] riscv: kexec_file: Verify the signature of Image files
@ 2026-11-18  1:37 Cong Wang
  2026-11-18 16:23 ` Mike Rapoport
  0 siblings, 1 reply; 2+ messages in thread
From: Cong Wang @ 2026-11-18  1:37 UTC (permalink / raw)
  To: linux-kernel, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Andrew Morton, Baoquan He, Mike Rapoport
  Cc: Alexandre Ghiti, linux-riscv, kexec, Cong Wang

From: Cong Wang <cwang@multikernel.io>

kexec_file_load() on riscv cannot check that the kernel it is given is
trusted. KEXEC_SIG is not selectable, so a kernel that is locked down
has to refuse kexec_file_load() altogether, and there is no way to
restrict it to kernels signed with a trusted key.

With CONFIG_EFI the riscv Image is a PE file, the same as on arm64, and
can carry an Authenticode signature added by tools such as sbsign.
Verify it with kexec_kernel_verify_pe_sig(), as arm64 does, and let
riscv select KEXEC_SIG, KEXEC_SIG_FORCE and KEXEC_IMAGE_VERIFY_SIG.

KEXEC_IMAGE_VERIFY_SIG is no longer specific to arm64, so drop "(ARM)"
from its prompt.

The ELF loader has no signature format, so a vmlinux is rejected
whenever signature verification is enforced.

Tested on QEMU virt with KEXEC_SIG_FORCE=y and a test certificate in
the built-in trusted keyring:

  signed Image                    loads and boots
  unsigned Image                  -ENODATA
  signed Image, one byte flipped  -EKEYREJECTED
  Image signed by an unknown key  -ENOKEY
  vmlinux                         -EKEYREJECTED

This is needed by multikernel, which loads its kernels with kexec_file,
but nothing here depends on it: it applies to any kexec_file_load() user.

Signed-off-by: Cong Wang <cwang@multikernel.io>
---
 arch/riscv/Kconfig              | 12 ++++++++++++
 arch/riscv/kernel/kexec_image.c |  3 +++
 kernel/Kconfig.kexec            |  2 +-
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index e7891a2a89da..f47bca71aa35 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -1122,6 +1122,18 @@ config ARCH_SELECTS_KEXEC_FILE
 	select HAVE_IMA_KEXEC if IMA
 	select KEXEC_ELF
 
+config ARCH_SUPPORTS_KEXEC_SIG
+	def_bool y
+
+config ARCH_SUPPORTS_KEXEC_SIG_FORCE
+	def_bool y
+
+config ARCH_SUPPORTS_KEXEC_IMAGE_VERIFY_SIG
+	def_bool y
+
+config ARCH_DEFAULT_KEXEC_IMAGE_VERIFY_SIG
+	def_bool y
+
 config ARCH_SUPPORTS_KEXEC_PURGATORY
 	def_bool ARCH_SUPPORTS_KEXEC_FILE
 
diff --git a/arch/riscv/kernel/kexec_image.c b/arch/riscv/kernel/kexec_image.c
index 963a25f5b55b..b1cec911adc5 100644
--- a/arch/riscv/kernel/kexec_image.c
+++ b/arch/riscv/kernel/kexec_image.c
@@ -93,4 +93,7 @@ static void *image_load(struct kimage *image,
 const struct kexec_file_ops image_kexec_ops = {
 	.probe = image_probe,
 	.load = image_load,
+#ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG
+	.verify_sig = kexec_kernel_verify_pe_sig,
+#endif
 };
diff --git a/kernel/Kconfig.kexec b/kernel/Kconfig.kexec
index a97ed9605602..24c28978f21b 100644
--- a/kernel/Kconfig.kexec
+++ b/kernel/Kconfig.kexec
@@ -69,7 +69,7 @@ config KEXEC_SIG_FORCE
 	  the kexec_file_load() syscall.
 
 config KEXEC_IMAGE_VERIFY_SIG
-	bool "Enable Image signature verification support (ARM)"
+	bool "Enable Image signature verification support"
 	default ARCH_DEFAULT_KEXEC_IMAGE_VERIFY_SIG
 	depends on ARCH_SUPPORTS_KEXEC_IMAGE_VERIFY_SIG
 	depends on KEXEC_SIG
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-18 16:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18  1:37 [PATCH] riscv: kexec_file: Verify the signature of Image files Cong Wang
2026-11-18 16:23 ` Mike Rapoport

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox