设备oopswhen模块被删除

时间:2015-12-25 04:13:28

标签: android linux-kernel

当我使用LKM挂钩关于Android内核的系统调用时,我出错了

但我不擅长Linux内核调试,我想知道如何处理这个问题。类似的问题告诉我原因是读取被阻止但是模块已经是rmmod,我想知道如何解决这个问题。

原因是我想要监控apk的行为。所以我选择了钩子Linux内核3.4.67(金鱼)和Android 4.4.4代码编译

这是我的代码,当我修改模块时,它真的得到了关于读取的动作。但是当我使用模块时,模拟器会直接获得oops,我终于找到原因在我的sys_read()钩子中,因为当我挂起系统调用时,它没关系。

#include <linux/kernel.h>
#include <linux/module.h>
#include<linux/init.h>
#include <linux/unistd.h>
#include <linux/semaphore.h>
#include <linux/moduleparam.h>
#include <asm/cacheflush.h>
#include<linux/delay.h>
#include<linux/file.h>
#include<linux/fs.h>
#include<linux/dirent.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("SafeCode han");
void  ** sys_call_table;

asmlinkage int (*original_call_read) (unsigned int, char*, int);
asmlinkage int hack_sys_read(unsigned int fd, char * buf, int count){

if(fd == 0 && count == 1)
{
    printk("something is read aha %s\n", buf);
}

return original_call_read(fd,buf count);

}
int init_module()
{
 //this is my sys_call_table address which found in System.map 
  sys_call_table =(void*)0xc000d984;
  printk(KERN_ALERT "testhahaha\n");
  original_call_read = sys_call_table[__NR_read];
  sys_call_table[__NR_read] = hack_sys_read;
  return 0;
}

/*when I need to rommd my module ,the devices oops..*/
 void cleanup_module()
{
  sys_call_table[__NR_read]=original_call_read;
//sys_call_table[__NR_open]=original_call_open;


}

所以,Plz帮助我〜谢谢〜,我想知道深度原因和解决方案

1 个答案:

答案 0 :(得分:0)

恢复syscall指针的先前值并卸载包含替换代码的模块是不安全的:此时某些进程可能会使用您的系统调用函数,并且当代码中断时它会非常沮丧。据我所知,没有任何保护措施。

内核模块不打算更改系统调用。要么修补内核代码本身,要么根本不接触系统调用并使用某种钩子,例如Kprobes的。