//------------------------------------------------------------------- // newcall.c // // This module dynamically installs a new 'method' for a Linux // system-call (without the necessity to recompile the kernel) // by overwriting an obsolete entry in the 'sys_call_table[]'. // NOTE: Our 'myexport.o' module must be previously installed. // // Our new 'method' merely increments the value of the integer // whose address is passed as the system-call's only argument. // // NOTE: Written and tested using Linux kernel version 2.4.20. // // programmer: ALLAN CRUSE // written on: 22 JUN 2004 // revised on: 28 SEP 2004 -- for Linux kernel version 2.4.26 //------------------------------------------------------------------- #include // for init_module() #include // for copy_to/from_user() #include // for __NR_break #define SUCCESS 0 #define OBSOLETE_ID __NR_break // system-call ID-number static char modname[] = "newcall"; static unsigned long save_old_syscall; extern unsigned long *sys_call_table; static asmlinkage long my_syscall( int * arg ) { int tmp; if ( copy_from_user( &tmp, arg, sizeof( int ) ) ) return -EFAULT; ++tmp; if ( copy_to_user( arg, &tmp, sizeof( int ) ) ) return -EFAULT; return SUCCESS; } int init_module( void ) { printk( "<1>\nInstalling \'%s\' \n", modname ); // modify the designated 'sys_call_table' entry save_old_syscall = sys_call_table[ OBSOLETE_ID ]; sys_call_table[ OBSOLETE_ID ] = (unsigned long)my_syscall; printk( " Installed a new \'method\' for " ); printk( "system-call number %d \n", OBSOLETE_ID ); return SUCCESS; } void cleanup_module( void ) { printk( "<1>Removing \'%s\' module\n", modname ); sys_call_table[ OBSOLETE_ID ] = save_old_syscall; } MODULE_LICENSE("GPL");