From: sashiko-bot@kernel.org
To: "Jinjie Ruan" <ruanjinjie@huawei.com>
Cc: devicetree@vger.kernel.org, conor+dt@kernel.org, robh@kernel.org
Subject: Re: [PATCH v16 05/10] x86: kexec_file: Use crash_prepare_headers() helper to simplify code
Date: Mon, 08 Jun 2026 07:47:47 +0000 [thread overview]
Message-ID: <20260608074748.58E8E1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260608073459.3119290-6-ruanjinjie@huawei.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] A Time-of-Check to Time-of-Use (TOCTOU) race condition with concurrent memory hotplug can cause an out-of-bounds array write in `prepare_elf64_ram_headers_callback()` due to a missing bounds check.
--
commit 4e1090b66ab88651797483f0d06242b9bd18b6b3
Author: Jinjie Ruan <ruanjinjie@huawei.com>
x86: kexec_file: Use crash_prepare_headers() helper to simplify code
This commit replaces x86's custom prepare_elf_headers() with the generic
crash_prepare_headers() helper. It implements the required architecture
callbacks arch_get_system_nr_ranges(), arch_crash_populate_cmem(), and
arch_crash_exclude_ranges() to manage crash memory regions.
> diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
> index cd796818d94d9..cb2ce7acfec45 100644
> --- a/arch/x86/kernel/crash.c
> +++ b/arch/x86/kernel/crash.c
[ ... ]
> -/* Prepare elf headers. Return addr and size */
> -static int prepare_elf_headers(void **addr, unsigned long *sz,
> - unsigned long *nr_mem_ranges)
> +int arch_crash_populate_cmem(struct crash_mem *cmem)
> {
> - struct crash_mem *cmem;
> - int ret;
> -
> - cmem = fill_up_crash_elf_data();
> - if (!cmem)
> - return -ENOMEM;
> -
> - ret = walk_system_ram_res(0, -1, cmem, prepare_elf64_ram_headers_callback);
> - if (ret)
> - goto out;
> -
> - /* Exclude unwanted mem ranges */
> - ret = elf_header_exclude_ranges(cmem);
> - if (ret)
> - goto out;
> -
> - /* Return the computed number of memory ranges, for hotplug usage */
> - *nr_mem_ranges = cmem->nr_ranges;
> -
> - /* By default prepare 64bit headers */
> - ret = crash_prepare_elf64_headers(cmem, IS_ENABLED(CONFIG_X86_64), addr, sz);
> -
> -out:
> - vfree(cmem);
> - return ret;
> + return walk_system_ram_res(0, -1, cmem, prepare_elf64_ram_headers_callback);
> }
[Severity: High]
This is a pre-existing issue, but can this sequence lead to an out-of-bounds
write during concurrent memory hotplug?
The generic crash_prepare_headers() performs two lockless passes over system
RAM resources:
1. arch_get_system_nr_ranges() counts the regions to allocate cmem.
2. arch_crash_populate_cmem() populates them using walk_system_ram_res()
and prepare_elf64_ram_headers_callback().
Since sys_kexec_file_load() does not hold mem_hotplug_lock, and
walk_system_ram_res() temporarily drops resource_lock between iterations,
concurrent memory hot-add operations can insert new memory regions between or
during these passes.
If the number of dynamically added RAM regions exceeds the reserved padding,
the second pass will encounter more regions than cmem->max_nr_ranges.
prepare_elf64_ram_headers_callback() currently does not verify bounds before
appending new regions:
cmem->ranges[cmem->nr_ranges].start = res->start;
cmem->ranges[cmem->nr_ranges].end = res->end;
cmem->nr_ranges++;
Could this allow an out-of-bounds array write on the vmalloc heap if enough
memory ranges are hotplugged concurrently? Would it make sense to add a bounds
check to prepare_elf64_ram_headers_callback() to prevent exceeding
cmem->max_nr_ranges, or perhaps hold the memory hotplug lock across the passes?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260608073459.3119290-1-ruanjinjie@huawei.com?part=5
next prev parent reply other threads:[~2026-06-08 7:47 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-08 7:34 [PATCH v16 00/10] arm64/riscv: Add support for crashkernel CMA reservation Jinjie Ruan
2026-06-08 7:34 ` [PATCH v16 01/10] riscv: kexec_file: Fix crashk_low_res not exclude bug Jinjie Ruan
2026-06-08 7:48 ` sashiko-bot
2026-06-08 8:05 ` Jinjie Ruan
2026-06-08 7:34 ` [PATCH v16 02/10] powerpc/crash: sort crash memory ranges before preparing elfcorehdr Jinjie Ruan
2026-06-08 7:34 ` [PATCH v16 03/10] crash: Add crash_prepare_headers() to exclude crash kernel memory Jinjie Ruan
2026-06-08 7:34 ` [PATCH v16 04/10] arm64: kexec_file: Use crash_prepare_headers() helper to simplify code Jinjie Ruan
2026-06-08 7:56 ` sashiko-bot
2026-06-08 8:07 ` Jinjie Ruan
2026-06-08 7:34 ` [PATCH v16 05/10] x86: " Jinjie Ruan
2026-06-08 7:47 ` sashiko-bot [this message]
2026-06-08 8:21 ` Jinjie Ruan
2026-06-08 7:34 ` [PATCH v16 06/10] riscv: " Jinjie Ruan
2026-06-08 7:54 ` sashiko-bot
2026-06-08 8:08 ` Jinjie Ruan
2026-06-08 7:34 ` [PATCH v16 07/10] LoongArch: " Jinjie Ruan
2026-06-08 7:52 ` sashiko-bot
2026-06-08 8:23 ` Jinjie Ruan
2026-06-08 7:34 ` [PATCH v16 08/10] powerpc/kexec_file: Use crash_exclude_core_ranges() helper Jinjie Ruan
2026-06-08 8:48 ` Breno Leitao
2026-06-08 7:34 ` [PATCH v16 09/10] arm64: kexec_file: Add support for crashkernel CMA reservation Jinjie Ruan
2026-06-08 7:34 ` [PATCH v16 10/10] riscv: " Jinjie Ruan
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=20260608074748.58E8E1F00893@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox