From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751945AbdJEX6N (ORCPT ); Thu, 5 Oct 2017 19:58:13 -0400 Received: from smtprelay0034.hostedemail.com ([216.40.44.34]:53582 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751083AbdJEX6M (ORCPT ); Thu, 5 Oct 2017 19:58:12 -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:1542:1593:1594:1711:1730:1747:1777:1792:1801:2393:2553:2559:2562:2693:3138:3139:3140:3141:3142:3354:3622:3865:3866:3867:3868:3871:3872:3873:3874:4605:5007:6117:6119:6120:6261:6742:7875:7903:8660:9040:10004:10400:10848:10967:11026:11232:11658:11914:12043:12296:12438:12663:12740:12760:12895:13148:13230:13439:13972:14181:14659:14721:21080:21451:21627:30012:30046:30054:30070:30089: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:2,LUA_SUMMARY:none X-HE-Tag: bomb25_817dd7d582855 X-Filterd-Recvd-Size: 3790 Date: Thu, 5 Oct 2017 19:58:08 -0400 From: Steven Rostedt To: Kees Cook Cc: Masami Hiramatsu , Ingo Molnar , Linus Torvalds , Peter Zijlstra , Alexei Starovoitov , Ananth N Mavinakayanahalli , "Paul E . McKenney" , Thomas Gleixner , LKML , "H . Peter Anvin" , Anil S Keshavamurthy , "David S . Miller" , Ian McDonald , Vlad Yasevich , Stephen Hemminger Subject: Re: [RFC PATCH -tip 0/5] kprobes: Abolish jprobe APIs Message-ID: <20171005195808.2525a155@vmware.local.home> In-Reply-To: References: <150724519527.5014.10207042218696587159.stgit@devbox> X-Mailer: Claws Mail 3.15.0-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, 5 Oct 2017 16:35:22 -0700 Kees Cook wrote: > > As far as I can see, tcp probe, dccp probe, sctp probe and lkdtm > > are using jprobe to probe function. Please consider to migrate. > > I'm happy to do so, but I'm quite unfamiliar with how to do this (I > didn't write lkdtm's jprobe code originally). lkdtm just wants to hook > function entry and call it's own function before. That can be done with ftrace. That's how live kernel patching works. It registers a callback via register_ftrace_function(), and with fentry (gcc 4.6 and later on x86), you can "hijack" the function. If you don't modify the regs->ip, then the function you hooked to will be called. > > It uses struct jprobe like this: > > .jprobe = { \ > .kp.symbol_name = _symbol, \ > .entry = (kprobe_opcode_t *)_entry, \ > }, \ > > and defines a bunch of handlers like this for the _symbol and _entry pairs: > > "do_IRQ", jp_do_irq), > ... > "tasklet_action", jp_tasklet_action), > > where all the handlers look exactly the same (and don't care about arguments): Hell, this is really easy then! > > static unsigned int jp_do_irq(unsigned int irq) > { > lkdtm_handler(); > jprobe_return(); > return 0; > } > > What's the right way to migrate away from jprobe for lkdtm? Perhaps something like: #include static void lkdtm_callback(unsigned long ip, unsigned long parent_ip, struct ftrace_ops *ops, struct pt_regs *regs) { lkdt_handler(); } static struct ftrace_ops ops = { .func = lkdtm_callback, }; [..] ftrace_set_filter(&ops, "do_IRQ", strlen("do_IRQ"), 0); ftrace_set_filter(&ops, "tasklet_action", strlen("tasklet_action"), 0); [..] /* to add the hook */ register_ftrace_function(&ops); Now all functions you set the filter for will be traced. Oh you may want to check the return status of ftrace_set_filter() otherwise, if they all fail, you will be tracing all functions. -- Steve