Re: [PATCH v2] livepatch: Reject livepatches with aliased old_func
From: Josh Poimboeuf
Date: Thu Aug 27 2026 - 18:58:08 EST
On Sun, Aug 23, 2026 at 02:07:34PM +0800, Harry Hsu wrote:
> Several symbols can share one address:
>
> ffffffff8ed7fef0 t __do_sys_fork
> ffffffff8ed7fef0 T __ia32_sys_fork
> ffffffff8ed7fef0 T __x64_sys_fork
>
> klp_find_ops() looks the ops up by func->old_func, i.e. by address, so
> two klp_funcs of the same livepatch naming two of these symbols resolve
> to the same klp_ops and are both pushed onto one ops->func_stack.
>
> This breaks the assumption that a single livepatch contributes at most
> one entry to any func_stack. klp_ftrace_handler() picks the entry at
> the top of the stack, but when both entries belong to the same livepatch
> there is nothing that says which of them should be used in the PATCHED
> state, and the UNPATCHED state has to end up at the original function
> either way. klp_check_stack_func() cannot tell them apart either: it
> asks whether the preceding entry is the original function or another
> livepatch's replacement, and an aliased sibling is neither.
>
> Patching two aliases of one function from a single livepatch was never
> meaningful, so reject it while the object is being initialized rather
> than leave the redirection undefined. Compare the resolved old_func of
> each klp_func against the ones already resolved for the same klp_object
> and return -EINVAL on a match, naming both symbols so that the offending
> pair can be found in the livepatch source.
>
> Fixes: 3c33f5b99d68 ("livepatch: support for repatching a function")
> Suggested-by: Petr Mladek <pmladek@xxxxxxxx>
> Signed-off-by: Harry Hsu <x90613@xxxxxxxxx>
> ---
> v2:
> - Drop the klp_check_stack_func() change. As Petr pointed out, using
> list_is_last() only made the last entry behave, still checked the
> aliased sibling's range for the other entries, and did nothing about
> klp_ftrace_handler() being unable to pick between them. Reject the
> livepatch in klp_init_object_loaded() instead, as suggested.
> - Rewrite the changelog around rejecting the configuration rather than
> around the out-of-bounds read that v1 described.
Acked-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
--
Josh