From: sashiko-bot@kernel.org
To: "Jinjie Ruan" <ruanjinjie@huawei.com>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH v14 10/17] arm64: kexec_file: Use crash_prepare_headers() helper to simplify code
Date: Mon, 25 May 2026 09:33:17 +0000 [thread overview]
Message-ID: <20260525093318.12C591F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260525084932.934910-11-ruanjinjie@huawei.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [Low] Stale function prototype for prepare_elf_headers() left in the arch header.
Pre-existing issues:
- [Critical] Retrying after load_other_segments() failure leads to Use-After-Free and Double Free of the ELF headers buffer.
--
commit 6831fa88a7516f58be581afc5bb7de8776b9c44c
Author: Jinjie Ruan <ruanjinjie@huawei.com>
arm64: kexec_file: Use crash_prepare_headers() helper to simplify code
Use the newly introduced crash_prepare_headers() function to replace
the existing prepare_elf_headers(), allocate cmem and exclude crash
kernel memory in the crash core, which reduce code duplication.
> diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c
> index 884e446f08e34..770a4c7bf5737 100644
> --- a/arch/arm64/kernel/kexec_image.c
> +++ b/arch/arm64/kernel/kexec_image.c
> @@ -97,14 +96,11 @@ 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);
> + ret = crash_prepare_headers_locked(true, &headers, &headers_sz, NULL);
> 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: Critical]
This isn't a bug introduced by this patch, but it appears there's a
use-after-free and double-free risk in the retry loop below this code.
If load_other_segments() fails during the retry loop, it frees the
headers buffer:
arch/arm64/kernel/machine_kexec_file.c:load_other_segments() {
...
if (image->type == KEXEC_TYPE_CRASH) {
...
ret = kexec_add_buffer(&kbuf);
if (ret) {
vfree(headers);
goto out_err;
}
...
}
If the retry loop in image_load() continues after this failure, won't the
next iteration pass the already freed headers pointer back into
load_other_segments()?
Additionally, since image->elf_headers stores this pointer, does
arch_kimage_file_post_load_cleanup() also call vfree(image->elf_headers)
upon failure, leading to a double-free?
[ ... ]
> diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c
> index c0ace89ded923..66fbfbaec1c67 100644
> --- a/arch/arm64/kernel/machine_kexec_file.c
> +++ b/arch/arm64/kernel/machine_kexec_file.c
> @@ -40,51 +40,33 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image)
> }
>
> #ifdef CONFIG_CRASH_DUMP
> -int prepare_elf_headers(void **addr, unsigned long *sz)
[Severity: Low]
Does the function prototype for prepare_elf_headers() need to be
removed from arch/arm64/include/asm/kexec.h as well?
It appears to be left behind as dead code since this patch removes its
architecture-specific implementation.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260525084932.934910-1-ruanjinjie@huawei.com?part=10
next prev parent reply other threads:[~2026-05-25 9:33 UTC|newest]
Thread overview: 28+ 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-26 3:14 ` Jinjie Ruan
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
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 [this message]
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=20260525093318.12C591F000E9@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