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 v2 8/8] loongarch: kdump: exclude non-dumpable reserved memory regions from vmcore
Date: Wed, 20 May 2026 13:10:13 +0000 [thread overview]
Message-ID: <20260520131013.AADB41F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260520091844.592753-9-chenwandun@lixiang.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Lockless iteration of memblock.memory during kexec_file_load can race with memory hotplug, leading to Use-After-Free (UAF) and out-of-bounds writes.
--
commit 940dd878bcc6cf760efd15c48a5b87206c6b6d94
Author: Wandun Chen <chenwandun1@gmail.com>
loongarch: kdump: exclude non-dumpable reserved memory regions from vmcore
This commit applies non-dumpable reserved memory filtering to LoongArch
kdump. It uses of_reserved_mem_kdump_exclude() to drop flagged regions and
of_reserved_mem_kdump_nr_ranges() to pre-size the crash_mem array.
> diff --git a/arch/loongarch/kernel/machine_kexec_file.c b/arch/loongarch/kernel/machine_kexec_file.c
> index 5584b798ba464..c5cead362d2db 100644
> --- a/arch/loongarch/kernel/machine_kexec_file.c
> +++ b/arch/loongarch/kernel/machine_kexec_file.c
[ ... ]
> @@ -67,6 +68,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++;
[Severity: High]
This isn't a bug introduced by this patch, but can this lockless iteration
of memblock.memory race with memory hotplug?
The kexec_file_load syscall enters prepare_elf_headers() without holding
get_online_mems() or any lock that serializes against CPU/memory hotplug.
Inside prepare_elf_headers(), for_each_mem_range() locklessly iterates over
the memblock.memory regions twice: first to count the regions (nr_ranges),
and second to populate the cmem->ranges array.
On architectures that keep memblock post-boot (like LoongArch with
CONFIG_ARCH_KEEP_MEMBLOCK), a concurrent memory hotplug event
(e.g., add_memory_resource()) can mutate memblock.memory via
memblock_add_node().
If memblock.memory.cnt reaches its capacity, memblock_add_node() invokes
memblock_double_array(), which allocates a larger array, copies the
contents, and frees the old array. The concurrent for_each_mem_range() loop
could then access the freed array, resulting in a use-after-free.
Additionally, if memblock.memory.cnt increases between the first counting
loop and the second population loop, cmem->nr_ranges will exceed the
allocated size of the flex array, causing an out-of-bounds write into the
cmem->ranges array.
> + nr_ranges += of_reserved_mem_kdump_nr_ranges();
>
> cmem = kmalloc_flex(*cmem, ranges, nr_ranges);
> if (!cmem)
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260520091844.592753-1-chenwandun@lixiang.com?part=8
prev parent reply other threads:[~2026-05-20 13:10 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-20 9:18 [PATCH v2 0/8] kdump: reduce vmcore size and capture time Wandun Chen
2026-05-20 9:18 ` [PATCH v2 1/8] of: reserved_mem: handle NULL name in of_reserved_mem_lookup() Wandun Chen
2026-05-20 9:18 ` [PATCH v2 2/8] kexec/crash: provide crash_exclude_mem_range() stub when CONFIG_CRASH_DUMP=n Wandun Chen
2026-05-20 9:18 ` [PATCH v2 3/8] of: reserved_mem: add dumpable flag to opt-in vmcore Wandun Chen
2026-05-20 9:53 ` Marek Szyprowski
2026-05-20 9:18 ` [PATCH v2 4/8] of: reserved_mem: save /memreserve/ entries into the reserved_mem array Wandun Chen
2026-05-20 10:37 ` sashiko-bot
2026-05-20 9:18 ` [PATCH v2 5/8] of: reserved_mem: add kdump helpers to exclude non-dumpable regions Wandun Chen
2026-05-20 11:03 ` sashiko-bot
2026-05-20 9:18 ` [PATCH v2 6/8] arm64: kdump: exclude non-dumpable reserved memory regions from vmcore Wandun Chen
2026-05-20 12:02 ` sashiko-bot
2026-05-20 9:18 ` [PATCH v2 7/8] riscv: " Wandun Chen
2026-05-20 12:34 ` sashiko-bot
2026-05-20 9:18 ` [PATCH v2 8/8] loongarch: " Wandun Chen
2026-05-20 13:10 ` sashiko-bot [this message]
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=20260520131013.AADB41F000E9@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