Re: [PATCH v2 3/3] livepatch: check task stacks against a sorted range table
From: Zhu, Yi
Date: Fri Dec 04 2026 - 13:02:59 EST
On Fri, Dec 04, 2026 at 05:25:38AM +0000, sashiko-bot@xxxxxxxxxx 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