Skip to content

Commit 0d07c0e

Browse files
mhiramatsuryasaimadhu
authored andcommitted
x86/kprobes: Fix optprobe to detect INT3 padding correctly
Commit 7705dc8 ("x86/vmlinux: Use INT3 instead of NOP for linker fill bytes") changed the padding bytes between functions from NOP to INT3. However, when optprobe decodes a target function it finds INT3 and gives up the jump optimization. Instead of giving up any INT3 detection, check whether the rest of the bytes to the end of the function are INT3. If all of them are INT3, those come from the linker. In that case, continue the optprobe jump optimization. [ bp: Massage commit message. ] Fixes: 7705dc8 ("x86/vmlinux: Use INT3 instead of NOP for linker fill bytes") Reported-by: Adam Zabrocki <[email protected]> Signed-off-by: Masami Hiramatsu <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Steven Rostedt (VMware) <[email protected]> Reviewed-by: Kees Cook <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/160767025681.3880685.16021570341428835411.stgit@devnote2
1 parent 190113b commit 0d07c0e

File tree

1 file changed

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

1 file changed

+20
-2
lines changed

arch/x86/kernel/kprobes/opt.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,19 @@ static int insn_is_indirect_jump(struct insn *insn)
272272
return ret;
273273
}
274274

275+
static bool is_padding_int3(unsigned long addr, unsigned long eaddr)
276+
{
277+
unsigned char ops;
278+
279+
for (; addr < eaddr; addr++) {
280+
if (get_kernel_nofault(ops, (void *)addr) < 0 ||
281+
ops != INT3_INSN_OPCODE)
282+
return false;
283+
}
284+
285+
return true;
286+
}
287+
275288
/* Decode whole function to ensure any instructions don't jump into target */
276289
static int can_optimize(unsigned long paddr)
277290
{
@@ -310,9 +323,14 @@ static int can_optimize(unsigned long paddr)
310323
return 0;
311324
kernel_insn_init(&insn, (void *)recovered_insn, MAX_INSN_SIZE);
312325
insn_get_length(&insn);
313-
/* Another subsystem puts a breakpoint */
326+
/*
327+
* In the case of detecting unknown breakpoint, this could be
328+
* a padding INT3 between functions. Let's check that all the
329+
* rest of the bytes are also INT3.
330+
*/
314331
if (insn.opcode.bytes[0] == INT3_INSN_OPCODE)
315-
return 0;
332+
return is_padding_int3(addr, paddr - offset + size) ? 1 : 0;
333+
316334
/* Recover address */
317335
insn.kaddr = (void *)addr;
318336
insn.next_byte = (void *)(addr + insn.length);

0 commit comments

Comments
 (0)