kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* Hooking a system call.
@ 2012-03-26  4:45 V.Ravikumar
  2012-03-26  7:48 ` Mulyadi Santosa
  0 siblings, 1 reply; 11+ messages in thread
From: V.Ravikumar @ 2012-03-26  4:45 UTC (permalink / raw)
  To: kernelnewbies

As part of auditing purpose I need to intercept/hook open/read/write system
calls.

I tried with below sample program. When I do a insmod of the module that
was built, my system was hanged. On some re-search I came to know that we
can not modify system call table as it is read only.

void **sys_call_table;

asmlinkage int (*original_call) (const char*, int, int);

asmlinkage int our_sys_open(const char* file, int flags, int mode)
{
   printk("A file was opened\n");
   return original_call(file, flags, mode);
}

int init_module()
{
    // sys_call_table address in System.map
    sys_call_table = (void*)0xc061e4e0;
    original_call = sys_call_table[__NR_open];
    sys_call_table[__NR_open] = our_sys_open;
}

void cleanup_module()
{
   // Restore the original call
   sys_call_table[__NR_open] = original_call;
}

As I was lack of knowledge into kernel development.Could somebody help me
out here ?
I'm working on RHEL-5 machine with Linux kernel version 2.6.18
Thanks & Regards,
Ravi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120326/826c6142/attachment.html 

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-03-28  6:10 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-26  4:45 Hooking a system call V.Ravikumar
2012-03-26  7:48 ` Mulyadi Santosa
2012-03-26  8:14   ` V.Ravikumar
2012-03-26  8:27     ` Mulyadi Santosa
2012-03-26 13:04       ` Peter Senna Tschudin
2012-03-26 13:43     ` Javier Martinez Canillas
2012-03-26 15:30     ` Ravishankar
2012-03-26 19:33       ` richard -rw- weinberger
2012-03-26 20:22     ` Fredrick
2012-03-28  3:46   ` V.Ravikumar
2012-03-28  6:10     ` rohan puri

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).