Skip to content

Commit c86a32c

Browse files
mhiramatKAGA-KOKO
authored andcommitted
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 <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Acked-by: David Woodhouse <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Ananth N Mavinakayanahalli <[email protected]> Cc: Arjan van de Ven <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/151629212062.10241.6991266100233002273.stgit@devbox
1 parent c1804a2 commit c86a32c

File tree

1 file changed

+22
-1
lines changed
  • arch/x86/kernel/kprobes

1 file changed

+22
-1
lines changed

arch/x86/kernel/kprobes/opt.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <asm/debugreg.h>
4141
#include <asm/set_memory.h>
4242
#include <asm/sections.h>
43+
#include <asm/nospec-branch.h>
4344

4445
#include "common.h"
4546

@@ -205,7 +206,7 @@ static int copy_optimized_instructions(u8 *dest, u8 *src)
205206
}
206207

207208
/* Check whether insn is indirect jump */
208-
static int insn_is_indirect_jump(struct insn *insn)
209+
static int __insn_is_indirect_jump(struct insn *insn)
209210
{
210211
return ((insn->opcode.bytes[0] == 0xff &&
211212
(X86_MODRM_REG(insn->modrm.value) & 6) == 4) || /* Jump */
@@ -239,6 +240,26 @@ static int insn_jump_into_range(struct insn *insn, unsigned long start, int len)
239240
return (start <= target && target <= start + len);
240241
}
241242

243+
static int insn_is_indirect_jump(struct insn *insn)
244+
{
245+
int ret = __insn_is_indirect_jump(insn);
246+
247+
#ifdef CONFIG_RETPOLINE
248+
/*
249+
* Jump to x86_indirect_thunk_* is treated as an indirect jump.
250+
* Note that even with CONFIG_RETPOLINE=y, the kernel compiled with
251+
* older gcc may use indirect jump. So we add this check instead of
252+
* replace indirect-jump check.
253+
*/
254+
if (!ret)
255+
ret = insn_jump_into_range(insn,
256+
(unsigned long)__indirect_thunk_start,
257+
(unsigned long)__indirect_thunk_end -
258+
(unsigned long)__indirect_thunk_start);
259+
#endif
260+
return ret;
261+
}
262+
242263
/* Decode whole function to ensure any instructions don't jump into target */
243264
static int can_optimize(unsigned long paddr)
244265
{

0 commit comments

Comments
 (0)