From: sashiko-bot@kernel.org
To: fangyu.yu@linux.alibaba.com
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v3 2/9] riscv: kexec: Bound FDT search by source buffer size, not destination
Date: Thu, 04 Jun 2026 13:37:59 +0000 [thread overview]
Message-ID: <20260604133759.AC3CC1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260604132418.15725-3-fangyu.yu@linux.alibaba.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [Critical] In `kexec_file_load`, an attacker can bypass Secure Boot restrictions by providing an initrd that starts with a forged FDT header, overwriting the kernel-constructed FDT.
- [High] The check `if (!internal->fdt_addr)` falsely rejects a valid FDT if it is placed at physical address 0x0.
--
commit 0ee8b0469cc5460085b86fc5826ddc9fa0522c40
Author: Fangyu Yu <fangyu.yu@linux.alibaba.com>
riscv: kexec: Bound FDT search by source buffer size, not destination
This commit changes the FDT size check in machine_kexec_prepare() to use
bufsz instead of memsz. This correctly bounds the read to the provided
source buffer, preventing out-of-bounds reads and potential kernel faults
when a segment is padded with zeros at its destination.
> diff --git a/arch/riscv/kernel/machine_kexec.c b/arch/riscv/kernel/machine_kexec.c
> index ea6794c9f4c2d..e6e179cffc447 100644
> --- a/arch/riscv/kernel/machine_kexec.c
> +++ b/arch/riscv/kernel/machine_kexec.c
> @@ -38,21 +38,21 @@ machine_kexec_prepare(struct kimage *image)
>
> /* Find the Flattened Device Tree and save its physical address */
> for (i = 0; i < image->nr_segments; i++) {
> - if (image->segment[i].memsz <= sizeof(fdt))
> + if (image->segment[i].bufsz < sizeof(fdt))
> continue;
>
> if (image->file_mode)
> memcpy(&fdt, image->segment[i].buf, sizeof(fdt));
> else if (copy_from_user(&fdt, image->segment[i].buf, sizeof(fdt)))
> continue;
>
> if (fdt_check_header(&fdt))
> continue;
>
> internal->fdt_addr = (unsigned long) image->segment[i].mem;
> break;
[Severity: Critical]
This is a pre-existing issue, but does this blind search loop in
machine_kexec_prepare() allow a user-provided segment to spoof the FDT?
For kexec_file_load, architecture-specific loading adds the user-provided
initrd segment before the kernel-constructed FDT segment. If a malicious
initrd starts with FDT magic bytes, it seems this loop would accept it and
break early.
Would this cause the next kernel to boot using an attacker-controlled FDT
instead of the kernel-generated one? This could allow injection of arbitrary
bootargs (like init=/bin/sh module.sig_enforce=0) and bypass Secure Boot
restrictions.
> }
>
> if (!internal->fdt_addr) {
[Severity: High]
This is a pre-existing issue, but could the !internal->fdt_addr check in
machine_kexec_prepare() incorrectly reject a valid FDT if it is placed at
physical address 0x0?
On RISC-V platforms where the physical memory base starts at 0x0 (such as
the T-Head TH1520), the FDT segment can legitimately be loaded at physical
address 0x0. The search loop will correctly set internal->fdt_addr = 0, but
this check would treat it as an error and return -EINVAL.
Is there a risk that this false rejection breaks kexec functionality on
platforms where memory starts at 0x0?
> pr_err("Device tree not included in the provided image\n");
> return -EINVAL;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260604132418.15725-1-fangyu.yu@linux.alibaba.com?part=2
next prev parent reply other threads:[~2026-06-04 13:37 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-04 13:24 [PATCH v3 0/9] riscv: kexec: Make kexec/kdump robust under VS-mode fangyu.yu
2026-06-04 13:24 ` fangyu.yu
2026-06-04 13:24 ` fangyu.yu
2026-06-04 13:24 ` [PATCH v3 1/9] riscv: kexec: Reset executable bit on the control code page in cleanup fangyu.yu
2026-06-04 13:24 ` fangyu.yu
2026-06-04 13:24 ` fangyu.yu
2026-06-04 13:24 ` [PATCH v3 2/9] riscv: kexec: Bound FDT search by source buffer size, not destination fangyu.yu
2026-06-04 13:24 ` fangyu.yu
2026-06-04 13:24 ` fangyu.yu
2026-06-04 13:37 ` sashiko-bot [this message]
2026-06-04 13:24 ` [PATCH v3 3/9] riscv: Add kexec trampoline text section to vmlinux.lds.S fangyu.yu
2026-06-04 13:24 ` fangyu.yu
2026-06-04 13:24 ` fangyu.yu
2026-06-04 13:24 ` [PATCH v3 4/9] riscv: kexec: Place norelocate trampoline into .kexec.tramp.text fangyu.yu
2026-06-04 13:24 ` fangyu.yu
2026-06-04 13:24 ` fangyu.yu
2026-06-04 13:24 ` [PATCH v3 5/9] riscv: kexec: Build trampoline page tables for crash kernel entry fangyu.yu
2026-06-04 13:24 ` fangyu.yu
2026-06-04 13:24 ` fangyu.yu
2026-06-04 13:24 ` [PATCH v3 6/9] riscv: kexec: Switch to trampoline page table before norelocate fangyu.yu
2026-06-04 13:24 ` fangyu.yu
2026-06-04 13:24 ` fangyu.yu
2026-06-04 13:40 ` sashiko-bot
2026-06-04 13:24 ` [PATCH v3 7/9] riscv: kexec: Always build the trampoline page table fangyu.yu
2026-06-04 13:24 ` fangyu.yu
2026-06-04 13:24 ` fangyu.yu
2026-06-04 13:24 ` [PATCH v3 8/9] riscv: kexec: Add the relocate-trampoline wrapper fangyu.yu
2026-06-04 13:24 ` fangyu.yu
2026-06-04 13:24 ` fangyu.yu
2026-06-04 13:46 ` sashiko-bot
2026-06-04 13:24 ` [PATCH v3 9/9] riscv: kexec: Route normal kexec through the trampoline page table fangyu.yu
2026-06-04 13:24 ` fangyu.yu
2026-06-04 13:24 ` fangyu.yu
2026-06-04 13:36 ` sashiko-bot
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=20260604133759.AC3CC1F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=fangyu.yu@linux.alibaba.com \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.