From aa4f3190484515fb7ca1b7822b6b77a2f0489b88 Mon Sep 17 00:00:00 2001 From: Kris Van Hees Date: Mon, 15 May 2017 23:29:16 -0400 Subject: [PATCH] dtrace: make x86_64 FBT return probe detection less restrictive The FBT return probe detection mechanism on x86_64 was requiring that the "ret" instruction be followed by a "push %rbp" or "nop", which is much too restrictive. The new code allows probing of all "ret" instructions that occur in a function regardless of what instructions follows. In order to make this possible, the functions to set and clear FBT probes on x86_64 (dtrace_invop_add() and dtrace_invop_remove()) have been modified to accept a 2nd argument that indicates the instruction to patch the probe location with. This is needed because FBT return probes need a different instruction on x86_64 (LOCK prefix to force an invalid opcode trap isn't safe because we do not know what instruction may follow the "ret"). This commit also fixes the declaration of the dtrace_bad_address() function that was missing its return type. Orabug: 25949048 Signed-off-by: Kris Van Hees Acked-by: Nick Alcock --- arch/x86/include/asm/dtrace_util.h | 5 +++-- arch/x86/kernel/dtrace_fbt.c | 8 ++------ arch/x86/kernel/dtrace_util.c | 8 ++++---- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/arch/x86/include/asm/dtrace_util.h b/arch/x86/include/asm/dtrace_util.h index d53b11f2d1a8..43e1de8434ec 100644 --- a/arch/x86/include/asm/dtrace_util.h +++ b/arch/x86/include/asm/dtrace_util.h @@ -12,13 +12,14 @@ #ifndef __ASSEMBLY__ +#include #include extern int dtrace_invop_add(uint8_t (*func)(struct pt_regs *)); extern void dtrace_invop_remove(uint8_t (*func)(struct pt_regs *)); -extern void dtrace_invop_enable(uint8_t *); -extern void dtrace_invop_disable(uint8_t *, uint8_t); +extern void dtrace_invop_enable(asm_instr_t *, asm_instr_t); +extern void dtrace_invop_disable(asm_instr_t *, asm_instr_t); extern int dtrace_user_addr_is_exec(uintptr_t); diff --git a/arch/x86/kernel/dtrace_fbt.c b/arch/x86/kernel/dtrace_fbt.c index 43f0b83af80c..97ee749665c8 100644 --- a/arch/x86/kernel/dtrace_fbt.c +++ b/arch/x86/kernel/dtrace_fbt.c @@ -80,7 +80,6 @@ void dtrace_fbt_init(fbt_add_probe_fn fbt_add_probe) while (kallsyms_iter_update(&sym, pos++)) { asm_instr_t *addr, *end; int state = 0, insc = 0; - void *efbp = NULL; void *fbtp = NULL; /* @@ -162,17 +161,14 @@ void dtrace_fbt_init(fbt_add_probe_fn fbt_add_probe) state = 2; break; case 1: /* look for ret */ - if (*addr == FBT_RET && - (*(addr + 1) == FBT_PUSHL_EBP || - *(addr + 1) == FBT_NOP)) { + if (*addr == FBT_RET) { uintptr_t off; off = addr - (asm_instr_t *)sym.value; - fbt_add_probe( + fbtp = fbt_add_probe( dtrace_kmod, sym.name, FBT_RETURN, *addr, addr, off, fbtp); - state = 2; } break; } diff --git a/arch/x86/kernel/dtrace_util.c b/arch/x86/kernel/dtrace_util.c index f246c4c5fdd0..edd5fdf05290 100644 --- a/arch/x86/kernel/dtrace_util.c +++ b/arch/x86/kernel/dtrace_util.c @@ -262,22 +262,22 @@ EXPORT_SYMBOL(dtrace_invop_remove); * Enable an INVOP-based probe, i.e. ensure that an INVOP trap is triggered at * the specified address. */ -void dtrace_invop_enable(uint8_t *addr) +void dtrace_invop_enable(asm_instr_t *addr, asm_instr_t opcode) { - text_poke(addr, ((unsigned char []){INVOP_TRAP_INSTR}), 1); + text_poke(addr, ((unsigned char []){opcode}), 1); } EXPORT_SYMBOL(dtrace_invop_enable); /* * Disable an INVOP-based probe. */ -void dtrace_invop_disable(uint8_t *addr, uint8_t opcode) +void dtrace_invop_disable(asm_instr_t *addr, asm_instr_t opcode) { text_poke(addr, ((unsigned char []){opcode}), 1); } EXPORT_SYMBOL(dtrace_invop_disable); -static inline dtrace_bad_address(void *addr) +static inline int dtrace_bad_address(void *addr) { unsigned long dummy; -- 2.50.1