Skip to content

Commit

Permalink
x86: mmiotrace - trace memory mapped IO
Browse files Browse the repository at this point in the history
Mmiotrace is a tool for trapping memory mapped IO (MMIO) accesses within
the kernel. It is used for debugging and especially for reverse
engineering evil binary drivers.

Mmiotrace works by wrapping the ioremap family of kernel functions and
marking the returned pages as not present. Access to the IO memory
triggers a page fault, which will be handled by mmiotrace's custom page
fault handler. This will single-step the faulted instruction with the
MMIO page marked as present. Access logs are directed to user space via
relay and debug_fs.

This page fault approach is necessary, because binary drivers have
readl/writel etc. calls inlined and therefore extremely difficult to
trap with with e.g. kprobes.

This patch depends on the custom page fault handlers patch.

Signed-off-by: Pekka Paalanen <pq@iki.fi>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
  • Loading branch information
Pekka Paalanen authored and Thomas Gleixner committed May 24, 2008
1 parent 677aa9f commit 8b7d89d
Show file tree
Hide file tree
Showing 11 changed files with 1,677 additions and 0 deletions.
27 changes: 27 additions & 0 deletions arch/x86/Kconfig.debug
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,33 @@ config PAGE_FAULT_HANDLERS
register a function that is called on every page fault. Custom
handlers are used by some debugging and reverse engineering tools.

config MMIOTRACE
tristate "Memory mapped IO tracing"
depends on DEBUG_KERNEL && PAGE_FAULT_HANDLERS && RELAY && DEBUG_FS
default n
help
This will build a kernel module called mmiotrace.

Mmiotrace traces Memory Mapped I/O access and is meant for debugging
and reverse engineering. The kernel module offers wrapped
versions of the ioremap family of functions. The driver to be traced
must be modified to call these wrappers. A user space program is
required to collect the MMIO data.

See http://nouveau.freedesktop.org/wiki/MmioTrace
If you are not helping to develop drivers, say N.

config MMIOTRACE_TEST
tristate "Test module for mmiotrace"
depends on MMIOTRACE && m
default n
help
This is a dumb module for testing mmiotrace. It is very dangerous
as it will write garbage to IO memory starting at a given address.
However, it should be safe to use on e.g. unused portion of VRAM.

Say N, unless you absolutely know what you are doing.

#
# IO delay types:
#
Expand Down
2 changes: 2 additions & 0 deletions arch/x86/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ obj-$(CONFIG_KGDB) += kgdb.o
obj-$(CONFIG_VM86) += vm86_32.o
obj-$(CONFIG_EARLY_PRINTK) += early_printk.o

obj-$(CONFIG_MMIOTRACE) += mmiotrace/

obj-$(CONFIG_HPET_TIMER) += hpet.o

obj-$(CONFIG_K8_NB) += k8.o
Expand Down
1 change: 1 addition & 0 deletions arch/x86/kernel/init_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ static struct signal_struct init_signals = INIT_SIGNALS(init_signals);
static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
struct mm_struct init_mm = INIT_MM(init_mm);
EXPORT_UNUSED_SYMBOL(init_mm); /* will be removed in 2.6.26 */
EXPORT_SYMBOL_GPL(init_mm);

/*
* Initial thread structure.
Expand Down
4 changes: 4 additions & 0 deletions arch/x86/kernel/mmiotrace/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
obj-$(CONFIG_MMIOTRACE) += mmiotrace.o
mmiotrace-objs := pf_in.o kmmio.o mmio-mod.o

obj-$(CONFIG_MMIOTRACE_TEST) += testmmiotrace.o
Loading

0 comments on commit 8b7d89d

Please sign in to comment.