Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1587835

Re: kprobes vs __ex_table[]

From Peter Zijlstra <peterz@infradead.org>
Newsgroups linux.kernel
Subject Re: kprobes vs __ex_table[]
Date 2017-02-24 18:50 +0100
Message-ID <tesad-3vj-11@gated-at.bofh.it> (permalink)
References <te6t3-51I-7@gated-at.bofh.it> <tecyt-Yd-9@gated-at.bofh.it> <tekml-6zZ-1@gated-at.bofh.it> <ter4u-2Kh-21@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Sat, Feb 25, 2017 at 01:34:15AM +0900, Masami Hiramatsu wrote:
> > Ah, but that is only #PF, we also use __ex_table on other faults/traps,
> > like #GP which would need help in do_general_protection(),
> 
> #GP is also handled via kprobe_exceptions_notify().

Ah! that's where its hidden :-) Thanks!

> > It looks like it rewrites regs->ip, which would make return from fault
> > return to the wrong place, no?
> 
> Hmm, when regs->ip is reset to the original place, kprobe_fault_handler()
> returns 0 and normal #PF handler fixup pages etc. and retry from the
> original place. This might kick kprobes again and do singlestep.
> 
> So, yes, it may not enough for other faults if those will not only check
> regs->ip, but read the instruction pointed by regs->ip (as your patch).
> In that case you need to use recover_probed_instruction() instead of
> probe_kernel_address(). (BTW, recover_probed_instruction() uses memcpy()
> without checking kernel_text, it should use probe_kernel_address().)

> > One more complication with __ex_table and optimized kprobes is that we
> > need to be careful not to clobber __ex_table[].fixup. It would be very
> > bad if the optimized probe were to clobber the address we let the fixup
> > return to -- or that needs fixups too, _after_ running
> > __ex_table[].handler().
> 
> can_optimize() takes care about that case. If the probe target function
> (not only probed address) includes an exception address, it rejects
> optimizing probes.

Ah, so it does search_exception_tables(), which avoids clobbering actual
exception instructions, and most fixups live in .text.fixup and I cannot
actually find if that is excluded.

In any case, thanks for the pointers, I'll see if I can spot any actual
holes.

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

kprobes vs __ex_table[] Peter Zijlstra <peterz@infradead.org> - 2017-02-23 19:40 +0100
  Re: kprobes vs __ex_table[] Masami Hiramatsu <mhiramat@kernel.org> - 2017-02-24 02:10 +0100
    Re: kprobes vs __ex_table[] Peter Zijlstra <peterz@infradead.org> - 2017-02-24 10:30 +0100
      Re: kprobes vs __ex_table[] Masami Hiramatsu <mhiramat@kernel.org> - 2017-02-24 17:40 +0100
        Re: kprobes vs __ex_table[] Peter Zijlstra <peterz@infradead.org> - 2017-02-24 18:50 +0100
          [RFC PATCH 1/2] kprobes/x86: Use probe_kernel_read instead of memcpy Masami Hiramatsu <mhiramat@kernel.org> - 2017-02-27 17:20 +0100
          [RFC PATCH 2/2] kprobes/x86: Exit single-stepping before trying fixup_exception Masami Hiramatsu <mhiramat@kernel.org> - 2017-02-27 17:20 +0100
          [RFC PATCH 0/2] kprobes/x86: Handle probing on ex_table cases Masami Hiramatsu <mhiramat@kernel.org> - 2017-02-27 17:20 +0100
      Re: kprobes vs __ex_table[] Masami Hiramatsu <mhiramat@kernel.org> - 2017-02-28 17:30 +0100
        [PATCH] [BUGFIX] kprobes/x86: Fix to check __ex_table entry by probed address Masami Hiramatsu <mhiramat@kernel.org> - 2017-02-28 18:50 +0100

csiph-web