Skip to content

Commit 38115f2

Browse files
mhiramatIngo Molnar
authored andcommitted
kprobes/x86: Release insn_slot in failure path
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>
1 parent ba883b4 commit 38115f2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

arch/x86/kernel/kprobes/core.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,8 @@ static int arch_copy_kprobe(struct kprobe *p)
457457

458458
int arch_prepare_kprobe(struct kprobe *p)
459459
{
460+
int ret;
461+
460462
if (alternatives_text_reserved(p->addr, p->addr))
461463
return -EINVAL;
462464

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

470-
return arch_copy_kprobe(p);
472+
ret = arch_copy_kprobe(p);
473+
if (ret) {
474+
free_insn_slot(p->ainsn.insn, 0);
475+
p->ainsn.insn = NULL;
476+
}
477+
478+
return ret;
471479
}
472480

473481
void arch_arm_kprobe(struct kprobe *p)

0 commit comments

Comments
 (0)