Skip to content

Commit 1993bf9

Browse files
mhiramatPeter Zijlstra
authored andcommitted
x86/kprobes: Fix kprobes instruction boudary check with CONFIG_RETHUNK
Since the CONFIG_RETHUNK and CONFIG_SLS will use INT3 for stopping speculative execution after RET instruction, kprobes always failes to check the probed instruction boundary by decoding the function body if the probed address is after such sequence. (Note that some conditional code blocks will be placed after function return, if compiler decides it is not on the hot path.) This is because kprobes expects kgdb puts the INT3 as a software breakpoint and it will replace the original instruction. But these INT3 are not such purpose, it doesn't need to recover the original instruction. To avoid this issue, kprobes checks whether the INT3 is owned by 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/167146051026.1374301.392728975473572291.stgit@devnote3
1 parent ade8c20 commit 1993bf9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

arch/x86/kernel/kprobes/core.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <linux/extable.h>
3838
#include <linux/kdebug.h>
3939
#include <linux/kallsyms.h>
40+
#include <linux/kgdb.h>
4041
#include <linux/ftrace.h>
4142
#include <linux/kasan.h>
4243
#include <linux/moduleloader.h>
@@ -281,12 +282,15 @@ static int can_probe(unsigned long paddr)
281282
if (ret < 0)
282283
return 0;
283284

285+
#ifdef CONFIG_KGDB
284286
/*
285-
* Another debugging subsystem might insert this breakpoint.
286-
* In that case, we can't recover it.
287+
* If there is a dynamically installed kgdb sw breakpoint,
288+
* this function should not be probed.
287289
*/
288-
if (insn.opcode.bytes[0] == INT3_INSN_OPCODE)
290+
if (insn.opcode.bytes[0] == INT3_INSN_OPCODE &&
291+
kgdb_has_hit_break(addr))
289292
return 0;
293+
#endif
290294
addr += insn.length;
291295
}
292296

0 commit comments

Comments
 (0)