Re: [PATCH v7 00/15] kexec: Fix CMA and elf header leaks and rework

From: Mike Rapoport

Date: Wed Nov 04 2026 - 09:57:12 EST


Hi Jinjie,

> ARM64, LoongArch and RISC-V load the elf core header, initrd, DTB
> and cmdline parameters with almost identical code. This series fixes
> the bugs in that path. And as Mike suggested, rework the common part
> into a helper.
>
> Patch 1 stops using the Image text_offset for arm64, which breaks CMA
> segments in both the load and release paths, and rejects images with
> a non-zero value.
>
> Patches 2-7 fix the CMA page and elf core header leaks in the retry
> loops in arm64 and LoongArch, also fix a modified_cmdline leak
> in LoongArch.

These mix fixes that can be easily merged via arch trees and something
that depends on a change to the generic kexec code.

Besides, elf_headers leak and arm64's text_offset fixes should be
applied to most if not all stable kernels, while CMA fixes are only for
the relatively new kernels.

I'd suggest splitting

arm64: kexec_file: Stop using the Image text_offset
arm64: kexec_file: Fix elf_headers memory leak in retry loop

and sending as pure arm64 material, and


LoongArch: kexec_file: Fix elf_headers memory leak in retry loop
LoongArch: kexec_file: Fix a modified_cmdline leak

as pure LoongArch material.

And then working on CMA fixes after these land.

If there are real dependencies or potential conflicts, b4 prep can help
you with managing them.

> Patches 8-10 pass the kbuf fields to crash_prepare_headers() to
> simplfy code.
>
> Patch 11 frees the elf core header from the generic post-load cleanup.
>
> Patches 12-15 add kexec_load_other_segments() and convert the three
> architectures, and arch_kexec_setup_other_segments() builds
> the architecture specific boot parameters (a DTB or a command line).

I think the refactoring should go before the identical fixes in arch/
code.

--
Sincerely yours,
Mike.