From: Song Liu <song@kernel.org>
To: <live-patching@vger.kernel.org>
Cc: <jpoimboe@kernel.org>, <jikos@kernel.org>, <mbenes@suse.cz>,
<pmladek@suse.com>, <joe.lawrence@redhat.com>,
<kernel-team@meta.com>, Song Liu <song@kernel.org>
Subject: [PATCH] livepatch: match symbols exactly in klp_find_object_symbol()
Date: Fri, 2 Jun 2023 16:24:01 -0700 [thread overview]
Message-ID: <20230602232401.3938285-1-song@kernel.org> (raw)
With CONFIG_LTO_CLANG, kallsyms.c:cleanup_symbol_name() removes symbols
suffixes during comparison. This is problematic for livepatch, as
kallsyms_on_each_match_symbol may find multiple matches for the same
symbol, and fail with:
livepatch: unresolvable ambiguity for symbol 'xxx' in object 'yyy'
Fix this by using kallsyms_on_each_symbol instead, and matching symbols
exactly.
Signed-off-by: Song Liu <song@kernel.org>
---
kernel/livepatch/core.c | 17 +++++------------
1 file changed, 5 insertions(+), 12 deletions(-)
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index 61328328c474..507e1e2e4290 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -125,10 +125,13 @@ struct klp_find_arg {
unsigned long pos;
};
-static int klp_match_callback(void *data, unsigned long addr)
+static int klp_find_callback(void *data, const char *name, unsigned long addr)
{
struct klp_find_arg *args = data;
+ if (strcmp(args->name, name))
+ return 0;
+
args->addr = addr;
args->count++;
@@ -143,16 +146,6 @@ static int klp_match_callback(void *data, unsigned long addr)
return 0;
}
-static int klp_find_callback(void *data, const char *name, unsigned long addr)
-{
- struct klp_find_arg *args = data;
-
- if (strcmp(args->name, name))
- return 0;
-
- return klp_match_callback(data, addr);
-}
-
static int klp_find_object_symbol(const char *objname, const char *name,
unsigned long sympos, unsigned long *addr)
{
@@ -166,7 +159,7 @@ static int klp_find_object_symbol(const char *objname, const char *name,
if (objname)
module_kallsyms_on_each_symbol(objname, klp_find_callback, &args);
else
- kallsyms_on_each_match_symbol(klp_match_callback, name, &args);
+ kallsyms_on_each_symbol(klp_find_callback, &args);
/*
* Ensure an address was found. If sympos is 0, ensure symbol is unique;
--
2.34.1
next reply other threads:[~2023-06-02 23:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-02 23:24 Song Liu [this message]
2023-06-05 16:39 ` [PATCH] livepatch: match symbols exactly in klp_find_object_symbol() Josh Poimboeuf
2023-06-09 7:09 ` Petr Mladek
2023-06-09 16:35 ` Song Liu
2023-06-13 15:16 ` Petr Mladek
2023-06-15 16:58 ` Song Liu
2023-06-16 1:23 ` Leizhen (ThunderTown)
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=20230602232401.3938285-1-song@kernel.org \
--to=song@kernel.org \
--cc=jikos@kernel.org \
--cc=joe.lawrence@redhat.com \
--cc=jpoimboe@kernel.org \
--cc=kernel-team@meta.com \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=pmladek@suse.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).