From: sashiko-bot@kernel.org
To: "Jinjie Ruan" <ruanjinjie@huawei.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v14 06/17] arm64: kexec_file: Fix potential buffer overflow in prepare_elf_headers()
Date: Mon, 25 May 2026 10:52:26 +0000 [thread overview]
Message-ID: <20260525105227.3C2421F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260525084932.934910-7-ruanjinjie@huawei.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] If kexec_add_buffer() fails for the ELF headers segment in load_other_segments(), it erroneously calls vfree(headers). However, the caller image_load() operates in a placement retry loop and will reuse the freed pointer on the next iteration, leading to a Use-After-Free. Furthermore, the global cleanup path will double-free the pointer.
- [High] In crash_load_dm_crypt_keys(), if kexec_add_buffer() fails, the global keys_header is freed via kvfree() but the pointer is not set to NULL. If the kexec load sequence retries, it will trigger a Use-After-Free or Double Free.
--
commit 205dd983aa0b64a4b48461b2eeaf22aeada0f3e8
Author: Jinjie Ruan <ruanjinjie@huawei.com>
arm64: kexec_file: Fix potential buffer overflow in prepare_elf_headers()
This commit addresses a TOCTOU race condition in prepare_elf_headers() during
memory hotplug events by physically isolating the locking contexts. It moves
the get_online_mems() read lock to the top-level architecture image loaders
and adds bounds checking in machine_kexec_file.c.
> diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c
> index 79efeaeb71e93..884e446f08e34 100644
> --- a/arch/arm64/kernel/kexec_image.c
> +++ b/arch/arm64/kernel/kexec_image.c
[ ... ]
> @@ -96,11 +97,14 @@ static void *image_load(struct kimage *image,
>
> #ifdef CONFIG_CRASH_DUMP
> if (image->type == KEXEC_TYPE_CRASH) {
> + get_online_mems();
> ret = prepare_elf_headers(&headers, &headers_sz);
> if (ret) {
> pr_err("Preparing elf core header failed\n");
> + put_online_mems();
> return ERR_PTR(ret);
> }
> + put_online_mems();
> image->elf_headers = headers;
> image->elf_headers_sz = headers_sz;
> }
[Severity: High]
This is a pre-existing issue, but does the retry loop directly below this
code lead to a use-after-free if kexec_add_buffer() fails in
load_other_segments()?
Looking at image_load(), the while loop attempts to load segments and calls
load_other_segments() repeatedly. If load_other_segments() fails during
kexec_add_buffer(), it calls vfree(headers). However, the loop in
image_load() will try again and pass the same freed headers pointer to
load_other_segments() on the next iteration.
Additionally, if the loop exhausts all options, does the global cleanup path
arch_kimage_file_post_load_cleanup() also unconditionally call
vfree(image->elf_headers), resulting in a double-free?
[Severity: High]
This is a pre-existing issue, but can this retry loop similarly trigger
a use-after-free or double-free with keys_header?
If kexec_add_buffer() fails inside crash_load_dm_crypt_keys(), the global
pointer keys_header is freed via kvfree() but not set to NULL.
When image_load() retries, crash_load_dm_crypt_keys() is invoked again. If it
calls build_keys_header(), it executes:
if (keys_header != NULL)
kvfree(keys_header);
which would trigger a double-free. Alternatively, if is_dm_key_reused is
true, would it reuse the freed pointer directly for a new
kexec_add_buffer() call?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260525084932.934910-1-ruanjinjie@huawei.com?part=6
next prev parent reply other threads:[~2026-05-25 10:52 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-25 8:49 [PATCH v14 00/17] arm64/riscv: Add support for crashkernel CMA reservation Jinjie Ruan
2026-05-25 8:49 ` [PATCH v14 01/17] riscv: kexec_file: Fix crashk_low_res not exclude bug Jinjie Ruan
2026-05-25 8:49 ` [PATCH v14 02/17] powerpc/crash: Fix possible memory leak in update_crash_elfcorehdr() Jinjie Ruan
2026-05-25 9:22 ` sashiko-bot
2026-05-25 8:49 ` [PATCH v14 03/17] powerpc/crash: sort crash memory ranges before preparing elfcorehdr Jinjie Ruan
2026-05-25 8:49 ` [PATCH v14 04/17] arm64: kexec: Fix image->elf_headers memory leak during retry loop Jinjie Ruan
2026-05-25 9:11 ` sashiko-bot
2026-05-25 8:49 ` [PATCH v14 05/17] x86/kexec: Fix potential buffer overflow in prepare_elf_headers() Jinjie Ruan
2026-05-25 8:49 ` [PATCH v14 06/17] arm64: kexec_file: " Jinjie Ruan
2026-05-25 10:52 ` sashiko-bot [this message]
2026-05-25 8:49 ` [PATCH v14 07/17] riscv: " Jinjie Ruan
2026-05-25 9:54 ` sashiko-bot
2026-05-25 8:49 ` [PATCH v14 08/17] LoongArch: kexec: " Jinjie Ruan
2026-05-25 8:49 ` [PATCH v14 09/17] crash: Add crash_prepare_headers() to exclude crash kernel memory Jinjie Ruan
2026-05-25 8:49 ` [PATCH v14 10/17] arm64: kexec_file: Use crash_prepare_headers() helper to simplify code Jinjie Ruan
2026-05-25 9:33 ` sashiko-bot
2026-05-25 8:49 ` [PATCH v14 11/17] x86/kexec: " Jinjie Ruan
2026-05-25 8:49 ` [PATCH v14 12/17] riscv: kexec_file: " Jinjie Ruan
2026-05-25 8:49 ` [PATCH v14 13/17] LoongArch: kexec: " Jinjie Ruan
2026-05-25 8:49 ` [PATCH v14 14/17] crash: Use crash_exclude_core_ranges() on powerpc Jinjie Ruan
2026-05-25 8:49 ` [PATCH v14 15/17] arm64: kexec: Add support for crashkernel CMA reservation Jinjie Ruan
2026-05-25 8:49 ` [PATCH v14 16/17] riscv: " Jinjie Ruan
2026-05-25 8:49 ` [PATCH v14 17/17] arm64/crash: Add crash hotplug support Jinjie Ruan
2026-05-25 10:17 ` sashiko-bot
2026-05-25 10:14 ` [PATCH v14 00/17] arm64/riscv: Add support for crashkernel CMA reservation Huacai Chen
2026-05-25 11:36 ` Mike Rapoport
2026-05-25 13:17 ` Huacai Chen
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=20260525105227.3C2421F000E9@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