[PATCH v7 00/15] kexec: Fix CMA and elf header leaks and rework
Jinjie Ruan
ruanjinjie at huawei.com
Tue Nov 3 01:14:35 PST 2026
在 2026/10/26 15:51, Jinjie Ruan 写道:
> 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.
>
> 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).
Hi, everyone,
Any thoughts or suggestions?
>
> Tested with kexec_file_load() and kdump on arm64, RISC-V and LoongArch
> under QEMU, including the non-zero text_offset rejection.
>
> This series is also available at:
> https://github.com/ruanjinjie-eng/linux/tree/kexec_cleanup_v7
>
> Changes in v7:
> - Rework the kexec_file load code to avoid code duplication
> as Mike suggested.
> - Add Acked-by.
> - Drop the two non-zero text_offset fix patches
> and deprecate .text_offset in arm64 as Mike suggested.
> - Drop the x86-32 fix patch.
> - Drop the TOCTOU race fix patches.
> - Link to v6: https://lore.kernel.org/all/20260921090450.807575-1-ruanjinjie@huawei.com/
>
> Previous Versions are as below:
> - v5: https://lore.kernel.org/all/20260918100442.3841135-1-ruanjinjie@huawei.com/
> - v4: https://lore.kernel.org/all/20260907125404.922123-1-ruanjinjie@huawei.com/
> - v3: https://lore.kernel.org/all/20260826092541.3905933-1-ruanjinjie@huawei.com/
> - v2: https://lore.kernel.org/all/20260729031235.2840255-1-ruanjinjie@huawei.com/
> - v1: https://lore.kernel.org/all/20260723131242.1537633-1-ruanjinjie@huawei.com/#t
>
> Jinjie Ruan (15):
> arm64: kexec_file: Stop using the Image text_offset
> kexec: Extract kexec_free_segment_cma() from kimage_free_cma()
> arm64: kexec_file: Fix CMA page leaks in segment placement retry loops
> arm64: kexec_file: Fix elf_headers memory leak in retry loop
> LoongArch: kexec_file: Fix CMA page leaks in segment placement retry
> loops
> LoongArch: kexec_file: Fix elf_headers memory leak in retry loop
> LoongArch: kexec_file: Fix a modified_cmdline leak
> arm64: kexec_file: Simplify load_other_segments()
> LoongArch: kexec_file: Simplify load_other_segments()
> riscv: kexec_file: Simplify load_extra_segments()
> kexec: Free the elf core header in kimage_file_post_load_cleanup()
> kexec: Add kexec_load_other_segments() helper
> arm64: kexec_file: Use kexec_load_other_segments() to simplify code
> LoongArch: kexec_file: Use kexec_load_other_segments() to simplify
> code
> riscv: kexec_file: Use kexec_load_other_segments() to simplify code
>
> arch/arm64/include/asm/kexec.h | 5 -
> arch/arm64/kernel/kexec_image.c | 33 +++++--
> arch/arm64/kernel/machine_kexec_file.c | 103 ++++-----------------
> arch/loongarch/include/asm/kexec.h | 4 -
> arch/loongarch/kernel/kexec_efi.c | 20 +++-
> arch/loongarch/kernel/kexec_elf.c | 11 ++-
> arch/loongarch/kernel/machine_kexec.c | 2 +
> arch/loongarch/kernel/machine_kexec_file.c | 96 +++----------------
> arch/powerpc/kexec/file_load_64.c | 4 -
> arch/riscv/include/asm/kexec.h | 4 -
> arch/riscv/kernel/kexec_elf.c | 11 ++-
> arch/riscv/kernel/kexec_image.c | 11 ++-
> arch/riscv/kernel/machine_kexec_file.c | 79 ++++------------
> arch/x86/kernel/machine_kexec_64.c | 4 -
> include/linux/kexec.h | 17 ++++
> kernel/kexec_core.c | 25 ++---
> kernel/kexec_file.c | 99 ++++++++++++++++++++
> 17 files changed, 248 insertions(+), 280 deletions(-)
>
--
Best regards,
Jinjie
More information about the linux-riscv
mailing list