Skip to contentSkip to conversation

kprobes/x86: Release insn_slot in failure path

PATCH New Masami Hiramatsu 2 participants 2 messages Jul 21, 2017 – Jul 24, 2017 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kprobes/x86: Release insn_slot in failure path

The commit 003002e04ed3 ("kprobes: Fix arch_prepare_kprobe to handle copy insn failures") returns error if copying insn failed, but not release allocated insn_slot.

Release insn_slot assigned to ainsn.slot correctly if copy insn is failed.

Fixes 003002e04ed3 ("kprobes: Fix arch_prepare_kprobe to handle copy insn failures")
---
 arch/x86/kernel/kprobes/core.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
arch/x86/kernel/kprobes/core.c +9 -1
index 6b87780..f015371 100644
@@ -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;
 
@@ -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)
#1 lore raw
kprobes/x86: Release insn_slot in failure path
Commit-ID:  38115f2f8cec8087d558c062e779c443a01f87d6
Gitweb:     http://git.kernel.org/tip/38115f2f8cec8087d558c062e779c443a01f87d6
Author:     Masami Hiramatsu <[email protected]>
AuthorDate: Fri, 21 Jul 2017 23:45:52 +0900
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 24 Jul 2017 11:14:59 +0200

kprobes/x86: Release insn_slot in failure path

The following commit:

003002e04ed3 ("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.

Cc Ananth N Mavinakayanahalli <[email protected]>
Cc Anil S Keshavamurthy <[email protected]>
Cc David S . Miller <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
Fixes 003002e04ed3 ("kprobes: Fix arch_prepare_kprobe to handle copy insn failures")
---
 arch/x86/kernel/kprobes/core.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
arch/x86/kernel/kprobes/core.c +9 -1
index 6b87780..f015371 100644
@@ -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;
 
@@ -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)