Re: [PATCH] riscv: kexec_file: Verify the signature of Image files

From: Mike Rapoport

Date: Wed Nov 18 2026 - 11:23:34 EST


On Tue, Nov 17, 2026 at 05:37:29PM -0800, Cong Wang wrote:
> From: Cong Wang <cwang@xxxxxxxxxxxxxx>
>
> 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@xxxxxxxxxxxxxx>
> ---
> 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

Hmm, looks like we already have plenty of those. I believe before enabling
those on riscv we need something like this: