Skip to contentSkip to conversation

FAILED: patch "[PATCH] arm64: kexec_file: Fix elf_headers memory leak in retry loop" failed to apply to 5.10-stable tree

PATCH New Sasha Levin 1 participant 2 messages Nov 10 – Nov 14

Subsystems (2)
lore
Share & tools
lore

Sasha Levin

author maintainer
#0 lore raw

The patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x ac302aea3d824ccc99f29b8e499c365cb9a684a9
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 5.10.y' 'HEAD^..'

Thanks,
Sasha

------------------ original commit in Linus's tree ------------------

From ac302aea3d824ccc99f29b8e499c365cb9a684a9 Mon Sep 17 00:00:00 2001
From: Jinjie Ruan <[email protected]>
Date: Thu, 5 Nov 2026 20:57:24 +0800
Subject: [PATCH] arm64: kexec_file: Fix elf_headers memory leak in retry loop

A retry allocates new elf headers and overwrites image->elf_headers, leaking the previous buffer.

Free it before assigning.

Cc Will Deacon <[email protected]>
Cc Thomas Huth <[email protected]>
Cc Breno Leitao <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Yeoreum Yun <[email protected]>
Cc Baoquan He <[email protected]>
Fixes 108aa503657e ("arm64: kexec_file: try more regions if loading segments fails")
[[email protected]: drop the redundant NULL check before vfree()]
---
 arch/arm64/kernel/machine_kexec_file.c | 2 ++
 1 file changed, 2 insertions(+)
arch/arm64/kernel/machine_kexec_file.c +2 -0
index 854d872dfd0f5..14f453dd09465 100644
@@ -112,6 +112,8 @@ int load_other_segments(struct kimage *image,
 			vfree(headers);
 			goto out_err;
 		}
+
+		vfree(image->elf_headers);
 		image->elf_headers = headers;
 		image->elf_load_addr = kbuf.mem;
 		image->elf_headers_sz = headers_sz;
Signature · 1 line
2.53.0
author maintainer
#1 lore raw

PATCH 1/1 arm64: kexec_file: Fix elf_headers memory leak in retry loop

From: Jinjie Ruan <[email protected]>

[ Upstream commit ac302aea3d824ccc99f29b8e499c365cb9a684a9 ]

A retry allocates new elf headers and overwrites image->elf_headers, leaking the previous buffer.

Free it before assigning.

Cc Will Deacon <[email protected]>
Cc Thomas Huth <[email protected]>
Cc Breno Leitao <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Yeoreum Yun <[email protected]>
Cc Baoquan He <[email protected]>
Fixes 108aa503657e ("arm64: kexec_file: try more regions if loading segments fails")
[[email protected]: drop the redundant NULL check before vfree()]
[ sashal: Changed the vfree() argument from image->elf_headers to image->arch.elf_headers. ]
---
 arch/arm64/kernel/machine_kexec_file.c | 2 ++
 1 file changed, 2 insertions(+)
arch/arm64/kernel/machine_kexec_file.c +2 -0
index 0cde47a63bebf..1226d665a5872 100644
@@ -284,6 +284,8 @@ int load_other_segments(struct kimage *image,
 			vfree(headers);
 			goto out_err;
 		}
+
+		vfree(image->arch.elf_headers);
 		image->arch.elf_headers = headers;
 		image->arch.elf_headers_mem = kbuf.mem;
 		image->arch.elf_headers_sz = headers_sz;
Signature · 1 line
2.53.0