Skip to content

Commit

Permalink
x86/livepatch: Validate __fentry__ location
Browse files Browse the repository at this point in the history
Currently livepatch assumes __fentry__ lives at func+0, which is most
likely untrue with IBT on. Instead make it use ftrace_location() by
default which both validates and finds the actual ip if there is any
in the same symbol.

Suggested-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
Link: https://lore.kernel.org/r/20220308154318.285971256@infradead.org
  • Loading branch information
Peter Zijlstra committed Mar 15, 2022
1 parent aebfd12 commit d15cb3d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 27 deletions.
10 changes: 0 additions & 10 deletions arch/powerpc/include/asm/livepatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@ static inline void klp_arch_set_pc(struct ftrace_regs *fregs, unsigned long ip)
regs_set_return_ip(regs, ip);
}

#define klp_get_ftrace_location klp_get_ftrace_location
static inline unsigned long klp_get_ftrace_location(unsigned long faddr)
{
/*
* Live patch works only with -mprofile-kernel on PPC. In this case,
* the ftrace location is always within the first 16 bytes.
*/
return ftrace_location_range(faddr, faddr + 16);
}

static inline void klp_init_thread_info(struct task_struct *p)
{
/* + 1 to account for STACK_END_MAGIC */
Expand Down
19 changes: 2 additions & 17 deletions kernel/livepatch/patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,6 @@ static void notrace klp_ftrace_handler(unsigned long ip,
ftrace_test_recursion_unlock(bit);
}

/*
* Convert a function address into the appropriate ftrace location.
*
* Usually this is just the address of the function, but on some architectures
* it's more complicated so allow them to provide a custom behaviour.
*/
#ifndef klp_get_ftrace_location
static unsigned long klp_get_ftrace_location(unsigned long faddr)
{
return faddr;
}
#endif

static void klp_unpatch_func(struct klp_func *func)
{
struct klp_ops *ops;
Expand All @@ -153,8 +140,7 @@ static void klp_unpatch_func(struct klp_func *func)
if (list_is_singular(&ops->func_stack)) {
unsigned long ftrace_loc;

ftrace_loc =
klp_get_ftrace_location((unsigned long)func->old_func);
ftrace_loc = ftrace_location((unsigned long)func->old_func);
if (WARN_ON(!ftrace_loc))
return;

Expand Down Expand Up @@ -186,8 +172,7 @@ static int klp_patch_func(struct klp_func *func)
if (!ops) {
unsigned long ftrace_loc;

ftrace_loc =
klp_get_ftrace_location((unsigned long)func->old_func);
ftrace_loc = ftrace_location((unsigned long)func->old_func);
if (!ftrace_loc) {
pr_err("failed to find location for function '%s'\n",
func->old_name);
Expand Down

0 comments on commit d15cb3d

Please sign in to comment.