[PATCH v6 07/14] LoongArch: kexec_file: Fix elf_headers memory leak in retry loop

sashiko-bot at kernel.org sashiko-bot at kernel.org
Mon Sep 21 02:14:12 PDT 2026


> 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 efi_kexec_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: Huacai Chen <chenhuacai at kernel.org>
> Cc: WANG Xuerui <kernel at xen0n.name>
> Cc: Youling Tang <tangyouling at kylinos.cn>
> Cc: "Mike Rapoport (Microsoft)" <rppt at kernel.org>
> Cc: Sourabh Jain <sourabhjain at linux.ibm.com>
> Cc: Kees Cook <kees at kernel.org>
> Cc: stable at vger.kernel.org
> Link: https://sashiko.dev/#/patchset/20260729031235.2840255-1-ruanjinjie%40huawei.com
> Fixes: 55d990f0084c ("LoongArch: Add EFI binary support for kexec_file")
> Signed-off-by: Jinjie Ruan <ruanjinjie at huawei.com>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260921090450.807575-1-ruanjinjie@huawei.com?part=7




More information about the kexec mailing list