The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: x86@kernel.org
Cc: "Peter Zijlstra" <peterz@infradead.org>,
	live-patching@vger.kernel.org,
	"Joe Lawrence" <joe.lawrence@redhat.com>,
	"Miroslav Benes" <mbenes@suse.cz>, "Song Liu" <song@kernel.org>,
	linux-kernel@vger.kernel.org, "Petr Mladek" <pmladek@suse.com>
Subject: Re: [PATCH v2 4/7] objtool/klp: Explicitly disallow patching or referencing init code/data
Date: Wed, 05 Aug 2026 15:12:02 +0000	[thread overview]
Message-ID: <20260805151203.D96FD1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <a8edecfad944523b2b1e294b66c28c22fc50dad3.1785939903.git.jpoimboe@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The `.init` safety check is bypassed for exported module symbols, allowing livepatches to silently reference freed init memory.
--

--- Patch [4]: [PATCH v2 4/7] objtool/klp: Explicitly disallow patching or referencing init code/data ---
commit fe2fe6cc51b729f1eb6addc3f9e161e818ce482f
Author: Josh Poimboeuf <jpoimboe@kernel.org>

objtool/klp: Explicitly disallow patching or referencing init code/data

This commit explicitly prevents the patching and referencing of init code
and data to avoid edge cases. It introduces an init check in the sympos
resolution to handle targets that might have their init section freed.

> diff --git a/tools/objtool/klp-sympos.c b/tools/objtool/klp-sympos.c
> index bbfae516d3395..dfca9dd746812 100644
> --- a/tools/objtool/klp-sympos.c
> +++ b/tools/objtool/klp-sympos.c
[ ... ]
> @@ -376,6 +381,11 @@ unsigned long klp_find_sympos(struct elf *elf, struct symbol *sym)
>  	bool has_dup = false;
>  	struct symbol *s;
>  
> +	if (is_init_sym(sym)) {
> +		ERROR("%s: can't patch or reference init code/data", sym->name);
> +		return ULONG_MAX;
> +	}
> +

[Severity: High]
Does this check adequately protect against exported module symbols?

Looking at clone_reloc_klp() in tools/objtool/klp-diff.c, if the symbol
is exported, the code skips calling klp_find_sympos() entirely:

tools/objtool/klp-diff.c:clone_reloc_klp() {
    if (export) {
        sym_modname = export->mod;
        sym_orig_name = export->sym;
        sympos = 0;
    } else {
        sym_modname = find_modname(e);
        if (!sym_modname)
            return -1;

        sym_orig_name = patched_sym->twin->name;
        sympos = klp_find_sympos(e->orig, patched_sym->twin);
    ...
}

If a livepatch object references an exported init symbol from a module,
would it bypass this new safety check and potentially result in a reference
to freed init memory once the target module finishes initialization?

>  	if (sym->bind != STB_LOCAL)
>  		return 0;
>

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

  reply	other threads:[~2026-08-05 15:12 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05 14:29 [PATCH v2 0/7] objtool/klp: sympos/module/alternative/etc fixes Josh Poimboeuf
2026-08-05 14:29 ` [PATCH v2 1/7] objtool/klp: Fix vmlinux .klp.symid link error for .no_trim_symbol symbols Josh Poimboeuf
2026-08-05 18:30   ` Song Liu
2026-08-05 14:29 ` [PATCH v2 2/7] objtool/klp: Fix size of empty special section entries Josh Poimboeuf
2026-08-05 20:36   ` Song Liu
2026-08-06  5:11     ` Josh Poimboeuf
2026-08-06 20:51       ` Song Liu
2026-08-05 14:29 ` [PATCH v2 3/7] objtool/klp: Ignore replacement offset of empty x86 alternatives Josh Poimboeuf
2026-08-05 20:51   ` Song Liu
2026-08-06  5:14     ` Josh Poimboeuf
2026-08-05 14:29 ` [PATCH v2 4/7] objtool/klp: Explicitly disallow patching or referencing init code/data Josh Poimboeuf
2026-08-05 15:12   ` sashiko-bot [this message]
2026-08-06  5:26     ` Josh Poimboeuf
2026-08-05 14:29 ` [PATCH v2 5/7] objtool/klp: Fix cross-module klp relocation section naming Josh Poimboeuf
2026-08-05 22:23   ` Song Liu
2026-08-05 14:29 ` [PATCH v2 6/7] objtool/klp: Don't match local symbols against exports Josh Poimboeuf
2026-08-05 20:59   ` Song Liu
2026-08-05 14:29 ` [PATCH v2 7/7] objtool/klp: Allow new references to module exports Josh Poimboeuf
2026-08-05 22:24   ` Song Liu
2026-08-06 15:57 ` [PATCH v2 0/7] objtool/klp: sympos/module/alternative/etc fixes Joe Lawrence
2026-08-07  1:25   ` 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=20260805151203.D96FD1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --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=sashiko-reviews@lists.linux.dev \
    --cc=song@kernel.org \
    --cc=x86@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox