From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752107AbbBURrL (ORCPT ); Sat, 21 Feb 2015 12:47:11 -0500 Received: from terminus.zytor.com ([198.137.202.10]:55883 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751561AbbBURrG (ORCPT ); Sat, 21 Feb 2015 12:47:06 -0500 Date: Sat, 21 Feb 2015 09:46:43 -0800 From: tip-bot for Petr Mladek Message-ID: Cc: rostedt@goodmis.org, linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@kernel.org, anil.s.keshavamurthy@intel.com, masami.hiramatsu.pt@hitachi.com, fweisbec@gmail.com, pmladek@suse.cz, jkosina@suse.cz, ananth@in.ibm.com, tglx@linutronix.de, davem@davemloft.net Reply-To: pmladek@suse.cz, jkosina@suse.cz, ananth@in.ibm.com, tglx@linutronix.de, davem@davemloft.net, rostedt@goodmis.org, linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@kernel.org, anil.s.keshavamurthy@intel.com, masami.hiramatsu.pt@hitachi.com, fweisbec@gmail.com In-Reply-To: <1424441250-27146-3-git-send-email-pmladek@suse.cz> References: <1424441250-27146-3-git-send-email-pmladek@suse.cz> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] kprobes/x86: Check for invalid ftrace location in __recover_probed_insn() Git-Commit-ID: 2a6730c8b6e075adf826a89a3e2caa705807afdb 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: 2a6730c8b6e075adf826a89a3e2caa705807afdb Gitweb: http://git.kernel.org/tip/2a6730c8b6e075adf826a89a3e2caa705807afdb Author: Petr Mladek AuthorDate: Fri, 20 Feb 2015 15:07:30 +0100 Committer: Ingo Molnar CommitDate: Sat, 21 Feb 2015 10:33:31 +0100 kprobes/x86: Check for invalid ftrace location in __recover_probed_insn() __recover_probed_insn() should always be called from an address where an instructions starts. The check for ftrace_location() might help to discover a potential inconsistency. This patch adds WARN_ON() when the inconsistency is detected. Also it adds handling of the situation when the original code can not get recovered. Suggested-by: Masami Hiramatsu Signed-off-by: Petr Mladek Cc: Ananth NMavinakayanahalli Cc: Anil S Keshavamurthy Cc: David S. Miller Cc: Frederic Weisbecker Cc: Jiri Kosina Cc: Steven Rostedt Link: http://lkml.kernel.org/r/1424441250-27146-3-git-send-email-pmladek@suse.cz Signed-off-by: Ingo Molnar --- arch/x86/kernel/kprobes/core.c | 12 ++++++++++++ arch/x86/kernel/kprobes/opt.c | 2 ++ 2 files changed, 14 insertions(+) diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c index c3b4b46..4e3d5a9 100644 --- a/arch/x86/kernel/kprobes/core.c +++ b/arch/x86/kernel/kprobes/core.c @@ -228,6 +228,13 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr) kp = get_kprobe((void *)addr); faddr = ftrace_location(addr); /* + * Addresses inside the ftrace location are refused by + * arch_check_ftrace_location(). Something went terribly wrong + * if such an address is checked here. + */ + if (WARN_ON(faddr && faddr != addr)) + return 0UL; + /* * Use the current code if it is not modified by Kprobe * and it cannot be modified by ftrace. */ @@ -265,6 +272,7 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr) * Recover the probed instruction at addr for further analysis. * Caller must lock kprobes by kprobe_mutex, or disable preemption * for preventing to release referencing kprobes. + * Returns zero if the instruction can not get recovered. */ unsigned long recover_probed_instruction(kprobe_opcode_t *buf, unsigned long addr) { @@ -299,6 +307,8 @@ static int can_probe(unsigned long paddr) * normally used, we just go through if there is no kprobe. */ __addr = recover_probed_instruction(buf, addr); + if (!__addr) + return 0; kernel_insn_init(&insn, (void *)__addr, MAX_INSN_SIZE); insn_get_length(&insn); @@ -347,6 +357,8 @@ int __copy_instruction(u8 *dest, u8 *src) unsigned long recovered_insn = recover_probed_instruction(buf, (unsigned long)src); + if (!recovered_insn) + return 0; kernel_insn_init(&insn, (void *)recovered_insn, MAX_INSN_SIZE); insn_get_length(&insn); /* Another subsystem puts a breakpoint, failed to recover */ diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c index 7c523bb..3aef248 100644 --- a/arch/x86/kernel/kprobes/opt.c +++ b/arch/x86/kernel/kprobes/opt.c @@ -259,6 +259,8 @@ static int can_optimize(unsigned long paddr) */ return 0; recovered_insn = recover_probed_instruction(buf, addr); + if (!recovered_insn) + return 0; kernel_insn_init(&insn, (void *)recovered_insn, MAX_INSN_SIZE); insn_get_length(&insn); /* Another subsystem puts a breakpoint */