Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Wandun Chen" <chenwandun1@gmail.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v4 09/10] riscv: kdump: exclude non-dumpable reserved memory regions from vmcore
Date: Tue, 30 Jun 2026 09:22:48 +0000	[thread overview]
Message-ID: <20260630092249.85B991F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260630074715.4126796-10-chenwandun1@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Concurrent memory hotplug between two `walk_system_ram_res()` calls creates a race condition leading to an out-of-bounds array write in `prepare_elf64_ram_headers_callback()`.
--

commit a4a73b4654fd97d90e65198367a18f9dc30631b2
Author: Wandun Chen <chenwandun@lixiang.com>

riscv: kdump: exclude non-dumpable reserved memory regions from vmcore

This commit applies non-dumpable reserved memory filtering to RISC-V kdump,
similar to arm64. It excludes flagged regions from the elfcorehdr PT_LOAD
segments and pre-sizes the crash_mem array accordingly.

> diff --git a/arch/riscv/kernel/machine_kexec_file.c b/arch/riscv/kernel/machine_kexec_file.c
> index 59d4bbc848a89..25359d583bc3b 100644
> --- a/arch/riscv/kernel/machine_kexec_file.c
> +++ b/arch/riscv/kernel/machine_kexec_file.c
[ ... ]
> @@ -64,6 +65,7 @@ static int prepare_elf_headers(void **addr, unsigned long *sz)
>  
>  	nr_ranges = 1; /* For exclusion of crashkernel region */
>  	walk_system_ram_res(0, -1, &nr_ranges, get_nr_ram_ranges_callback);
> +	nr_ranges += of_reserved_mem_kdump_nr_ranges();
>  
>  	cmem = kmalloc_flex(*cmem, ranges, nr_ranges);
>  	if (!cmem)

[Severity: High]
This is a pre-existing issue, but is it possible for a memory hotplug event
to occur between counting the ranges here and when the array is actually
populated?

In prepare_elf_headers(), the code counts the memory ranges to allocate
the cmem array, but a concurrent memory hot-add could occur before the
subsequent walk_system_ram_res() call populates it:

arch/riscv/kernel/machine_kexec_file.c:prepare_elf_headers() {
    ...
    walk_system_ram_res(0, -1, &nr_ranges, get_nr_ram_ranges_callback);
    ...
    ret = walk_system_ram_res(0, -1, cmem, prepare_elf64_ram_headers_callback);
    ...
}

If the number of ranges increases, prepare_elf64_ram_headers_callback()
will write past the end of the flexible array since it doesn't verify
that cmem->nr_ranges is less than cmem->max_nr_ranges:

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++;
    ...
}

Could this missing bounds check lead to an out-of-bounds heap write?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260630074715.4126796-1-chenwandun1@gmail.com?part=9

  reply	other threads:[~2026-06-30  9:22 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-30  7:47 [PATCH v4 00/10] kdump: reduce vmcore size and capture time Wandun Chen
2026-06-30  7:47 ` [PATCH v4 01/10] kexec/crash: provide crash_exclude_mem_range() stub when CONFIG_CRASH_DUMP=n Wandun Chen
2026-06-30 11:05   ` Pratyush Yadav
2026-06-30  7:47 ` [PATCH v4 02/10] of: reserved_mem: dedup and relocate reserved-memory messages Wandun Chen
2026-06-30  7:47 ` [PATCH v4 03/10] of: reserved_mem: skip late scan when no regions are reserved Wandun Chen
2026-06-30  8:19   ` sashiko-bot
2026-06-30  7:47 ` [PATCH v4 04/10] of: reserved_mem: split alloc_reserved_mem_array() from fdt_scan_reserved_mem_late() Wandun Chen
2026-06-30  7:47 ` [PATCH v4 05/10] of: reserved_mem: add dumpable flag to opt-in vmcore Wandun Chen
2026-06-30  7:47 ` [PATCH v4 06/10] of: reserved_mem: save /memreserve/ entries into the reserved_mem array Wandun Chen
2026-06-30  7:47 ` [PATCH v4 07/10] of: reserved_mem: add kdump helpers to exclude non-dumpable regions Wandun Chen
2026-06-30 11:06   ` Pratyush Yadav
2026-06-30  7:47 ` [PATCH v4 08/10] arm64: kdump: exclude non-dumpable reserved memory regions from vmcore Wandun Chen
2026-06-30  9:04   ` sashiko-bot
2026-06-30 11:06   ` Pratyush Yadav
2026-06-30  7:47 ` [PATCH v4 09/10] riscv: " Wandun Chen
2026-06-30  9:22   ` sashiko-bot [this message]
2026-06-30 11:12   ` Pratyush Yadav
2026-06-30 12:00     ` Wandun
2026-06-30  7:47 ` [PATCH v4 10/10] loongarch: " Wandun Chen
2026-06-30  9:37   ` sashiko-bot
2026-06-30 11:13   ` Pratyush Yadav

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=20260630092249.85B991F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=chenwandun1@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox