[PATCH] kernel/livepatch/core: Fixed the issue of parsing failure caused by symbols carrying '-' generated by the kpatch software
From: Li kunyu
Date: Thu Jul 24 2025 - 08:41:29 EST
A possible issue with the kpatch software was discovered during testing
in the 6.6 and above kernel:
livepatch: symbol .klp.sym.vmlinux-bringup_idt_table,5438511 has an
incorrectly formatted name.
The "-" between ".vmlinux-bringup_idt_table" cannot be parsed in the
current kernel. Of course, this is a problem generated by the kpatch
software.
Perhaps, we could adopt the approach in the patch to skip the error
symbols compiled by kpatch.
Signed-off-by: Li kunyu <likunyu10@xxxxxxx>
---
kernel/livepatch/core.c | 29 +++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index 0e73fac55f8e..74b07a1b6c1f 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -199,6 +199,7 @@ static int klp_resolve_symbols(Elf_Shdr *sechdrs, const char *strtab,
unsigned long sympos, addr;
bool sym_vmlinux;
bool sec_vmlinux = !strcmp(sec_objname, "vmlinux");
+ bool reload = false;
/*
* Since the field widths for sym_objname and sym_name in the sscanf()
@@ -227,12 +228,32 @@ static int klp_resolve_symbols(Elf_Shdr *sechdrs, const char *strtab,
".klp.sym.%55[^.].%511[^,],%lu",
sym_objname, sym_name, &sympos);
if (cnt != 3) {
- pr_err("symbol %s has an incorrectly formatted name\n",
- strtab + sym->st_name);
- return -EINVAL;
+ if (strchr(strtab + sym->st_name, '-')) {
+ memset(sym_objname, 0, strlen(sym_objname));
+ memset(sym_name, 0, strlen(sym_name));
+ cnt = sscanf(strtab + sym->st_name,
+ ".klp.sym.%55[^-]-%511[^,],%lu",
+ sym_objname, sym_name, &sympos);
+ if (cnt != 3) {
+ pr_err("symbol %s has an incorrectly formatted name, " \
+ "cnt=%d, sym_objname:%s, sym_name:%s\n",
+ strtab + sym->st_name, cnt, sym_objname, sym_name);
+ return -EINVAL;
+ }
+ reload = true;
+ sympos = 1;
+ } else {
+
+ pr_err("symbol %s has an incorrectly formatted name\n",
+ strtab + sym->st_name);
+ return -EINVAL;
+ }
}
- sym_vmlinux = !strcmp(sym_objname, "vmlinux");
+ if (!reload)
+ sym_vmlinux = !strcmp(sym_objname, "vmlinux");
+ else
+ sym_vmlinux = sec_vmlinux;
/*
* Prevent module-specific KLP rela sections from referencing
--
2.47.3