From: Cong Wang <xiyou.wangcong@gmail.com>
To: linux-kernel@vger.kernel.org, Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Andrew Morton <akpm@linux-foundation.org>,
Baoquan He <baoquan.he@linux.dev>,
Mike Rapoport <rppt@kernel.org>
Cc: Alexandre Ghiti <alex@ghiti.fr>,
linux-riscv@lists.infradead.org, kexec@lists.infradead.org,
Cong Wang <cwang@multikernel.io>
Subject: [PATCH] riscv: kexec_file: Verify the signature of Image files
Date: Tue, 17 Nov 2026 17:37:29 -0800 [thread overview]
Message-ID: <20261118013729.576325-1-xiyou.wangcong@gmail.com> (raw)
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
reply other threads:[~2026-11-18 1:37 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261118013729.576325-1-xiyou.wangcong@gmail.com \
--to=xiyou.wangcong@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=baoquan.he@linux.dev \
--cc=cwang@multikernel.io \
--cc=kexec@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=rppt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®