All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Wandun Chen" <chenwandun1@gmail.com>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH v5 6/8] crash_core: fold duplicated memblock arch hooks into the weak default
Date: Thu, 06 Aug 2026 09:56:04 +0000	[thread overview]
Message-ID: <20260806095605.21E131F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260806093519.2907771-7-chenwandun1@gmail.com>

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

New issues:
- [Low] Leftover unused `#include <linux/memblock.h>` in `arch/riscv/kernel/machine_kexec_file.c`.

Pre-existing issues:
- [High] A time-of-check to time-of-use (TOCTOU) race condition in `crash_prepare_headers()` allows an out-of-bounds array write and Use-After-Free (UAF) during concurrent memory hotplug.
--

--- Patch [6]: [PATCH v5 6/8] crash_core: fold duplicated memblock arch hooks into the weak default ---
commit 1003e078862f2080b60e5f21352f7989a4d125c2
Author: Wandun Chen <chenwandun@lixiang.com>

crash_core: fold duplicated memblock arch hooks into the weak default

arm64, loongarch and riscv open-code the same memblock walk in
arch_get_system_nr_ranges() and arch_crash_populate_cmem(). Move it into
the __weak defaults in kernel/crash_core.c and delete the arch copies.

> diff --git a/arch/riscv/kernel/machine_kexec_file.c b/arch/riscv/kernel/machine_kexec_file.c
> index 808e872f40634..fdc6695e85882 100644
> --- a/arch/riscv/kernel/machine_kexec_file.c
> +++ b/arch/riscv/kernel/machine_kexec_file.c
> @@ -37,32 +37,6 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image)
>  }
>  
>  #ifdef CONFIG_CRASH_DUMP

[Severity: Low]
This isn't a bug, but can we also drop the #include <linux/memblock.h>
from arch/riscv/kernel/machine_kexec_file.c?

The patch successfully relocates all memblock usage out of the riscv file,
and the include was correctly dropped for arm64 and loongarch, but it looks
like it was missed here.

> -unsigned int arch_get_system_nr_ranges(void)
> -{

[ ... ]

> diff --git a/kernel/crash_core.c b/kernel/crash_core.c
> index 2b36aa9fade06..77285ae3ce600 100644
> --- a/kernel/crash_core.c
> +++ b/kernel/crash_core.c

[ ... ]

> +int __weak arch_crash_populate_cmem(struct crash_mem *cmem)
> +{
> +	phys_addr_t start, end;
> +	u64 i;
> +
> +	for_each_mem_range(i, &start, &end) {
> +		cmem->ranges[cmem->nr_ranges].start = start;
> +		cmem->ranges[cmem->nr_ranges].end = end - 1;
> +		cmem->nr_ranges++;
> +	}

[Severity: High]
This is a pre-existing issue, but does this loop risk an out-of-bounds array
write during concurrent memory hotplug?

The loop unconditionally writes to cmem->ranges and increments the index
without verifying bounds against cmem->max_nr_ranges.

In crash_prepare_headers(), the code sequentially counts the regions,
allocates memory, and then calls arch_crash_populate_cmem():

	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);

Since neither kexec_file_load nor these functions hold the memory hotplug
read lock (get_online_mems()), couldn't memblock.memory be modified
concurrently between the check and the use? If regions are added or split,
this loop would write past the allocated array size.

> +	return 0;
> +}
>  int __weak arch_crash_exclude_ranges(struct crash_mem *cmem) { return 0; }

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

  reply	other threads:[~2026-08-06  9:56 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20260806093541eucas1p169d6fcb31de09012bdfca326867e86d6@eucas1p1.samsung.com>
2026-08-06  9:35 ` [PATCH v5 0/8] kdump: reduce vmcore size and capture time Wandun Chen
2026-08-06  9:35   ` Wandun Chen
2026-08-06  9:35   ` [PATCH v5 1/8] memblock: introduce MEMBLOCK_NODUMP flag Wandun Chen
2026-08-06  9:35     ` Wandun Chen
2026-08-06  9:51     ` sashiko-bot
2026-08-06 11:43       ` Wandun
2026-08-06  9:35   ` [PATCH v5 2/8] of: reserved_mem: add dumpable flag to opt-in vmcore Wandun Chen
2026-08-06  9:35     ` Wandun Chen
2026-08-06  9:47     ` sashiko-bot
2026-08-06 11:48       ` Wandun
2026-08-06  9:35   ` [PATCH v5 3/8] of: reserved_mem: mark /reserved-memory entries with MEMBLOCK_NODUMP Wandun Chen
2026-08-06  9:35     ` Wandun Chen
2026-08-06 10:06     ` sashiko-bot
2026-08-06  9:35   ` [PATCH v5 4/8] of: reserved_mem: mark /memreserve/ entries as MEMBLOCK_NODUMP Wandun Chen
2026-08-06  9:35     ` Wandun Chen
2026-08-06  9:57     ` sashiko-bot
2026-08-06  9:35   ` [PATCH v5 5/8] riscv: build crash_mem ranges from memblock instead of resource tree Wandun Chen
2026-08-06  9:35     ` Wandun Chen
2026-08-06 10:10     ` sashiko-bot
2026-08-06  9:35   ` [PATCH v5 6/8] crash_core: fold duplicated memblock arch hooks into the weak default Wandun Chen
2026-08-06  9:35     ` Wandun Chen
2026-08-06  9:56     ` sashiko-bot [this message]
2026-08-06  9:35   ` [PATCH v5 7/8] crash_core: replace for_each_mem_range() with for_each_mem_region() Wandun Chen
2026-08-06  9:35     ` Wandun Chen
2026-08-06 10:07     ` sashiko-bot
2026-08-06  9:35   ` [PATCH v5 8/8] crash_core: skip MEMBLOCK_NODUMP regions when building vmcore ELF header Wandun Chen
2026-08-06  9:35     ` Wandun Chen
2026-08-06 10:24     ` sashiko-bot
2026-08-06 10:11   ` [PATCH v5 0/8] kdump: reduce vmcore size and capture time Marek Szyprowski
2026-08-06 10:11     ` Marek Szyprowski

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=20260806095605.21E131F00A3A@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 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.