lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAGXu5jJC9eq16dy8r3mc26OcX-A3a3ysy8K7KZrZzuGwJqqqLw@mail.gmail.com>
Date:   Thu, 5 Oct 2017 17:06:04 -0700
From:   Kees Cook <keescook@...omium.org>
To:     Steven Rostedt <rostedt@...dmis.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, Oct 5, 2017 at 4:58 PM, Steven Rostedt <rostedt@...dmis.org> wrote:
> 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.

Ah-ha! Perfect, thank you! I'll give this a shot.

-Kees

-- 
Kees Cook
Pixel Security

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ