All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Josh Poimboeuf" <jpoimboe@kernel.org>
Cc: linux-modules@vger.kernel.org
Subject: Re: [PATCH 02/14] objtool/klp: Normalize Module.symvers paths to module names
Date: Mon, 03 Aug 2026 03:37:11 +0000	[thread overview]
Message-ID: <20260803033711.7C6EB1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <dbe1b72931bd3c31b751fd0729613d9f2226fff6.1785727106.git.jpoimboe@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] normalize_modname() returns an interior pointer, causing the original heap allocation base pointer to be lost in read_exports() and __find_modname().
--

--- Patch [2]: [PATCH 02/14] objtool/klp: Normalize Module.symvers paths to module names ---
commit 8f5aadae3b846aa3bb569cfc55ef783d4449690f
Author: Joe Lawrence <joe.lawrence@redhat.com>

objtool/klp: Normalize Module.symvers paths to module names

This commit normalizes Module.symvers object paths to runtime module names
for exported symbols to prevent a crash during livepatch loading. It extracts
the module name processing into a shared normalize_modname() helper.

> diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
> index aeb99d572300c..15d37d955af0e 100644
> --- a/tools/objtool/klp-diff.c
> +++ b/tools/objtool/klp-diff.c
> @@ -83,6 +83,35 @@ static char *escape_str(const char *orig)
[ ... ]
> +static char *normalize_modname(char *name)
> +{
> +	char *slash = strrchr(name, '/');
> +
> +	if (slash)
> +		name = slash + 1;
> +
> +	for (char *c = name; *c; c++) {
> +		if (*c == '-')
> +			*c = '_';
> +		else if (*c == '.') {
> +			*c = '\0';
> +			break;
> +		}
> +	}
> +	return name;
> +}
> +
>  static int read_exports(void)
>  {
[ ... ]
> @@ -150,6 +179,9 @@ static int read_exports(void)
>  			return -1;
>  		}
>  
> +		if (strcmp(export->mod, "vmlinux"))
> +			export->mod = normalize_modname(export->mod);
> +

[Severity: Medium]
Does this assignment leak the original pointer returned by strdup()?

Looking at read_exports(), export->mod is allocated via strdup() right
before this check:

        export->mod = strdup(mod);
        if (!export->mod) {
                ERROR_GLIBC("strdup");
                return -1;
        }

        if (strcmp(export->mod, "vmlinux"))
                export->mod = normalize_modname(export->mod);

When processing module paths with a slash, normalize_modname() returns
an interior pointer (slash + 1).

If this offset pointer overwrites export->mod, the original base
address from strdup() is permanently lost. 

While objtool often relies on process termination for cleanup, if these
strings are ever freed later, passing an interior pointer to free() will
cause an invalid free crash.

Could this be avoided by shifting the string contents in-place with
memmove() instead?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1785727106.git.jpoimboe@kernel.org?part=2

  reply	other threads:[~2026-08-03  3:37 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-03  3:24 [PATCH 00/14] objtool/klp: sympos/module/alternative/etc fixes Josh Poimboeuf
2026-08-03  3:24 ` [PATCH 01/14] objtool/klp: Fix module name normalization for paths with dots Josh Poimboeuf
2026-08-03  5:49   ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2026-08-03  3:24 ` [PATCH 02/14] objtool/klp: Normalize Module.symvers paths to module names Josh Poimboeuf
2026-08-03  3:37   ` sashiko-bot [this message]
2026-08-03  5:37     ` Josh Poimboeuf
2026-08-03  5:49   ` [tip: objtool/core] " tip-bot2 for Joe Lawrence
2026-08-03  3:24 ` [PATCH 03/14] objtool/klp: Fix false module dependencies caused by dead relocs Josh Poimboeuf
2026-08-03  5:49   ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2026-08-03  3:24 ` [PATCH 04/14] objtool/klp: Skip hidden directories when finding objects Josh Poimboeuf
2026-08-03  5:49   ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2026-08-03  3:24 ` [PATCH 05/14] objtool/klp: Add .klp.symid for sympos disambiguation Josh Poimboeuf
2026-08-03  3:41   ` sashiko-bot
2026-08-03  5:42     ` Josh Poimboeuf
2026-08-03  5:49   ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2026-08-03  6:12     ` sashiko-bot
2026-08-03  3:24 ` [PATCH 06/14] objtool/klp: Fix symbol resolution for duplicate data symbols Josh Poimboeuf
2026-08-03  5:49   ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2026-08-03  3:24 ` [PATCH 07/14] module: Add module_kallsyms_on_each_core_symbol() Josh Poimboeuf
2026-08-03  6:24   ` Josh Poimboeuf
2026-08-03  3:24 ` [PATCH 08/14] objtool/klp,livepatch: Resolve module symbols against core kallsyms Josh Poimboeuf
2026-08-03  3:53   ` sashiko-bot
2026-08-03  6:26   ` Josh Poimboeuf
2026-08-03  3:24 ` [PATCH 09/14] objtool/klp: Fix size of empty special section entries Josh Poimboeuf
2026-08-03  3:24 ` [PATCH 10/14] objtool/klp: Ignore replacement offset of empty x86 alternatives Josh Poimboeuf
2026-08-03  3:24 ` [PATCH 11/14] objtool/klp: Explicitly disallow patching or referencing init code/data Josh Poimboeuf
2026-08-03  3:24 ` [PATCH 12/14] objtool/klp: Fix cross-module klp relocation section naming Josh Poimboeuf
2026-08-03  3:24 ` [PATCH 13/14] objtool/klp: Don't match local symbols against exports Josh Poimboeuf
2026-08-03  3:24 ` [PATCH 14/14] objtool/klp: Allow new references to module exports Josh Poimboeuf

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=20260803033711.7C6EB1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=jpoimboe@kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.