All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Wandun Chen" <chenwandun1@gmail.com>
Cc: robh@kernel.org, devicetree@vger.kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v3 09/11] arm64: kdump: exclude non-dumpable reserved memory regions from vmcore
Date: Wed, 27 May 2026 04:10:04 +0000	[thread overview]
Message-ID: <20260527041005.BDBD41F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260527032917.3385849-10-chenwandun1@gmail.com>

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

Pre-existing issues:
- [High] Pre-existing TOCTOU and heap buffer overflow in `prepare_elf_headers()` due to unlocked `memblock` traversal.
--

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

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

This commit excludes device firmware memory regions reserved via device tree 
from the vmcore by default, honoring the dumpable flag. It calculates the 
required array size using of_reserved_mem_kdump_nr_ranges() and filters 
them via of_reserved_mem_kdump_exclude().

> diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c
> --- a/arch/arm64/kernel/machine_kexec_file.c
> +++ b/arch/arm64/kernel/machine_kexec_file.c
[ ... ]
> @@ -51,6 +52,7 @@ static int prepare_elf_headers(void **addr, unsigned long *sz)
>  	nr_ranges = 2; /* for exclusion of crashkernel region */
>  	for_each_mem_range(i, &start, &end)
>  		nr_ranges++;
> +	nr_ranges += of_reserved_mem_kdump_nr_ranges();
>  
>  	cmem = kmalloc_flex(*cmem, ranges, nr_ranges);

[Severity: High]
This is a pre-existing issue, but could a concurrent memory hotplug event
cause a buffer overflow or use-after-free here?

The prepare_elf_headers() function iterates over memblock.memory locklessly
using for_each_mem_range() to count the memory ranges, and then allocates
the cmem array based on this count before later populating it.

Since ARM64 sets CONFIG_ARCH_KEEP_MEMBLOCK, memory hotplug operations can
dynamically add or remove regions at runtime via memblock_add_node() and
memblock_remove(). While these modifications are protected by
mem_hotplug_begin(), the sys_kexec_file_load() path does not appear to
acquire this lock.

If a hotplug event occurs between the counting loop and the population loop,
might the number of ranges increase and cause an out-of-bounds write past
the end of the allocated cmem->ranges array?

Additionally, can a concurrent hotplug trigger memblock_double_array(),
which reallocates the memblock.memory.regions array and frees the old one,
leading to a use-after-free read during the unlocked iteration?

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

  reply	other threads:[~2026-05-27  4:10 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-27  3:29 [PATCH v3 00/11] kdump: reduce vmcore size and capture time Wandun Chen
2026-05-27  3:29 ` Wandun Chen
2026-05-27  3:29 ` [PATCH v3 01/11] of: reserved_mem: handle NULL name in of_reserved_mem_lookup() Wandun Chen
2026-05-27  3:29   ` Wandun Chen
2026-05-27  3:29 ` [PATCH v3 02/11] kexec/crash: provide crash_exclude_mem_range() stub when CONFIG_CRASH_DUMP=n Wandun Chen
2026-05-27  3:29   ` Wandun Chen
2026-05-27  3:29 ` [PATCH v3 03/11] of: reserved_mem: avoid post-init UAF when alloc_reserved_mem_array() fails Wandun Chen
2026-05-27  3:29   ` Wandun Chen
2026-06-02 16:24   ` Rob Herring
2026-06-02 16:24     ` Rob Herring
2026-06-03  6:44     ` Wandun
2026-06-03  6:44       ` Wandun
2026-06-03 17:44       ` Rob Herring
2026-06-03 17:44         ` Rob Herring
2026-06-04  1:48         ` Wandun
2026-06-04  1:48           ` Wandun
2026-05-27  3:29 ` [PATCH v3 04/11] of: reserved_mem: zero total_reserved_mem_cnt if no valid /reserved-memory entry Wandun Chen
2026-05-27  3:29   ` Wandun Chen
2026-05-27  3:53   ` sashiko-bot
2026-05-27  3:29 ` [PATCH v3 05/11] of: reserved_mem: split alloc_reserved_mem_array() from fdt_scan_reserved_mem_late() Wandun Chen
2026-05-27  3:29   ` Wandun Chen
2026-05-27  4:21   ` sashiko-bot
2026-05-27  3:29 ` [PATCH v3 06/11] of: reserved_mem: add dumpable flag to opt-in vmcore Wandun Chen
2026-05-27  3:29   ` Wandun Chen
2026-05-27  3:29 ` [PATCH v3 07/11] of: reserved_mem: save /memreserve/ entries into the reserved_mem array Wandun Chen
2026-05-27  3:29   ` Wandun Chen
2026-05-27  3:29 ` [PATCH v3 08/11] of: reserved_mem: add kdump helpers to exclude non-dumpable regions Wandun Chen
2026-05-27  3:29   ` Wandun Chen
2026-05-27  3:29 ` [PATCH v3 09/11] arm64: kdump: exclude non-dumpable reserved memory regions from vmcore Wandun Chen
2026-05-27  3:29   ` Wandun Chen
2026-05-27  4:10   ` sashiko-bot [this message]
2026-05-29 15:08   ` Will Deacon
2026-05-29 15:08     ` Will Deacon
2026-05-30 16:25     ` Mike Rapoport
2026-05-30 16:25       ` Mike Rapoport
2026-06-01  5:00       ` Baoquan He
2026-06-01  5:00         ` Baoquan He
2026-06-02  9:34         ` Mike Rapoport
2026-06-02  9:34           ` Mike Rapoport
2026-05-27  3:29 ` [PATCH v3 10/11] riscv: " Wandun Chen
2026-05-27  3:29   ` Wandun Chen
2026-05-27  4:05   ` sashiko-bot
2026-05-27  3:29 ` [PATCH v3 11/11] loongarch: " Wandun Chen
2026-05-27  3:29   ` Wandun Chen
2026-05-27  4:12   ` 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=20260527041005.BDBD41F000E9@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.