From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754330AbdGXKXS (ORCPT ); Mon, 24 Jul 2017 06:23:18 -0400 Received: from terminus.zytor.com ([65.50.211.136]:46875 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753376AbdGXKWt (ORCPT ); Mon, 24 Jul 2017 06:22:49 -0400 Date: Mon, 24 Jul 2017 03:19:20 -0700 From: tip-bot for Masami Hiramatsu Message-ID: Cc: mhiramat@kernel.org, hpa@zytor.com, linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, peterz@infradead.org, tglx@linutronix.de, davem@davemloft.net, ananth@in.ibm.com, mingo@kernel.org, anil.s.keshavamurthy@intel.com Reply-To: mingo@kernel.org, anil.s.keshavamurthy@intel.com, tglx@linutronix.de, peterz@infradead.org, torvalds@linux-foundation.org, davem@davemloft.net, ananth@in.ibm.com, linux-kernel@vger.kernel.org, mhiramat@kernel.org, hpa@zytor.com In-Reply-To: <150064834183.6172.11694375818447664416.stgit@devbox> References: <150064834183.6172.11694375818447664416.stgit@devbox> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] kprobes/x86: Release insn_slot in failure path Git-Commit-ID: 38115f2f8cec8087d558c062e779c443a01f87d6 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 38115f2f8cec8087d558c062e779c443a01f87d6 Gitweb: http://git.kernel.org/tip/38115f2f8cec8087d558c062e779c443a01f87d6 Author: Masami Hiramatsu AuthorDate: Fri, 21 Jul 2017 23:45:52 +0900 Committer: Ingo Molnar 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. Signed-off-by: Masami Hiramatsu Cc: Ananth N Mavinakayanahalli Cc: Anil S Keshavamurthy Cc: David S . Miller Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Fixes: 003002e04ed3 ("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 --- arch/x86/kernel/kprobes/core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c index 6b87780..f015371 100644 --- a/arch/x86/kernel/kprobes/core.c +++ b/arch/x86/kernel/kprobes/core.c @@ -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)