Skip to content

Commit 003002e

Browse files
mhiramathitachiIngo Molnar
authored andcommitted
kprobes: Fix arch_prepare_kprobe to handle copy insn failures
Fix arch_prepare_kprobe() to handle failures in copy instruction correctly. This fix is related to the previous fix: 8101376 which made __copy_instruction return an error result if failed, but caller site was not updated to handle it. Thus, this is the other half of the bugfix. This fix is also related to the following bug-report: https://bugzilla.redhat.com/show_bug.cgi?id=910649 Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Acked-by: Steven Rostedt <rostedt@goodmis.org> Tested-by: Jonathan Lebon <jlebon@redhat.com> Cc: Frank Ch. Eigler <fche@redhat.com> Cc: systemtap@sourceware.org Cc: yrl.pp-manager.tt@hitachi.com Link: http://lkml.kernel.org/r/20130605031216.15285.2001.stgit@mhiramat-M0-7522 Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent f1a5278 commit 003002e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

arch/x86/kernel/kprobes/core.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,14 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
365365
return insn.length;
366366
}
367367

368-
static void __kprobes arch_copy_kprobe(struct kprobe *p)
368+
static int __kprobes arch_copy_kprobe(struct kprobe *p)
369369
{
370+
int ret;
371+
370372
/* Copy an instruction with recovering if other optprobe modifies it.*/
371-
__copy_instruction(p->ainsn.insn, p->addr);
373+
ret = __copy_instruction(p->ainsn.insn, p->addr);
374+
if (!ret)
375+
return -EINVAL;
372376

373377
/*
374378
* __copy_instruction can modify the displacement of the instruction,
@@ -384,6 +388,8 @@ static void __kprobes arch_copy_kprobe(struct kprobe *p)
384388

385389
/* Also, displacement change doesn't affect the first byte */
386390
p->opcode = p->ainsn.insn[0];
391+
392+
return 0;
387393
}
388394

389395
int __kprobes arch_prepare_kprobe(struct kprobe *p)
@@ -397,8 +403,8 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
397403
p->ainsn.insn = get_insn_slot();
398404
if (!p->ainsn.insn)
399405
return -ENOMEM;
400-
arch_copy_kprobe(p);
401-
return 0;
406+
407+
return arch_copy_kprobe(p);
402408
}
403409

404410
void __kprobes arch_arm_kprobe(struct kprobe *p)

0 commit comments

Comments
 (0)