PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Function Hijacking - put_queue



Lord Kefir
09-09-2005, 10:21
Guten Morgen!

Wie der Titel schon sagt, möchte ich gerne die Funktion 'put_queue' des Linuxkernels abfangen. Programmierung im Kernelspace ist völliges Neuland für mich, dennoch hat folgender Code bei mir zu Hause einwandfrei funktioniert:



#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/string.h>

#define LICENSE "GPL"
#define CODESIZE 7
#define ADDRESS 0xc027a860
#define VERSION "0.1"

// global variables:
void (*put_queue)(int) = (void(*)(int))ADDRESS;

static char code[CODESIZE];
static char jump[CODESIZE] =
"\xb8\x00\x00\x00\x00"
"\xff\xe0";

// prototypes:
void _put_queue (int ch);

/* ---------------------------------
function: _put_queue
--------------------------------- */
void _put_queue (int ch) {
printk ("keycode: %d\n", ch);

memcpy (put_queue, code, CODESIZE);
put_queue (ch);
memcpy (put_queue, jump, CODESIZE);
}

/* ---------------------------------
function: init_module
--------------------------------- */
int init_module (void) {
*(long*)&jump[1] = (long)_put_queue;
memcpy (code, put_queue, CODESIZE);
memcpy (put_queue, jump, CODESIZE);

return (0);
}

/* ---------------------------------
function: cleanup_module
--------------------------------- */
void cleanup_module (void) {
memcpy (put_queue, code, CODESIZE);
}

// Macros:
MODULE_LICENSE (LICENSE);


Bei meiner Freundin am Rechner kompiliert hat das Modul recht fatale Folgen: der Rechner läuft zwar noch, allerdings bekomme ich keine Tastaturausgaben mehr. Nachdem Entladen des Moduls funktioniert alles wieder einwandfrei.

Wie sich herausgestellt hat, ist wahrscheinlich die Adresse 0xc027a860 falsch - ich habe allerdings keine Ahnung wieso. Ermittelt habe ich sie so:



lordkefir@linda:~$ grep put_queue /proc/kallsyms
c027a860 t put_queue
c02a5700 t cfq_put_queue


Hier kann doch eigentlich nicht der Fehler liegen, oder? Über jegliche Hilfe wäre ich sehr dankbar...

Mfg, Lord Kefir