]> git.ipfire.org Git - thirdparty/linux.git/commit
LoongArch: Fix address space mismatch in kexec command line lookup
authorGeorge Guo <guodongtai@kylinos.cn>
Thu, 23 Jul 2026 14:27:30 +0000 (22:27 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Thu, 23 Jul 2026 14:27:30 +0000 (22:27 +0800)
commit485ed44db5694d8d2e5027f63ad608e705286f30
tree8a8c6c53805a61c8f9a3cd969fef7a7b46d37376
parent4e8f58620f6717f72f3d88a2c8f25c0c656d0ba7
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.

Cc: stable@vger.kernel.org
Fixes: 4a03b2ac06a5 ("LoongArch: Add kexec support")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202605051639.aEPioXdD-lkp@intel.com/
Co-developed-by: Kexin Liu <liukexin@kylinos.cn>
Signed-off-by: Kexin Liu <liukexin@kylinos.cn>
Signed-off-by: George Guo <guodongtai@kylinos.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
arch/loongarch/kernel/machine_kexec.c