FAILED: patch "[PATCH] arm64: kexec: use a typed entry to fix kCFI oops" failed to apply to 6.1-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.1-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-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x b059e957d07b3cab92eef4656988244043f5769a
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026120258-brunt-heaviness-372e@gregkh' --subject-prefix 'PATCH 6.1.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From b059e957d07b3cab92eef4656988244043f5769a Mon Sep 17 00:00:00 2001
From: Ben Cressey <[email protected]>
Date: Wed, 11 Nov 2026 15:26:04 -0800
Subject: [PATCH] arm64: kexec: use a typed entry to fix kCFI oops
An arm64 Linux kernel built with CONFIG_CFI=y oopses after "Bye!" on every kexec that relocates the image. Crash images load in place and are not affected. The oops reproduces under QEMU:
Unable to handle kernel paging request at virtual address 00000000544bfffc pc : machine_kexec+0x104/0x274 Code: d5182008 d5033fdf aa1303e0 f9418a68 (b85fc110)
b85fc110 is "ldur w16, [x8, #-4]", the kCFI check's load of the type hash in front of the callee. Commit efc2d0f20a9d ("arm64: kexec: keep MMU enabled during kexec relocation") made machine_kexec() call the control page's copy of arm64_relocate_new_kernel() indirectly, while TTBR0 maps only that page. The copy starts at the page's first byte, so the load faults. SYM_CODE_START() also gives the routine no hash.
SYM_TYPED_FUNC_START() emits the hash inside .kexec_relocate.text, and machine_kexec_post_load() already copies that whole section, at most 4 KiB, to the page's start, so the mapped page holds both hash and entry.
The ASSERT from commit dc4824faa265 ("arm64: avoid executing padding bytes during kexec / hibernation") kept the entry first, since C branched to the page's start. Relax it, so the entry need only be in the section.
Fix by typing the routine with SYM_TYPED_FUNC_START() and a C prototype, and entering the copy at the symbol's offset in the section.
The code is Kees Cook's, as posted in review, with two comments and the ASSERT message reworded.
An LLM diagnosed the oops.
arch/arm64/include/asm/kexec.h +2 -0
@@ -100,6 +100,8 @@ void cpu_soft_restart(unsigned long el2_switch, unsigned long entry, unsigned long arg0, unsigned long arg1, unsigned long arg2); +void arm64_relocate_new_kernel (struct kimage *kimage); +int machine_kexec_post_load (struct kimage *image);#define machine_kexec_post_load machine_kexec_post_load#endif
arch/arm64/kernel/machine_kexec.c +5 -2
@@ -147,9 +147,12 @@ int machine_kexec_post_load(struct kimage *kimage) kimage->arch.ttbr1 =__pa (trans_pgd); kimage->arch.zero_page =__pa_symbol (empty_zero_page); +/* Copy the whole section: a kCFI hash may precede the entry point */ reloc_size = __relocate_new_kernel_end - __relocate_new_kernel_start;memcpy (reloc_code, __relocate_new_kernel_start, reloc_size); - kimage->arch.kern_reloc =__pa (reloc_code); + kimage->arch.kern_reloc =__pa (reloc_code) + + ((unsigned long )arm64_relocate_new_kernel - + (unsigned long )__relocate_new_kernel_start); rc =trans_pgd_idmap_page (&info, &kimage->arch.ttbr0, &kimage->arch.t0sz, reloc_code);if (rc)
@@ -204,7 +207,7 @@ void machine_kexec(struct kimage *kimage)restart (is_hyp_nvhe (), kimage->start, kimage->arch.dtb_mem,0 ,0 ); }else { -void (*kernel_reloc)(struct kimage *kimage); +typeof (arm64_relocate_new_kernel) *kernel_reloc;if (is_hyp_nvhe ())__hyp_set_vectors (kimage->arch.el2_vectors);
arch/arm64/kernel/relocate_kernel.S +7 -4
@@ -8,6 +8,7 @@ * Pasha Tatashin <[email protected]> */ +#include <linux/cfi_types.h> #include <linux/kexec.h> #include <linux/linkage.h>
@@ -32,11 +33,13 @@ * new image to its final location. To assure that the * arm64_relocate_new_kernel routine which does that copy is not overwritten, * all code and data needed by arm64_relocate_new_kernel must be between the - * symbols arm64_relocate_new_kernel and arm64_relocate_new_kernel_end. The - * machine_kexec() routine will copy arm64_relocate_new_kernel to the kexec + * symbols __relocate_new_kernel_start and __relocate_new_kernel_end. The + * machine_kexec_post_load() routine will copy that whole region to the kexec * safe memory that has been set up to be preserved during the copy operation. + * + * Called indirectly by machine_kexec(), this routine needs a kCFI type hash. */ -SYM_CODE_START(arm64_relocate_new_kernel) +SYM_TYPED_FUNC_START(arm64_relocate_new_kernel) /* * The kimage structure isn't allocated specially and may be clobbered * during relocation. We must load any values we need from it prior to
@@ -98,4 +101,4 @@ SYM_CODE_START(arm64_relocate_new_kernel) mov x2, xzr mov x3, xzr br x28 /* Jumps from el1 */ -SYM_CODE_END(arm64_relocate_new_kernel) +SYM_FUNC_END(arm64_relocate_new_kernel)
arch/arm64/kernel/vmlinux.lds.S +3 -2
@@ -440,6 +440,7 @@ ASSERT(swapper_pg_dir - tramp_pg_dir == TRAMP_SWAPPER_OFFSET, ASSERT(__relocate_new_kernel_end - __relocate_new_kernel_start <= SZ_4K, "kexec relocation code is bigger than 4 KiB") ASSERT(KEXEC_CONTROL_PAGE_SIZE >= SZ_4K, "KEXEC_CONTROL_PAGE_SIZE is broken") -ASSERT(__relocate_new_kernel_start == arm64_relocate_new_kernel, - "kexec control page does not start with arm64_relocate_new_kernel") +ASSERT(arm64_relocate_new_kernel >= __relocate_new_kernel_start && + arm64_relocate_new_kernel < __relocate_new_kernel_end, + "kexec relocation code does not contain arm64_relocate_new_kernel") #endif