Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753127AbdI1K46 (ORCPT ); Thu, 28 Sep 2017 06:56:58 -0400 Received: from terminus.zytor.com ([65.50.211.136]:55669 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752777AbdI1K44 (ORCPT ); Thu, 28 Sep 2017 06:56:56 -0400 Date: Thu, 28 Sep 2017 03:53:21 -0700 From: tip-bot for Masami Hiramatsu Message-ID: Cc: ast@kernel.org, ast@fb.com, mhiramat@kernel.org, ananth@linux.vnet.ibm.com, mingo@kernel.org, peterz@infradead.org, rostedt@goodmis.org, linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, hpa@zytor.com, paulmck@linux.vnet.ibm.com, tglx@linutronix.de Reply-To: mhiramat@kernel.org, ast@fb.com, ast@kernel.org, tglx@linutronix.de, paulmck@linux.vnet.ibm.com, hpa@zytor.com, torvalds@linux-foundation.org, rostedt@goodmis.org, linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@kernel.org, ananth@linux.vnet.ibm.com In-Reply-To: <150581521955.32348.3615624715034787365.stgit@devbox> References: <150581521955.32348.3615624715034787365.stgit@devbox> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] kprobes: Warn if optprobe handler tries to change execution path Git-Commit-ID: e863d5396146411b615231cae0c518cb2a23371c 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 Content-Length: 1824 Lines: 46 Commit-ID: e863d5396146411b615231cae0c518cb2a23371c Gitweb: https://git.kernel.org/tip/e863d5396146411b615231cae0c518cb2a23371c Author: Masami Hiramatsu AuthorDate: Tue, 19 Sep 2017 19:00:19 +0900 Committer: Ingo Molnar CommitDate: Thu, 28 Sep 2017 09:23:04 +0200 kprobes: Warn if optprobe handler tries to change execution path Warn if optprobe handler tries to change execution path. As described in Documentation/kprobes.txt, with optprobe user handler can not change instruction pointer. In that case user must avoid optimizing the kprobes by setting post_handler or break_handler. Signed-off-by: Masami Hiramatsu Cc: Alexei Starovoitov Cc: Alexei Starovoitov Cc: Ananth N Mavinakayanahalli Cc: Linus Torvalds Cc: Paul E . McKenney Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/150581521955.32348.3615624715034787365.stgit@devbox Signed-off-by: Ingo Molnar --- kernel/kprobes.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 15fba7f..2d28377 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -387,7 +387,10 @@ void opt_pre_handler(struct kprobe *p, struct pt_regs *regs) list_for_each_entry_rcu(kp, &p->list, list) { if (kp->pre_handler && likely(!kprobe_disabled(kp))) { set_kprobe_instance(kp); - kp->pre_handler(kp, regs); + if (kp->pre_handler(kp, regs)) { + if (WARN_ON_ONCE(1)) + pr_err("Optprobe ignores instruction pointer changing.(%pF)\n", p->addr); + } } reset_kprobe_instance(); }