linux/arch
Steven Rostedt (Red Hat) 8676ef6461 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 08:18:56 -08:00
..
alpha alpha: fix broken network checksum 2014-01-31 09:21:55 -08:00
arc ARC: switch to generic ENTRY/END assembler annotations 2015-01-27 08:18:54 -08:00
arm ARM: mvebu: disable I/O coherency on non-SMP situations on Armada 370/375/38x/XP 2015-01-16 06:59:34 -08:00
arm64 arm64: kernel: fix __cpu_suspend mm switch on warm-boot 2015-01-16 06:59:34 -08:00
avr32 avr32: add generic vga.h to Kbuild 2014-02-17 11:24:48 +01:00
blackfin Merge branch 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media 2014-01-31 09:31:14 -08:00
c6x Build fix for c6x 2014-03-07 09:52:46 -08:00
cris cris: convert ffs from an object-like macro to a function-like macro 2014-03-10 17:26:21 -07:00
frv Merge branch 'kbuild' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild 2014-01-30 16:58:05 -08:00
hexagon
ia64 hugetlb: restrict hugepage_migration_support() to x86_64 2014-06-30 20:11:53 -07:00
m32r
m68k m68k: Disable/restore interrupts in hwreg_present()/hwreg_write() 2014-10-30 09:38:21 -07:00
metag parisc,metag: Do not hardcode maximum userspace stack size 2014-07-17 16:21:03 -07:00
microblaze microblaze: Fix a typo when disabling stack protection 2014-02-10 07:44:11 +01:00
mips MIPS: Loongson: Make platform serial setup always built-in. 2014-12-06 15:55:33 -08:00
mn10300 Merge branch 'kbuild' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild 2014-01-30 16:58:05 -08:00
openrisc OpenRISC updates for 3.14 2014-01-30 17:08:41 -08:00
parisc parisc: fix out-of-register compiler error in ldcw inline assembler function 2015-01-27 08:18:55 -08:00
powerpc powerpc/book3s: Fix partial invalidation of TLBs in MCE code. 2015-01-16 06:59:30 -08:00
s390 groups: Consolidate the setgroups permission checks 2015-01-08 10:00:49 -08:00
score Merge branch 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media 2014-01-31 09:31:14 -08:00
sh sh: fix sh770x SCIF memory regions 2014-11-14 09:00:07 -08:00
sparc sparc64: Fix constraints on swab helpers. 2014-12-06 15:55:33 -08:00
tile hugetlb: restrict hugepage_migration_support() to x86_64 2014-06-30 20:11:53 -07:00
um um: ubd: Fix for processes stuck in D state forever 2014-11-14 08:59:49 -08:00
unicore32 mm: per-thread vma caching 2014-10-09 12:21:29 -07:00
x86 ftrace/jprobes/x86: Fix conflict between jprobes and function graph tracing 2015-01-27 08:18:56 -08:00
xtensa xtensa: re-wire umount syscall to sys_oldumount 2014-11-21 09:23:01 -08:00
.gitignore
Kconfig