From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756493AbdKCODX (ORCPT ); Fri, 3 Nov 2017 10:03:23 -0400 Received: from smtprelay0012.hostedemail.com ([216.40.44.12]:40255 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756228AbdKCODW (ORCPT ); Fri, 3 Nov 2017 10:03:22 -0400 X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Spam-Summary: 50,0,0,,d41d8cd98f00b204,rostedt@goodmis.org,:::::::::::::::::::::::::,RULES_HIT:41:69:355:379:541:599:800:960:967:968:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1543:1593:1594:1711:1730:1747:1777:1792:2198:2199:2393:2525:2553:2560:2563:2682:2685:2691:2693:2859:2890:2911:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3355:3622:3865:3866:3867:3868:3870:3871:3872:3873:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4042:4250:4321:4425:5007:6261:6742:7875:7903:9010:9025:10004:10400:10848:10967:11026:11232:11658:11914:12043:12291:12296:12438:12555:12663:12683:12700:12737:12740:12760:12895:13439:13972:14181:14659:14721:21080:21324:21450:21451:21627:30001:30054:30076:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:9,LUA_SUMMARY:none X-HE-Tag: lake63_745cfa13fc304 X-Filterd-Recvd-Size: 4582 Date: Fri, 3 Nov 2017 10:03:17 -0400 From: Steven Rostedt To: Jessica Yu Cc: Masami Hiramatsu , Ananth N Mavinakayanahalli , Anil S Keshavamurthy , "David S . Miller" , Ingo Molnar , Petr Mladek , Josh Poimboeuf , Joe Lawrence , Jiri Kosina , Miroslav Benes , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/2] kprobes: propagate error from arm_kprobe_ftrace() Message-ID: <20171103100317.01db273b@vmware.local.home> In-Reply-To: <20171102163334.3947-2-jeyu@kernel.org> References: <20171102163334.3947-1-jeyu@kernel.org> <20171102163334.3947-2-jeyu@kernel.org> X-Mailer: Claws Mail 3.15.1-dirty (GTK+ 2.24.31; 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 Thu, 2 Nov 2017 17:33:33 +0100 Jessica Yu wrote: > Improve error handling when arming ftrace-based kprobes. Specifically, if > we fail to arm a ftrace-based kprobe, register_kprobe()/enable_kprobe() > should report an error instead of success. Previously, this has lead to > confusing situations where register_kprobe() would return 0 indicating > success, but the kprobe would not be functional if ftrace registration > during the kprobe arming process had failed. We should therefore take any > errors returned by ftrace into account and propagate this error so that we > do not register/enable kprobes that cannot be armed. This can happen if, > for example, register_ftrace_function() finds an IPMODIFY conflict (since > kprobe_ftrace_ops has this flag set) and returns an error. Such a conflict > is possible since livepatches also set the IPMODIFY flag for their ftrace_ops. > > arm_all_kprobes() keeps its current behavior and attempts to arm all > kprobes. It returns the last encountered error and gives a warning if > not all kprobes could be armed. > > This patch is based on Petr Mladek's original patchset (patches 2 and 3) > back in 2015, which improved kprobes error handling, found here: > > https://lkml.org/lkml/2015/2/26/452 > > However, further work on this had been paused since then and the patches > were not upstreamed. > > Based-on-patches-by: Petr Mladek > Signed-off-by: Jessica Yu > --- > kernel/kprobes.c | 88 ++++++++++++++++++++++++++++++++++++++++---------------- > 1 file changed, 63 insertions(+), 25 deletions(-) > > diff --git a/kernel/kprobes.c b/kernel/kprobes.c > index da2ccf142358..f4a094007cb5 100644 > --- a/kernel/kprobes.c > +++ b/kernel/kprobes.c > @@ -978,18 +978,27 @@ static int prepare_kprobe(struct kprobe *p) > } > > /* Caller must lock kprobe_mutex */ > -static void arm_kprobe_ftrace(struct kprobe *p) > +static int arm_kprobe_ftrace(struct kprobe *p) > { > - int ret; > + int ret = 0; > > ret = ftrace_set_filter_ip(&kprobe_ftrace_ops, > (unsigned long)p->addr, 0, 0); > - WARN(ret < 0, "Failed to arm kprobe-ftrace at %p (%d)\n", p->addr, ret); > - kprobe_ftrace_enabled++; > - if (kprobe_ftrace_enabled == 1) { > + if (WARN(ret < 0, "Failed to arm kprobe-ftrace at %p (%d)\n", p->addr, ret)) > + return ret; > + > + if (kprobe_ftrace_enabled == 0) { > ret = register_ftrace_function(&kprobe_ftrace_ops); > - WARN(ret < 0, "Failed to init kprobe-ftrace (%d)\n", ret); > + if (WARN(ret < 0, "Failed to init kprobe-ftrace (%d)\n", ret)) > + goto err_ftrace; > } > + > + kprobe_ftrace_enabled++; > + return ret; > + > +err_ftrace: > + ftrace_set_filter_ip(&kprobe_ftrace_ops, (unsigned long)p->addr, 1, 0); Hmm, this could have a very nasty side effect. If you remove a function from the ops, and it was the last function, an empty ops means to trace *all* functions. Perhaps you want to add it to the "notrace" list. Which would require implementing a ftrace_set_notrace_ip() function. Which I believe is what you want. Any function in the notrace hash will have the same functions in the filter hash be ignored. I'll let Masami review the rest. -- Steve > + return ret; > } >