[tip: objtool/core] objtool/klp: Fix module name normalization for paths with dots

"tip-bot2 for Josh Poimboeuf" <[email protected]> Mon, 03 Aug 2026 05:49:45 -0000
Newsgroups org.kernel.vger.live-patching,org.kernel.vger.linux-kernel
Message-ID <178573618517.1210945.6163112616985750312.tip-bot2@tip-bot2>
The following commit has been merged into the objtool/core branch of tip:

Commit-ID:     165affd6f095323d953b0ed5823ec4d0db3b7d0d
Gitweb:        https://git.kernel.org/tip/165affd6f095323d953b0ed5823ec4d0db3=
b7d0d
Author:        Josh Poimboeuf <[email protected]>
AuthorDate:    Sun, 02 Aug 2026 20:24:23 -07:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Mon, 03 Aug 2026 07:12:38 +02:00

objtool/klp: Fix module name normalization for paths with dots

When .modinfo has no "name=3D" tag, __find_modname() falls back to
converting the object's build-tree path to a runtime module name by
stripping directory components, converting '-' to '_' and truncating the
file extension.

It does all that in a single pass over the entire path, so the first dot
anywhere in the path ends the name.  For an object built in a directory
whose name contains a dot, e.g. "drivers/foo-1.0/bar.o", the result is a
bogus module name.

Strip the directory components up front so only the basename is scanned
for the extension separator.

Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffing =
object files")
Reported-by: Sashiko <[email protected]>
Signed-off-by: Josh Poimboeuf <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
Cc: [email protected]
Link: https://patch.msgid.link/9017b4609553bed16674e8f924d34691cbc2b2c1.17857=
[email protected]
---
 tools/objtool/klp-diff.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index f8787d7..aeb99d5 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -1140,7 +1140,7 @@ static struct export *find_export(struct symbol *sym)
 static const char *__find_modname(struct elfs *e)
 {
 	struct section *sec;
-	char *name;
+	char *name, *slash;
=20
 	sec =3D find_section_by_name(e->orig, ".modinfo");
 	if (!sec) {
@@ -1158,10 +1158,12 @@ static const char *__find_modname(struct elfs *e)
 		return NULL;
 	}
=20
+	slash =3D strrchr(name, '/');
+	if (slash)
+		name =3D slash + 1;
+
 	for (char *c =3D name; *c; c++) {
-		if (*c =3D=3D '/')
-			name =3D c + 1;
-		else if (*c =3D=3D '-')
+		if (*c =3D=3D '-')
 			*c =3D '_';
 		else if (*c =3D=3D '.') {
 			*c =3D '\0';