From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751908AbcF0OtL (ORCPT ); Mon, 27 Jun 2016 10:49:11 -0400 Received: from smtprelay0103.hostedemail.com ([216.40.44.103]:50867 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751696AbcF0OtJ (ORCPT ); Mon, 27 Jun 2016 10:49:09 -0400 X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,rostedt@goodmis.org,:::::::::::::,RULES_HIT:41:355:379:541:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2553:2559:2562:3138:3139:3140:3141:3142:3353:3622:3865:3866:3867:3868:3871:3872:3874:4321:5007:6261:7875:10004:10400:10848:10967:11026:11232:11473:11658:11914:12517:12519:12555:12663:12740:13069:13311:13357:13439:14181:14659:14721:21080:30012:30025:30054:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: flesh63_88b96610df309 X-Filterd-Recvd-Size: 2680 Date: Mon, 27 Jun 2016 10:48:58 -0400 From: Steven Rostedt To: Petr Mladek Cc: Ingo Molnar , Frederic Weisbecker , Masami Hiramatsu , Jiri Kosina , linux-kernel@vger.kernel.org, x86@kernel.org Subject: Re: [PATCH 2/4] ftrace/x86: Do not crash when reading wrong ftrace func Message-ID: <20160627104858.68d02f24@gandalf.local.home> In-Reply-To: <1467035677-12193-3-git-send-email-pmladek@suse.com> References: <1467035677-12193-1-git-send-email-pmladek@suse.com> <1467035677-12193-3-git-send-email-pmladek@suse.com> X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 27 Jun 2016 15:54:35 +0200 Petr Mladek wrote: > Ftrace modifies the code on many locations. It is paranoid > and avoid a kernel crash using probe_kernel_read() and > probe_kernel_write(). The only exception is update_ftrace_func() > where where we read the old code using memcpy(). > > It is true that this function is used only to modify well > defined functions that are part of the ftrace API. But > it might still make sense to be paranoid and be consistent > with the writing side. I'm not so sure I'm too hot on this patch. I left it with the memcpy() because it was a well known location. If this is wrong, then we should crash the kernel. I'm not totally against it. But a comment should be added stating something like: /* * ip points to the ftrace infrastructure. If this fails, * then something is totally messed up. */ and perhaps even add a WARN_ON() here too. -- Steve > > Signed-off-by: Petr Mladek > --- > arch/x86/kernel/ftrace.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c > index 42ea69d35dfd..8305c6792ad2 100644 > --- a/arch/x86/kernel/ftrace.c > +++ b/arch/x86/kernel/ftrace.c > @@ -233,7 +233,8 @@ static int update_ftrace_func(unsigned long ip, void *new) > unsigned char old[MCOUNT_INSN_SIZE]; > int ret; > > - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE); > + if (probe_kernel_read(old, (void *)ip, MCOUNT_INSN_SIZE)) > + return -EFAULT; > > /* > * Make sure that we replace 5-byte instruction that