[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20171005195808.2525a155@vmware.local.home>
Date: Thu, 5 Oct 2017 19:58:08 -0400
From: Steven Rostedt <rostedt@...dmis.org>
To: Kees Cook <keescook@...omium.org>
Cc: Masami Hiramatsu <mhiramat@...nel.org>,
Ingo Molnar <mingo@...nel.org>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Peter Zijlstra <peterz@...radead.org>,
Alexei Starovoitov <ast@...nel.org>,
Ananth N Mavinakayanahalli <ananth@...ux.vnet.ibm.com>,
"Paul E . McKenney" <paulmck@...ux.vnet.ibm.com>,
Thomas Gleixner <tglx@...utronix.de>,
LKML <linux-kernel@...r.kernel.org>,
"H . Peter Anvin" <hpa@...or.com>,
Anil S Keshavamurthy <anil.s.keshavamurthy@...el.com>,
"David S . Miller" <davem@...emloft.net>,
Ian McDonald <ian.mcdonald@...di.co.nz>,
Vlad Yasevich <vyasevich@...il.com>,
Stephen Hemminger <stephen@...workplumber.org>
Subject: Re: [RFC PATCH -tip 0/5] kprobes: Abolish jprobe APIs
On Thu, 5 Oct 2017 16:35:22 -0700
Kees Cook <keescook@...omium.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
Powered by blists - more mailing lists