From: sashiko-bot@kernel.org
To: "Zhu, Yi" <chuyee@google.com>,
"Josh Poimboeuf" <jpoimboe@kernel.org>,
"Miroslav Benes" <mbenes@suse.cz>,
"Petr Mladek" <pmladek@suse.com>,
"Joe Lawrence" <joe.lawrence@redhat.com>,
"Song Liu" <song@kernel.org>,
"Wilson Felipe Pereira" <wfelipe@google.com>,
"Dylan Hatch" <dylanbhatch@google.com>
Cc: live-patching@vger.kernel.org
Subject: Re: [PATCH v2 3/3] livepatch: check task stacks against a sorted range table
Date: Fri, 04 Dec 2026 05:25:38 +0000 [thread overview]
Message-ID: <sashiko-outbox-249141@kernel.org> (raw)
In-Reply-To: <370addaa39777621da6828eea8e1d0b17bc26b2e.1796357900.git.chuyee@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] livepatch: klp_discard_nops() frees old_name still referenced
by range table
--
commit 66c10fb7e04a8201e4389a5450561bd570f25d7a
Author: Zhu, Yi <chuyee@google.com>
livepatch: check task stacks against a sorted range table
This commit builds an RCU-published sorted table of active transition
function ranges so klp_check_stack() can check each stack entry with
bsearch() instead of scanning every patched function per task.
> diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c
> index 07e786c2d8123..6756d5ccdea89 100644
> --- a/kernel/livepatch/transition.c
> +++ b/kernel/livepatch/transition.c
[ ... ]
> @@ -241,23 +272,118 @@ static int klp_check_stack_func(struct klp_func *func, unsigned long *entries,
[ ... ]
> +void klp_update_stack_ranges(void)
> +{
[ ... ]
> + klp_for_each_object(klp_transition_patch, obj) {
> + if (!obj->patched)
> + continue;
> + klp_for_each_func(obj, func) {
> + unsigned long func_addr, func_size;
> +
> + klp_func_stack_range(func, &func_addr, &func_size);
> + if (!func_size)
> + continue;
> + new->range[i].start = func_addr;
> + new->range[i].end = func_addr + func_size;
> + new->range[i].name = func->old_name;
> + i++;
> + }
> + }
[Severity: Medium]
Can range->name become a dangling pointer to a freed func->old_name while a
reader still uses an older klp_stack_ranges table?
For a dynamic NOP in a replacing patch, func->old_name is freed synchronously
with kfree() in klp_free_func_nop(), whereas klp_stack_ranges is freed with
kvfree_rcu(). In klp_complete_transition(), klp_discard_nops() runs before
klp_synchronize_transition() and before clearing klp_stack_ranges.
If a target module patched by a dynamic NOP unloads during a transition,
klp_module_going() unpatches that object before replacing the table. A
concurrent __klp_sched_try_switch() reader can still hold the old table T1
when a forced transition completes:
CPU0 CPU1
klp_module_going()
klp_cleanup_module_patches_limited()
obj->patched = false
__klp_sched_try_switch()
klp_check_stack()
ranges = klp_stack_ranges (T1)
klp_update_stack_ranges()
rcu_replace_pointer(..., T2)
kvfree_rcu(T1, rcu)
mutex_unlock(&klp_mutex)
klp_force_transition()
klp_complete_transition()
klp_discard_nops()
klp_free_func_nop()
kfree(func->old_name)
klp_try_switch_task()
pr_debug(..., old_name)
<-- use-after-free
Because obj->patched is already false and klp_resched_disable() does not wait
for preemption-disabled readers already in __klp_sched_try_switch(),
klp_discard_nops() can free func->old_name with no RCU grace period. If
CPU1's stack matches the stale range, pr_debug() reads freed memory.
Clearing klp_stack_ranges and synchronizing before klp_discard_nops(), or
freeing func->old_name via RCU, would keep the string alive for readers.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796357900.git.chuyee@google.com?part=3
prev parent reply other threads:[~2026-12-04 5:25 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 0:35 [PATCH 0/2] livepatch: make the transition stack check scale with patch size Zhu, Yi
2026-12-04 0:35 ` [PATCH 1/2] livepatch: look up klp_ops in a hash table Zhu, Yi
2026-12-04 0:51 ` sashiko-bot
2026-12-04 0:35 ` [PATCH 2/2] livepatch: check task stacks against a sorted range table Zhu, Yi
2026-12-04 0:59 ` sashiko-bot
2026-12-04 4:51 ` [PATCH v2 0/3] livepatch: make the transition stack check scale with patch size Zhu, Yi
2026-12-04 4:51 ` [PATCH v2 1/3] livepatch: fix racy klp_ops lookup in klp_check_stack_func() Zhu, Yi
2026-12-04 4:51 ` [PATCH v2 2/3] livepatch: look up klp_ops in a hash table Zhu, Yi
2026-12-04 4:51 ` [PATCH v2 3/3] livepatch: check task stacks against a sorted range table Zhu, Yi
2026-12-04 5:25 ` sashiko-bot [this message]
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=sashiko-outbox-249141@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=chuyee@google.com \
--cc=dylanbhatch@google.com \
--cc=joe.lawrence@redhat.com \
--cc=jpoimboe@kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=pmladek@suse.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=song@kernel.org \
--cc=wfelipe@google.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