Skip to content

Commit 63dc632

Browse files
mhiramatPeter Zijlstra
authored andcommitted
x86/kprobes: Fix optprobe optimization check with CONFIG_RETHUNK
Since the CONFIG_RETHUNK and CONFIG_SLS will use INT3 for stopping speculative execution after function return, kprobe jump optimization always fails on the functions with such INT3 inside the function body. (It already checks the INT3 padding between functions, but not inside the function) To avoid this issue, as same as kprobes, check whether the INT3 comes from kgdb or not, and if so, stop decoding and make it fail. The other INT3 will come from CONFIG_RETHUNK/CONFIG_SLS and those can be treated as a one-byte instruction. Fixes: e463a09 ("x86: Add straight-line-speculation mitigation") Suggested-by: Peter Zijlstra <[email protected]> Signed-off-by: Masami Hiramatsu (Google) <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/167146051929.1374301.7419382929328081706.stgit@devnote3
1 parent 1993bf9 commit 63dc632

File tree

1 file changed

+8
-20
lines changed
  • arch/x86/kernel/kprobes

1 file changed

+8
-20
lines changed

arch/x86/kernel/kprobes/opt.c

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/extable.h>
1616
#include <linux/kdebug.h>
1717
#include <linux/kallsyms.h>
18+
#include <linux/kgdb.h>
1819
#include <linux/ftrace.h>
1920
#include <linux/objtool.h>
2021
#include <linux/pgtable.h>
@@ -279,19 +280,6 @@ static int insn_is_indirect_jump(struct insn *insn)
279280
return ret;
280281
}
281282

282-
static bool is_padding_int3(unsigned long addr, unsigned long eaddr)
283-
{
284-
unsigned char ops;
285-
286-
for (; addr < eaddr; addr++) {
287-
if (get_kernel_nofault(ops, (void *)addr) < 0 ||
288-
ops != INT3_INSN_OPCODE)
289-
return false;
290-
}
291-
292-
return true;
293-
}
294-
295283
/* Decode whole function to ensure any instructions don't jump into target */
296284
static int can_optimize(unsigned long paddr)
297285
{
@@ -334,15 +322,15 @@ static int can_optimize(unsigned long paddr)
334322
ret = insn_decode_kernel(&insn, (void *)recovered_insn);
335323
if (ret < 0)
336324
return 0;
337-
325+
#ifdef CONFIG_KGDB
338326
/*
339-
* In the case of detecting unknown breakpoint, this could be
340-
* a padding INT3 between functions. Let's check that all the
341-
* rest of the bytes are also INT3.
327+
* If there is a dynamically installed kgdb sw breakpoint,
328+
* this function should not be probed.
342329
*/
343-
if (insn.opcode.bytes[0] == INT3_INSN_OPCODE)
344-
return is_padding_int3(addr, paddr - offset + size) ? 1 : 0;
345-
330+
if (insn.opcode.bytes[0] == INT3_INSN_OPCODE &&
331+
kgdb_has_hit_break(addr))
332+
return 0;
333+
#endif
346334
/* Recover address */
347335
insn.kaddr = (void *)addr;
348336
insn.next_byte = (void *)(addr + insn.length);

0 commit comments

Comments
 (0)