mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Josh Poimboeuf <jpoimboe@kernel.org>
To: Wilson Felipe Pereira <wfelipe@google.com>
Cc: 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>,
	live-patching@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Dylan Hatch <dylanbhatch@google.com>, Yi Zhu <chuyee@google.com>
Subject: Re: [PATCH 1/2] objtool/klp: Disambiguate global symbols colliding with local symbols
Date: Sat, 21 Nov 2026 17:19:34 -0800	[thread overview]
Message-ID: <awJCWTSXV0J11rqP@jpoimboe> (raw)
In-Reply-To: <20261117000835.1992893-2-wfelipe@google.com>

On Tue, Nov 17, 2026 at 12:08:31AM +0000, Wilson Felipe Pereira wrote:
> 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)

This could be simplified a bit?

	if (export) {
		sym_modname = export->mod;
		sym_orig_name = export->sym;
	} else {
		sym_modname = find_modname(e);
		if (!sym_modname)
			return -1;

		sym_orig_name = patched_sym->twin->name;
	}

	sympos = 0;
	if (patched_sym->twin) {
		sympos = klp_find_sympos(e->orig, patched_sym->twin);
		if (sympos == ULONG_MAX)
			return -1;
	}

-- 
Josh

  reply	other threads:[~2026-11-22  1:19 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 ` [PATCH 1/2] objtool/klp: Disambiguate global symbols colliding with local symbols Wilson Felipe Pereira
2026-11-22  1:19   ` Josh Poimboeuf [this message]
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=awJCWTSXV0J11rqP@jpoimboe \
    --to=jpoimboe@kernel.org \
    --cc=chuyee@google.com \
    --cc=dylanbhatch@google.com \
    --cc=joe.lawrence@redhat.com \
    --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 \
    --cc=wfelipe@google.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®