From: Wilson Felipe Pereira <wfelipe@google.com>
To: Josh Poimboeuf <jpoimboe@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Miroslav Benes <mbenes@suse.cz>, Petr Mladek <pmladek@suse.com>,
Joe Lawrence <joe.lawrence@redhat.com>,
Song Liu <song@kernel.org>
Cc: live-patching@vger.kernel.org, linux-kernel@vger.kernel.org,
Dylan Hatch <dylanbhatch@google.com>, Yi Zhu <chuyee@google.com>,
Wilson Felipe Pereira <wfelipe@google.com>
Subject: [PATCH 1/2] objtool/klp: Disambiguate global symbols colliding with local symbols
Date: Tue, 17 Nov 2026 00:08:31 +0000 [thread overview]
Message-ID: <20261117000835.1992893-2-wfelipe@google.com> (raw)
In-Reply-To: <20261117000835.1992893-1-wfelipe@google.com>
klp_find_sympos() returns 0 for any non-STB_LOCAL symbol, symid_needed()
skips non-local symbols when emitting .klp.symid entries for vmlinux.o,
and clone_reloc_klp() hardcodes sympos = 0 when a relocation targets a
restricted or module export.
However, a global symbol in one translation unit can share its name with a
static (STB_LOCAL) symbol in another translation unit (for example,
cgroup_storage_lookup in kernel/bpf/local_storage.c vs
kernel/bpf/bpf_cgrp_storage.c). At runtime, both
kallsyms_on_each_match_symbol() and module_kallsyms_on_each_symbol() count
local and global symbols together, so emitting sympos 0 for the global
symbol fails module load in klp_find_object_symbol() with 'unresolvable
ambiguity for symbol'.
Allow defined non-local symbols to receive .klp.symid entries when
duplicate names exist in vmlinux.o, compute sympos for defined non-local
symbols in klp_find_sympos() (returning 0 when unique and skipping
undefined and non-alloc symbols), and resolve sympos via klp_find_sympos()
in clone_reloc_klp() when the exported target is defined in the patched
object.
Signed-off-by: Wilson Felipe Pereira <wfelipe@google.com>
---
tools/objtool/klp-diff.c | 11 +++++++++++
tools/objtool/klp-symid.c | 2 +-
tools/objtool/klp-sympos.c | 9 ++++++---
3 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index 34da55e45609..37ad315d00af 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -1404,9 +1404,20 @@ static int clone_reloc_klp(struct elfs *e, struct reloc *patched_reloc,
*/
if (export) {
+ const char *modname = find_modname(e);
+
+ if (!modname)
+ return -1;
+
sym_modname = export->mod;
sym_orig_name = export->sym;
sympos = 0;
+ if (!strcmp(export->mod, modname) &&
+ patched_sym->twin && !is_undef_sym(patched_sym->twin)) {
+ sympos = klp_find_sympos(e->orig, patched_sym->twin);
+ if (sympos == ULONG_MAX)
+ return -1;
+ }
} else {
sym_modname = find_modname(e);
if (!sym_modname)
diff --git a/tools/objtool/klp-symid.c b/tools/objtool/klp-symid.c
index b19f76dff13e..d01c13b8ffa8 100644
--- a/tools/objtool/klp-symid.c
+++ b/tools/objtool/klp-symid.c
@@ -52,7 +52,7 @@ static bool symid_needed(struct elf *elf, struct symbol *sym)
{
struct symbol *s;
- if (!is_local_sym(sym) || is_undef_sym(sym))
+ if (is_undef_sym(sym))
return false;
if (!is_func_sym(sym) && !is_object_sym(sym))
diff --git a/tools/objtool/klp-sympos.c b/tools/objtool/klp-sympos.c
index dfca9dd74681..087892ef3593 100644
--- a/tools/objtool/klp-sympos.c
+++ b/tools/objtool/klp-sympos.c
@@ -381,14 +381,14 @@ unsigned long klp_find_sympos(struct elf *elf, struct symbol *sym)
bool has_dup = false;
struct symbol *s;
+ if (is_undef_sym(sym))
+ return 0;
+
if (is_init_sym(sym)) {
ERROR("%s: can't patch or reference init code/data", sym->name);
return ULONG_MAX;
}
- if (sym->bind != STB_LOCAL)
- return 0;
-
/*
* vmlinux: the final link reorders symbols relative to vmlinux.o,
* so the position needs to be derived from the linked orig vmlinux via
@@ -403,6 +403,9 @@ unsigned long klp_find_sympos(struct elf *elf, struct symbol *sym)
* module_kallsyms_on_each_symbol().
*/
for_each_sym(elf, s) {
+ if (is_sec_sym(s) || is_file_sym(s) || is_undef_sym(s) ||
+ !(s->sec->sh.sh_flags & SHF_ALLOC))
+ continue;
if (!strcmp(s->name, sym->name)) {
nr_matches++;
if (s == sym)
--
2.56.1.703.gf848ed807c-goog
next prev parent reply other threads:[~2026-11-17 0:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 0:08 [PATCH 0/2] objtool/klp: Fix sympos for global/local symbol collisions Wilson Felipe Pereira
2026-11-17 0:08 ` Wilson Felipe Pereira [this message]
2026-11-17 0:25 ` [PATCH 1/2] objtool/klp: Disambiguate global symbols colliding with local symbols sashiko-bot
2026-11-17 0:08 ` [PATCH 2/2] objtool/klp: Add test for global/local symbol name collisions Wilson Felipe Pereira
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261117000835.1992893-2-wfelipe@google.com \
--to=wfelipe@google.com \
--cc=chuyee@google.com \
--cc=dylanbhatch@google.com \
--cc=joe.lawrence@redhat.com \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=peterz@infradead.org \
--cc=pmladek@suse.com \
--cc=song@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.