Understanding kprobes basics
A kernel probe (Kprobe, kprobe, or simply probe) is a way to hook or trap into (almost) any function in the kernel proper or within a kernel module, including interrupt handlers. You can think of kprobes as a dynamic analysis/instrumentation toolset that can even be used on production systems to collect (and later analyze) debugging and/or performance-related telemetry.
To use it, kprobes have to be enabled in the kernel; the kernel config CONFIG_KPROBES
must be set to y
(you'll typically find it under the General architecture-dependent options
menu). Selecting it automatically selects CONFIG_KALLSYMS=y
as well. With kprobes, you can set up three – all optional – types of traps or hooks. To illustrate, let's say you want to trap into the kernel function do_sys_open()
(which is the kernel function invoked when a userspace process or thread issues the open(2)
system call; see the System calls and where they land in the kernel section...