Live Patching
 help / color / mirror / Atom feed
From: "Zhu, Yi" <chuyee@google.com>
To: sashiko-bot@kernel.org
Cc: 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>,
	 live-patching@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 3/3] livepatch: check task stacks against a sorted range table
Date: Fri,  4 Dec 2026 18:02:21 +0000	[thread overview]
Message-ID: <20261204180221.1862093-1-chuyee@google.com> (raw)
In-Reply-To: <sashiko-outbox-249141@kernel.org>

On Fri, Dec 04, 2026 at 05:25:38AM +0000, sashiko-bot@kernel.org wrote:
> [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.

[ ... ]

> 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.

This can only happen with a forced transition, and it isn't new with
this patch.

Without force, the transition can't complete while a task is still
failing its own check in __klp_sched_try_switch(): it hasn't switched,
and other CPUs get -EBUSY trying to switch it while it runs.

With klp_force_transition(), the existing per-function check has the
same window and is worse off: it walks the NOP funcs that
klp_discard_nops() frees, not just their names. Like the race fixed by
patch 1, this dates from e3ff7c609f39 ("livepatch,sched: Add livepatch
task switching to cond_resched()").

A klp_synchronize_transition() before klp_discard_nops() in
klp_complete_transition() would fix both. I can send that as a
separate fix.

Thanks,
-yi

      reply	other threads:[~2026-12-04 18:02 UTC|newest]

Thread overview: 11+ 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
2026-12-04 18:02       ` Zhu, Yi [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=20261204180221.1862093-1-chuyee@google.com \
    --to=chuyee@google.com \
    --cc=dylanbhatch@google.com \
    --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=pmladek@suse.com \
    --cc=sashiko-bot@kernel.org \
    --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