FAILED: patch "[PATCH] LoongArch: Fix address space mismatch in kexec command line" failed to apply to 6.12-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.12-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.12.y
git checkout FETCH_HEAD
git cherry-pick -x 485ed44db5694d8d2e5027f63ad608e705286f30
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026072914-impromptu-excretion-26f0@gregkh' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 485ed44db5694d8d2e5027f63ad608e705286f30 Mon Sep 17 00:00:00 2001
From: George Guo <[email protected]>
Date: Thu, 23 Jul 2026 22:27:30 +0800
Subject: [PATCH] LoongArch: Fix address space mismatch in kexec command line
lookup
When searching the loaded segments for the "kexec" command line marker, the kexec_load(2) path (file_mode == 0) passes the user-space segment buffer straight to strncmp() through a bogus (char __user *) cast. This dereferences a user pointer in kernel context, which is wrong and is flagged by sparse:
arch/loongarch/kernel/machine_kexec.c:84:51: sparse: incorrect type in argument 2 (different address spaces) @@ expected char const * @@ got char [noderef] __user *
Here copy the marker-sized prefix of each segment into a small on-stack buffer with copy_from_user() before comparing, and skip segments that fault. The subsequent copy_from_user() that stages the full command line into the safe area is left unchanged.
arch/loongarch/kernel/machine_kexec.c +4 -1
@@ -42,6 +42,7 @@ static unsigned long first_ind_entry;int machine_kexec_prepare (struct kimage *kimage) {int i; +char head[8 ];char *bootloader ="kexec" ;void *cmdline_ptr = (void *)KEXEC_CMDLINE_ADDR ;
@@ -59,7 +60,9 @@ int machine_kexec_prepare(struct kimage *kimage) }else {/* Find the command line */ for (i =0 ; i < kimage->nr_segments; i++) { -if (!strncmp (bootloader, (char __user *)kimage->segment[i].buf,strlen (bootloader))) { +if (copy_from_user (head, kimage->segment[i].buf,strlen (bootloader))) +continue ; +if (!strncmp (bootloader, head,strlen (bootloader))) {if (!copy_from_user (cmdline_ptr, kimage->segment[i].buf,COMMAND_LINE_SIZE )) kimage->arch.cmdline_ptr = (unsigned long )cmdline_ptr;break ;