Skip to content

Commit

Permalink
kprobes/x86: Release insn_slot in failure path
Browse files Browse the repository at this point in the history
The following commit:

  003002e ("kprobes: Fix arch_prepare_kprobe to handle copy insn failures")

returns an error if the copying of the instruction, but does not release
the allocated insn_slot.

Clean up correctly.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Cc: David S . Miller <davem@davemloft.net>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Fixes: 003002e ("kprobes: Fix arch_prepare_kprobe to handle copy insn failures")
Link: http://lkml.kernel.org/r/150064834183.6172.11694375818447664416.stgit@devbox
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Masami Hiramatsu authored and Ingo Molnar committed Jul 24, 2017
1 parent ba883b4 commit 38115f2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion arch/x86/kernel/kprobes/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@ static int arch_copy_kprobe(struct kprobe *p)

int arch_prepare_kprobe(struct kprobe *p)
{
int ret;

if (alternatives_text_reserved(p->addr, p->addr))
return -EINVAL;

Expand All @@ -467,7 +469,13 @@ int arch_prepare_kprobe(struct kprobe *p)
if (!p->ainsn.insn)
return -ENOMEM;

return arch_copy_kprobe(p);
ret = arch_copy_kprobe(p);
if (ret) {
free_insn_slot(p->ainsn.insn, 0);
p->ainsn.insn = NULL;
}

return ret;
}

void arch_arm_kprobe(struct kprobe *p)
Expand Down

0 comments on commit 38115f2

Please sign in to comment.