From: Jinjie Ruan <ruanjinjie@huawei.com>
To: <catalin.marinas@arm.com>, <will@kernel.org>,
<akpm@linux-foundation.org>, <baoquan.he@linux.dev>,
<rppt@kernel.org>, <pasha.tatashin@soleen.com>,
<pratyush@kernel.org>, <thuth@redhat.com>, <mark.rutland@arm.com>,
<jic23@kernel.org>, <james.morse@arm.com>, <ardb@kernel.org>,
<leitao@debian.org>, <yeoreum.yun@arm.com>,
<sourabhjain@linux.ibm.com>, <robh@kernel.org>, <kees@kernel.org>,
<coxu@redhat.com>, <makb@juniper.net>, <piliu@redhat.com>,
<graf@amazon.com>, <ebiggers@kernel.org>, <jbouron@amazon.com>,
<bgwin@google.com>, <linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>, <kexec@lists.infradead.org>
Cc: <ruanjinjie@huawei.com>
Subject: [PATCH v2 3/5] arm64: kexec_file: Fix image->elf_headers memory leak in retry loop
Date: Wed, 29 Jul 2026 11:12:33 +0800 [thread overview]
Message-ID: <20260729031235.2840255-4-ruanjinjie@huawei.com> (raw)
In-Reply-To: <20260729031235.2840255-1-ruanjinjie@huawei.com>
If load_other_segments() fails after image->elf_headers is assigned,
the memory lifecycle is safely managed by the global kimage object
and will be freed in arch_kimage_file_post_load_cleanup().
However, during a retry loop in image_load(), a subsequent iteration
will allocate a new buffer and overwrite image->elf_headers. This
permanently leaks the stale memory from the previous iteration before
the global cleanup can track it.
Fix this by explicitly freeing the stale `image->elf_headers` buffer
before assigning the newly allocated headers.
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Thomas Huth <thuth@redhat.com>
Cc: Breno Leitao <leitao@debian.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Yeoreum Yun <yeoreum.yun@arm.com>
Cc: Baoquan He <bhe@redhat.com>
Cc: stable@vger.kernel.org
Fixes: 108aa503657e ("arm64: kexec_file: try more regions if loading segments fails")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/arm64/kernel/machine_kexec_file.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c
index e48f29167b38..2f750e5f4fcc 100644
--- a/arch/arm64/kernel/machine_kexec_file.c
+++ b/arch/arm64/kernel/machine_kexec_file.c
@@ -112,6 +112,10 @@ int load_other_segments(struct kimage *image,
vfree(headers);
goto out_err;
}
+
+ if (unlikely(image->elf_headers))
+ vfree(image->elf_headers);
+
image->elf_headers = headers;
image->elf_load_addr = kbuf.mem;
image->elf_headers_sz = headers_sz;
--
2.34.1
next prev parent reply other threads:[~2026-07-29 3:13 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 3:12 [PATCH v2 0/5] arm64: crash: Add crash hotplug support Jinjie Ruan
2026-07-29 3:12 ` [PATCH v2 1/5] kexec: Extract kexec_free_segment_cma() from kimage_free_cma() Jinjie Ruan
2026-07-29 3:12 ` [PATCH v2 2/5] arm64: kexec_file: Fix CMA page leaks in segment placement retry loops Jinjie Ruan
2026-07-29 3:12 ` Jinjie Ruan [this message]
2026-07-29 3:12 ` [PATCH v2 4/5] arm64: kexec_file: Simplify load_other_segments() Jinjie Ruan
2026-07-29 3:12 ` [PATCH v2 5/5] arm64: crash: Add crash hotplug support Jinjie Ruan
2026-08-13 16:05 ` Catalin Marinas
2026-08-17 10:45 ` Jinjie Ruan
2026-08-11 13:05 ` [PATCH v2 0/5] " Jinjie Ruan
2026-08-13 14:40 ` Catalin Marinas
2026-08-14 1:15 ` Jinjie Ruan
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=20260729031235.2840255-4-ruanjinjie@huawei.com \
--to=ruanjinjie@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=ardb@kernel.org \
--cc=baoquan.he@linux.dev \
--cc=bgwin@google.com \
--cc=catalin.marinas@arm.com \
--cc=coxu@redhat.com \
--cc=ebiggers@kernel.org \
--cc=graf@amazon.com \
--cc=james.morse@arm.com \
--cc=jbouron@amazon.com \
--cc=jic23@kernel.org \
--cc=kees@kernel.org \
--cc=kexec@lists.infradead.org \
--cc=leitao@debian.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=makb@juniper.net \
--cc=mark.rutland@arm.com \
--cc=pasha.tatashin@soleen.com \
--cc=piliu@redhat.com \
--cc=pratyush@kernel.org \
--cc=robh@kernel.org \
--cc=rppt@kernel.org \
--cc=sourabhjain@linux.ibm.com \
--cc=thuth@redhat.com \
--cc=will@kernel.org \
--cc=yeoreum.yun@arm.com \
/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