Skip to content

Commit

Permalink
kprobes: Allow probing on any address belonging to ftrace
Browse files Browse the repository at this point in the history
On certain architectures, ftrace can reserve multiple instructions at
function entry. Rather than rejecting kprobe on addresses other than the
exact ftrace call instruction, use the address returned by ftrace to
probe at the correct address when CONFIG_KPROBES_ON_FTRACE is enabled.

Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
  • Loading branch information
rnav authored and Nobody committed Feb 20, 2022
1 parent 7861c39 commit a97b1bb
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions kernel/kprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,10 @@ bool within_kprobe_blacklist(unsigned long addr)
static kprobe_opcode_t *_kprobe_addr(kprobe_opcode_t *addr,
const char *symbol_name, unsigned int offset)
{
#ifdef CONFIG_KPROBES_ON_FTRACE
unsigned long ftrace_addr = 0;
#endif

if ((symbol_name && addr) || (!symbol_name && !addr))
goto invalid;

Expand All @@ -1507,6 +1511,14 @@ static kprobe_opcode_t *_kprobe_addr(kprobe_opcode_t *addr,
}

addr = (kprobe_opcode_t *)(((char *)addr) + offset);

#ifdef CONFIG_KPROBES_ON_FTRACE
if (addr)
ftrace_addr = ftrace_location((unsigned long)addr);
if (ftrace_addr)
return (kprobe_opcode_t *)ftrace_addr;
#endif

if (addr)
return addr;

Expand Down

0 comments on commit a97b1bb

Please sign in to comment.