Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kprobes/x86: Disable optimizing on the function jumps to indirect thunk

Since indirect jump instructions will be replaced by jump
to __x86_indirect_thunk_*, those jmp instruction must be
treated as an indirect jump. Since optprobe prohibits to
optimize probes in the function which uses an indirect jump,
it also needs to find out the function which jump to
__x86_indirect_thunk_* and disable optimization.

Add a check that the jump target address is between the
__indirect_thunk_start/end when optimizing kprobe.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: David Woodhouse <dwmw@amazon.co.uk>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
Cc: Arjan van de Ven <arjan@linux.intel.com>
Cc: Greg Kroah-Hartman <gregkh@linux-foundation.org>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/151629212062.10241.6991266100233002273.stgit@devbox

authored by

Masami Hiramatsu and committed by
Thomas Gleixner
c86a32c0 c1804a23

+22 -1
+22 -1
arch/x86/kernel/kprobes/opt.c
··· 40 40 #include <asm/debugreg.h> 41 41 #include <asm/set_memory.h> 42 42 #include <asm/sections.h> 43 + #include <asm/nospec-branch.h> 43 44 44 45 #include "common.h" 45 46 ··· 206 205 } 207 206 208 207 /* Check whether insn is indirect jump */ 209 - static int insn_is_indirect_jump(struct insn *insn) 208 + static int __insn_is_indirect_jump(struct insn *insn) 210 209 { 211 210 return ((insn->opcode.bytes[0] == 0xff && 212 211 (X86_MODRM_REG(insn->modrm.value) & 6) == 4) || /* Jump */ ··· 238 237 target = (unsigned long)insn->next_byte + insn->immediate.value; 239 238 240 239 return (start <= target && target <= start + len); 240 + } 241 + 242 + static int insn_is_indirect_jump(struct insn *insn) 243 + { 244 + int ret = __insn_is_indirect_jump(insn); 245 + 246 + #ifdef CONFIG_RETPOLINE 247 + /* 248 + * Jump to x86_indirect_thunk_* is treated as an indirect jump. 249 + * Note that even with CONFIG_RETPOLINE=y, the kernel compiled with 250 + * older gcc may use indirect jump. So we add this check instead of 251 + * replace indirect-jump check. 252 + */ 253 + if (!ret) 254 + ret = insn_jump_into_range(insn, 255 + (unsigned long)__indirect_thunk_start, 256 + (unsigned long)__indirect_thunk_end - 257 + (unsigned long)__indirect_thunk_start); 258 + #endif 259 + return ret; 241 260 } 242 261 243 262 /* Decode whole function to ensure any instructions don't jump into target */