Skip to contentSkip to conversation

LKM function call on kernel function call?

DISCUSSION S 4 participants 4 messages Jul 5, 2005 – Jul 14, 2005

lore
Share & tools
lore

S

author
#0 lore raw

Is it possible to code a loadable module having function1(), which would be called, everytime a particular function of the kernel is called? If not, atleast a way this could be done without re-compiling the whole kernel and rebooting the system?

Example:

My LKM:
-------------

init_module() {
...
}

function1() {
...
}

cleanup_module() {
...
}

I want function1() to be called, everytime the function ide_do_rw_disk() of ide-disk.c is called. I do not want to re-compile the complete kernel to do this.

Thanks in advance,

Regards,
S

#1 lore raw
Quoted 4 lines · On Tue, 2005-07-05 at 16:23 +0800, S wrote:

Is it possible to code a loadable module having function1(), which would be called, everytime a particular function of the kernel is called? If not, atleast a way this could be done without re-compiling the whole kernel and rebooting the system?

why don't you want to compile the whole kernel ? You have the source code and it for sure is the easiest way to add this (debug?) hack...

#2 lore raw
In reply to S

Le 05/07/05 16:23 +0800, S écrivit:

Quoted 4 lines

I want function1() to be called, everytime the function ide_do_rw_disk() of ide-disk.c is called. I do not want to re-compile the complete kernel to do this.

You're looking for kprobes
http://www-106.ibm.com/developerworks/library/l-kprobes.html?ca=dgr-lnxw07Kprobe
Regards,
Frederik Deweerdt

Signature · 8 lines
o---------------------------------------------o
| http://open-news.net : l'info alternative   |
| Tech - Sciences - Politique - International |
o---------------------------------------------o
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw
In reply to S

You can also look about some methods of "function redirection hooks"... add some opcodes at the start of the "hooked function" (something like to add a CALL or JMP pointing to the address of your function). There are docs about this subject, but unfortunately I couldn't find anything now (http://www.ouah.org/p59-0x08.txt is not exactly what I'm talking about, it's talking about ELF redirection). It's a dirty thing to do, and it's not intended to be done in any production thing (in fact, it's a *hack*).

Quoted 36 lines · On 7/5/05, S <[email protected]> wrote:

Is it possible to code a loadable module having function1(), which would be called, everytime a particular function of the kernel is called? If not, atleast a way this could be done without re-compiling the whole kernel and rebooting the system?

Example:

My LKM:
-------------

init_module() {
...
}

function1() {
...
}

cleanup_module() {
...
}

I want function1() to be called, everytime the function ide_do_rw_disk() of ide-disk.c is called. I do not want to re-compile the complete kernel to do this.

Thanks in advance,

Regards,
S
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 1 line
# (perl -e "while (1) { print "\x90"; }") | dd of=/dev/evil