A negative return value can usually be interpreted as a negated errno
value. Have a look at http://www.virtsync.com/c-error-codes-include-errno or so:
#define ENOENT 2 /* No such file or directory */
So the problem seems to be that register_kprobe
could not find something, probably the list_add
symbol. Let's dig into the source to figure out why it is that way.
register_kprobe
calls kprobe_addr
to resolve the symbol name, which in turn calls kprobe_lookup_name
, which is a #define
for kallsyms_lookup_name
. So it seems that you need to get the symbol you want to hook into kallsyms for this to work.
For documentation about kprobes, have a look at Documentation/kprobes.txt in the kernel source tree. About kprobe'ing inline functions, it says:
If you install a probe in an inline-able function, Kprobes makes no attempt to chase down all inline instances of the function and install probes there. gcc may inline a function without being asked, so keep this in mind if you're not seeing the probe hits you expect.
So, it doesn't really work for inlined functions.
Now that we have figured out the problems, let's look for solutions. You'll probably need to recompile your kernel for this though.
First, make sure that the kernel configuration option CONFIG_KALLSYMS_ALL
is turned on – that makes sure that kallsyms knows about more symbols. Then, try moving the implementation of list_add
into a seperate .c
file and adding __attribute__ ((noinline))
to it. That new kernel build is going to be slower, but I think that your kprobe module should work with it.