linux-uconsole/arch
Steven Rostedt (Red Hat) 1bd60326bf ftrace/jprobes/x86: Fix conflict between jprobes and function graph tracing
commit 237d28db03 upstream.

If the function graph tracer traces a jprobe callback, the system will
crash. This can easily be demonstrated by compiling the jprobe
sample module that is in the kernel tree, loading it and running the
function graph tracer.

 # modprobe jprobe_example.ko
 # echo function_graph > /sys/kernel/debug/tracing/current_tracer
 # ls

The first two commands end up in a nice crash after the first fork.
(do_fork has a jprobe attached to it, so "ls" just triggers that fork)

The problem is caused by the jprobe_return() that all jprobe callbacks
must end with. The way jprobes works is that the function a jprobe
is attached to has a breakpoint placed at the start of it (or it uses
ftrace if fentry is supported). The breakpoint handler (or ftrace callback)
will copy the stack frame and change the ip address to return to the
jprobe handler instead of the function. The jprobe handler must end
with jprobe_return() which swaps the stack and does an int3 (breakpoint).
This breakpoint handler will then put back the saved stack frame,
simulate the instruction at the beginning of the function it added
a breakpoint to, and then continue on.

For function tracing to work, it hijakes the return address from the
stack frame, and replaces it with a hook function that will trace
the end of the call. This hook function will restore the return
address of the function call.

If the function tracer traces the jprobe handler, the hook function
for that handler will not be called, and its saved return address
will be used for the next function. This will result in a kernel crash.

To solve this, pause function tracing before the jprobe handler is called
and unpause it before it returns back to the function it probed.

Some other updates:

Used a variable "saved_sp" to hold kcb->jprobe_saved_sp. This makes the
code look a bit cleaner and easier to understand (various tries to fix
this bug required this change).

Note, if fentry is being used, jprobes will change the ip address before
the function graph tracer runs and it will not be able to trace the
function that the jprobe is probing.

Link: http://lkml.kernel.org/r/20150114154329.552437962@goodmis.org

Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-01-27 07:52:32 -08:00
..
alpha arch: mm: pass userspace fault flag to generic fault handler 2014-11-21 09:22:56 -08:00
arc ARC: [nsimosci] move peripherals to match model to FPGA 2015-01-27 07:52:31 -08:00
arm ARM: mvebu: disable I/O coherency on non-SMP situations on Armada 370/375/38x/XP 2015-01-16 06:59:02 -08:00
arm64 arch: mm: pass userspace fault flag to generic fault handler 2014-11-21 09:22:56 -08:00
avr32 arch: mm: pass userspace fault flag to generic fault handler 2014-11-21 09:22:56 -08:00
blackfin blackfin updates for Linux 3.10 2013-05-10 07:21:16 -07:00
c6x arch: c6x: mm: include "asm/uaccess.h" to pass compiling 2013-07-21 18:21:29 -07:00
cris arch: mm: pass userspace fault flag to generic fault handler 2014-11-21 09:22:56 -08:00
frv arch: mm: pass userspace fault flag to generic fault handler 2014-11-21 09:22:56 -08:00
h8300 We get rid of the general module prefix confusion with a binary config option, 2013-05-05 10:58:06 -07:00
hexagon arch: mm: pass userspace fault flag to generic fault handler 2014-11-21 09:22:56 -08:00
ia64 arch: mm: pass userspace fault flag to generic fault handler 2014-11-21 09:22:56 -08:00
m32r arch: mm: pass userspace fault flag to generic fault handler 2014-11-21 09:22:56 -08:00
m68k arch: mm: pass userspace fault flag to generic fault handler 2014-11-21 09:22:56 -08:00
metag arch: mm: pass userspace fault flag to generic fault handler 2014-11-21 09:22:56 -08:00
microblaze arch: mm: pass userspace fault flag to generic fault handler 2014-11-21 09:22:56 -08:00
mips MIPS: Loongson: Make platform serial setup always built-in. 2014-12-06 15:05:46 -08:00
mn10300 arch: mm: pass userspace fault flag to generic fault handler 2014-11-21 09:22:56 -08:00
openrisc arch: mm: pass userspace fault flag to generic fault handler 2014-11-21 09:22:56 -08:00
parisc arch: mm: pass userspace fault flag to generic fault handler 2014-11-21 09:22:56 -08:00
powerpc powerpc: 32 bit getcpu VDSO function uses 64 bit instructions 2014-12-16 09:09:43 -08:00
s390 groups: Consolidate the setgroups permission checks 2015-01-08 09:58:16 -08:00
score arch: mm: pass userspace fault flag to generic fault handler 2014-11-21 09:22:56 -08:00
sh arch: mm: pass userspace fault flag to generic fault handler 2014-11-21 09:22:56 -08:00
sparc sparc64: Fix constraints on swab helpers. 2014-12-06 15:05:46 -08:00
tile arch: mm: pass userspace fault flag to generic fault handler 2014-11-21 09:22:56 -08:00
um arch: mm: pass userspace fault flag to generic fault handler 2014-11-21 09:22:56 -08:00
unicore32 arch: mm: pass userspace fault flag to generic fault handler 2014-11-21 09:22:56 -08:00
x86 ftrace/jprobes/x86: Fix conflict between jprobes and function graph tracing 2015-01-27 07:52:32 -08:00
xtensa arch: mm: pass userspace fault flag to generic fault handler 2014-11-21 09:22:56 -08:00
.gitignore
Kconfig microblaze: fix clone syscall 2013-08-20 08:43:02 -07:00