From: Petr Mladek <pmladek@suse.com>
To: sashiko-reviews@lists.linux.dev
Cc: Harry Hsu <x90613@gmail.com>,
joe.lawrence@redhat.com, mbenes@suse.cz, jpoimboe@kernel.org,
song@kernel.org, shuah@kernel.org, live-patching@vger.kernel.org,
jikos@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 1/5] livepatch: Fail object initialization on duplicate patched function
Date: Tue, 8 Sep 2026 15:02:11 +0200 [thread overview]
Message-ID: <aqAHU9Qecqvl88VT@pathway> (raw)
In-Reply-To: <20260908121744.81D641F00A3A@smtp.kernel.org>
On Tue 2026-09-08 12:17:44, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] Atomic replace patches will fail to load if previous patches targeted aliased functions.
> --
>
> commit e5553650270f93e11fe885d264a3829802223d3a
> Author: Harry Hsu <x90613@gmail.com>
>
> livepatch: Fail object initialization on duplicate patched function
>
> This commit introduces a check to prevent patching multiple aliases of a
> function within a single livepatch. It fails object initialization if aliases
> resolving to the same address are detected.
>
> > diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
> > index a240d1144e89c..a6762cbe74b70 100644
> > --- a/kernel/livepatch/core.c
> > +++ b/kernel/livepatch/core.c
> [ ... ]
> > @@ -885,6 +885,21 @@ static int klp_init_object_loaded(struct klp_patch *patch,
> > if (ret)
> > return ret;
> >
> > + /*
> > + * Aliased symbols share one address, so they would resolve to
> > + * the same klp_ops and stack up on a single ops->func_stack,
> > + * leaving the redirection ambiguous.
> > + */
> > + klp_for_each_func(obj, prev_func) {
> > + if (prev_func == func)
> > + break;
> > + if (prev_func->old_func == func->old_func) {
> > + pr_err("'%s' and '%s' resolve to the same address, aliased symbols are not supported\n",
> > + prev_func->old_name, func->old_name);
> > + return -EINVAL;
>
> [Severity: High]
> Will this check inadvertently reject nop functions generated by an atomic
> replace patch when previous patches targeted aliased functions?
>
> If previously loaded livepatches targeted aliased functions (for example, one
> patch targets __do_sys_fork and another targets __x64_sys_fork), they were
> permitted since they resided in different patches.
>
> When an atomic replace patch is loaded, klp_add_nops() loops over all
> previously patched functions and adds nops for them to the new patch. Since
> nop deduplication is based on old_name, nops for both aliases are added.
>
> Later, this check in klp_init_object_loaded() resolves their addresses and
> finds duplicate old_func addresses. This causes the initialization to fail
> with -EINVAL, which prevents the system from atomically replacing existing
> livepatches and might force a reboot if the old patches cannot be safely
> disabled manually.
Wow, this is a nice catch. I would say that it is a corner case but
the problem seems to exist. Now, the question is how to deal with it.
I see three possibilities:
1. We might detect the aliases in klp_find_func() and create only
one "nop" entry or do not create it all.
2. The problem might be easier to solve after adding
the provides/obsoletes, aka replace set, feature [1].
It should prevent loading the other livepatch for the aliased
symbol in the 1st place.
3. Just document the problem as a limitation. It might be hit only
when installing more liveapatches in parallel that current
wild way.
I personally prefer to wait for the provides/requires feature.
[1] https://lore.kernel.org/all/20260607131659.29281-1-laoar.shao@gmail.com/
Best Regards,
Petr
> > + }
> > + }
> > +
> > ret = kallsyms_lookup_size_offset((unsigned long)func->old_func,
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260908120325.299649-1-pmladek@suse.com?part=1
next prev parent reply other threads:[~2026-09-08 13:02 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-08 12:03 [PATCH v4 0/5] " Petr Mladek
2026-09-08 12:03 ` [PATCH v4 1/5] " Petr Mladek
2026-09-08 12:17 ` sashiko-bot
2026-09-08 13:02 ` Petr Mladek [this message]
2026-09-08 12:03 ` [PATCH v4 2/5] selftests/livepatch: Test rejection of aliased symbols in one object Petr Mladek
2026-09-08 12:03 ` [PATCH v4 3/5] livepatch: Move code for updating livepatch object relocations Petr Mladek
2026-09-08 12:03 ` [PATCH v4 4/5] livepatch: Clear relocations when klp_apply_object_relocs() fails Petr Mladek
2026-09-08 12:18 ` sashiko-bot
2026-09-08 13:29 ` Petr Mladek
2026-09-08 12:03 ` [PATCH v4 5/5] livepatch: Clean up klp_init_object_loaded() when fails Petr Mladek
2026-09-08 12:25 ` sashiko-bot
2026-09-08 13:32 ` Petr Mladek
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=aqAHU9Qecqvl88VT@pathway \
--to=pmladek@suse.com \
--cc=jikos@kernel.org \
--cc=joe.lawrence@redhat.com \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=x90613@gmail.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®