From: Masami Hiramatsu <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Kees Cook <keescook@chromium.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Ingo Molnar <mingo@kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Peter Zijlstra <peterz@infradead.org>,
Alexei Starovoitov <ast@kernel.org>,
Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>,
"Paul E . McKenney" <paulmck@linux.vnet.ibm.com>,
Thomas Gleixner <tglx@linutronix.de>,
LKML <linux-kernel@vger.kernel.org>,
"H . Peter Anvin" <hpa@zytor.com>,
Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>,
"David S . Miller" <davem@davemloft.net>,
Ian McDonald <ian.mcdonald@jandi.co.nz>,
Vlad Yasevich <vyasevich@gmail.com>,
Stephen Hemminger <stephen@networkplumber.org>
Subject: Re: [RFC PATCH -tip 0/5] kprobes: Abolish jprobe APIs
Date: Fri, 6 Oct 2017 13:49:59 +0900 [thread overview]
Message-ID: <20171006134959.e50c904ba6f302126cf4418c@kernel.org> (raw)
In-Reply-To: <20171005195808.2525a155@vmware.local.home>
On Thu, 5 Oct 2017 19:58:08 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:
> On Thu, 5 Oct 2017 16:35:22 -0700
> Kees Cook <keescook@chromium.org> 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 <linux/ftrace.h>
>
> 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, could you write a documentation how to use ftrace callback?
I think I should update the Documentation/kprobes.txt so that jprobe
user can easily migrate on that.
Thank you,
--
Masami Hiramatsu <mhiramat@kernel.org>
next prev parent reply other threads:[~2017-10-06 4:50 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-05 23:13 [RFC PATCH -tip 0/5] kprobes: Abolish jprobe APIs Masami Hiramatsu
2017-10-05 23:13 ` [RFC PATCH -tip 1/5] kprobes: Use ENOTSUPP instead of ENOSYS Masami Hiramatsu
2017-10-20 8:57 ` Ingo Molnar
2017-10-20 15:51 ` Masami Hiramatsu
2017-10-05 23:14 ` [RFC PATCH -tip 2/5] kprobes: Abolish jprobe APIs Masami Hiramatsu
2017-10-20 12:26 ` [tip:perf/core] kprobes: Disable the jprobes APIs tip-bot for Masami Hiramatsu
2017-10-05 23:15 ` [RFC PATCH -tip 3/5] kprobes: Disable jprobe test code Masami Hiramatsu
2017-10-20 12:26 ` [tip:perf/core] kprobes: Disable the jprobes " tip-bot for Masami Hiramatsu
2017-10-05 23:15 ` [RFC PATCH -tip 4/5] kprobes: Remove jprobe sample code Masami Hiramatsu
2017-10-20 12:27 ` [tip:perf/core] kprobes: Remove the jprobes " tip-bot for Masami Hiramatsu
2017-10-05 23:16 ` [RFC PATCH -tip 5/5] kprobes: docs: Remove jprobe related document Masami Hiramatsu
2017-10-20 12:27 ` [tip:perf/core] kprobes/docs: Remove jprobes related documents tip-bot for Masami Hiramatsu
2017-10-05 23:35 ` [RFC PATCH -tip 0/5] kprobes: Abolish jprobe APIs Kees Cook
2017-10-05 23:58 ` Steven Rostedt
2017-10-06 0:06 ` Kees Cook
2017-10-06 4:49 ` Masami Hiramatsu [this message]
2017-10-06 12:58 ` Steven Rostedt
2017-10-06 15:34 ` Steven Rostedt
2017-10-07 5:24 ` Stafford Horne
2017-10-09 16:48 ` Steven Rostedt
2017-10-07 8:55 ` Ingo Molnar
2017-10-09 16:45 ` Steven Rostedt
2017-10-07 9:35 ` Masami Hiramatsu
2017-10-09 16:59 ` Steven Rostedt
2017-10-09 15:33 ` Jonathan Corbet
2017-10-09 16:20 ` Steven Rostedt
2017-10-09 16:33 ` Jonathan Corbet
2017-10-09 16:41 ` Steven Rostedt
2017-10-09 18:10 ` Steven Rostedt
2017-10-10 14:02 ` Steven Rostedt
2017-10-06 0:32 ` Masami Hiramatsu
2017-10-06 1:11 ` Steven Rostedt
2017-10-06 4:47 ` Masami Hiramatsu
2017-10-20 12:22 ` Ingo Molnar
2017-10-20 13:32 ` Kees Cook
2017-10-20 15:17 ` Ingo Molnar
2017-10-20 16:28 ` Kees Cook
2017-10-21 8:06 ` Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171006134959.e50c904ba6f302126cf4418c@kernel.org \
--to=mhiramat@kernel.org \
--cc=ananth@linux.vnet.ibm.com \
--cc=anil.s.keshavamurthy@intel.com \
--cc=ast@kernel.org \
--cc=davem@davemloft.net \
--cc=hpa@zytor.com \
--cc=ian.mcdonald@jandi.co.nz \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=stephen@networkplumber.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=vyasevich@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox