From: sashiko-bot@kernel.org
To: "Jinjie Ruan" <ruanjinjie@huawei.com>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH v17 10/10] riscv: kexec_file: Add support for crashkernel CMA reservation
Date: Mon, 29 Jun 2026 11:33:54 +0000 [thread overview]
Message-ID: <20260629113355.099941F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260629094746.191843-11-ruanjinjie@huawei.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing bounds check in `prepare_elf64_ram_headers_callback` can lead to an out-of-bounds heap write if memory is hot-plugged concurrently.
--
commit 12b2d1ca4895e26a575347f3f6f5b7e59957f99a
Author: Jinjie Ruan <ruanjinjie@huawei.com>
riscv: kexec_file: Add support for crashkernel CMA reservation
This commit adds CMA support for kdump crashkernel reservation on RISC-V.
It parses CMA reservation parameters, allocates the memory dynamically, and
handles exclusion of these ranges from the crash kernel memory appropriately.
> diff --git a/arch/riscv/kernel/machine_kexec_file.c b/arch/riscv/kernel/machine_kexec_file.c
> index 439cbc50dfa69..85f14abceb507 100644
> --- a/arch/riscv/kernel/machine_kexec_file.c
> +++ b/arch/riscv/kernel/machine_kexec_file.c
> @@ -46,7 +46,7 @@ static int get_nr_ram_ranges_callback(struct resource *res, void *arg)
>
> unsigned int arch_get_system_nr_ranges(void)
> {
> - unsigned int nr_ranges = 2; /* For exclusion of crashkernel region */
> + unsigned int nr_ranges = 2 + crashk_cma_cnt; /* For exclusion of crashkernel region */
[Severity: High]
This is a pre-existing issue, but while modifying arch_get_system_nr_ranges(),
I noticed a potential race condition with concurrent memory hotplug.
In crash_prepare_headers(), the code counts the ranges and then allocates the
cmem array based on that count:
kernel/crash_core.c:crash_prepare_headers() {
...
max_nr_ranges = arch_get_system_nr_ranges();
if (!max_nr_ranges)
return -ENOMEM;
cmem = alloc_cmem(max_nr_ranges);
if (!cmem)
return -ENOMEM;
ret = arch_crash_populate_cmem(cmem);
...
}
Neither kexec_lock nor resource_lock appears to be held to prevent the system
RAM resource tree from being modified between the counting phase and the
population phase. If a memory hotplug event inserts a new memory range during
this window, the second traversal of the resource tree will encounter it.
When that happens, could prepare_elf64_ram_headers_callback() write past the
end of the allocated cmem array?
arch/riscv/kernel/machine_kexec_file.c:prepare_elf64_ram_headers_callback() {
...
cmem->ranges[cmem->nr_ranges].start = res->start;
cmem->ranges[cmem->nr_ranges].end = res->end;
cmem->nr_ranges++;
...
}
Does this callback need a bounds check against cmem->max_nr_ranges to prevent
an out-of-bounds heap write?
>
> walk_system_ram_res(0, -1, &nr_ranges, get_nr_ram_ranges_callback);
>
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260629094746.191843-1-ruanjinjie@huawei.com?part=10
next prev parent reply other threads:[~2026-06-29 11:33 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-29 9:47 [PATCH v17 00/10] arm64/riscv: Add support for crashkernel CMA reservation Jinjie Ruan
2026-06-29 9:47 ` Jinjie Ruan
2026-06-29 9:47 ` [PATCH v17 01/10] riscv: kexec_file: Fix crashk_low_res not exclude bug Jinjie Ruan
2026-06-29 9:47 ` Jinjie Ruan
2026-06-29 9:58 ` sashiko-bot
2026-06-29 9:47 ` [PATCH v17 02/10] powerpc/crash: sort crash memory ranges before preparing elfcorehdr Jinjie Ruan
2026-06-29 9:47 ` Jinjie Ruan
2026-06-29 9:47 ` [PATCH v17 03/10] crash: Add crash_prepare_headers() to exclude crash kernel memory Jinjie Ruan
2026-06-29 9:47 ` Jinjie Ruan
2026-06-29 10:19 ` sashiko-bot
2026-06-29 9:47 ` [PATCH v17 04/10] arm64: kexec_file: Use crash_prepare_headers() helper to simplify code Jinjie Ruan
2026-06-29 9:47 ` Jinjie Ruan
2026-06-29 10:31 ` sashiko-bot
2026-06-29 9:47 ` [PATCH v17 05/10] x86/crash: " Jinjie Ruan
2026-06-29 9:47 ` Jinjie Ruan
2026-06-29 10:41 ` sashiko-bot
2026-06-29 9:47 ` [PATCH v17 06/10] riscv: kexec_file: " Jinjie Ruan
2026-06-29 9:47 ` Jinjie Ruan
2026-06-29 10:53 ` sashiko-bot
2026-06-29 11:28 ` Guo Ren
2026-06-29 11:28 ` Guo Ren
2026-06-29 9:47 ` [PATCH v17 07/10] LoongArch: " Jinjie Ruan
2026-06-29 9:47 ` Jinjie Ruan
2026-06-29 11:06 ` sashiko-bot
2026-06-29 9:47 ` [PATCH v17 08/10] powerpc/kexec_file: Use crash_exclude_core_ranges() helper Jinjie Ruan
2026-06-29 9:47 ` Jinjie Ruan
2026-06-29 9:47 ` [PATCH v17 09/10] arm64: kexec_file: Add support for crashkernel CMA reservation Jinjie Ruan
2026-06-29 9:47 ` Jinjie Ruan
2026-06-29 9:47 ` [PATCH v17 10/10] riscv: " Jinjie Ruan
2026-06-29 9:47 ` Jinjie Ruan
2026-06-29 11:33 ` sashiko-bot [this message]
2026-06-30 15:49 ` [PATCH v17 00/10] arm64/riscv: " Mike Rapoport
2026-06-30 15:49 ` Mike Rapoport
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=20260629113355.099941F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=robh@kernel.org \
--cc=ruanjinjie@huawei.com \
--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.