Re: [PATCH] livepatch: Fix races between stack check and module load/unload

From: Andrea Parri

Date: Mon Oct 12 2026 - 11:26:47 EST


On Mon, Oct 12, 2026 at 04:49:33PM +0200, Peter Zijlstra wrote:
> On Mon, Oct 12, 2026 at 04:05:45PM +0200, Andrea Parri wrote:
> > @@ -201,12 +202,16 @@ void klp_update_patch_state(struct task_struct *task)
> > /*
> > * Determine whether the given stack trace includes any references to a
> > * to-be-patched or to-be-unpatched function.
> > + *
> > + * Must be called under rcu_read_lock(), see klp_check_stack().
> > */
> > static int klp_check_stack_func(struct klp_func *func, unsigned long *entries,
> > unsigned int nr_entries)
>
> As per always, I much prefer things like lockdep_assert_held() and
> __must_hold() over comments.

Makes sense. For v2 I'll annotate klp_check_stack_func() with
__must_hold_shared(RCU) and add lockdep_assert_in_rcu_read_lock() there,
dropping the comment. For klp_find_ops() the requirement is "klp_mutex
or RCU", which list_for_each_entry_rcu()'s lockdep condition already
checks under PROVE_RCU_LIST, so I'll just drop the comment there.

I'll wait a bit for comments from the livepatch folks before sending v2.

Thanks,
Andrea