title: Unable to handle kernel paging request at X while intercepting the system call
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2103315/linux-kernel-system-call-hooking-example">Linux Kernel: System call hooking example</a>  </p>
  </blockquote>
  
  
  
  <p>I have been trying to hook the system calls at the kernel level.I got the basic idea from this <a href="https://stackoverflow.com/questions/2103315/linux-kernel-system-call-hooking-example">question</a>.The system call I was trying to intercept was the <strong>fork()</strong>. So I found out the address of the <strong>sys_call_table</strong> from System.map and it turned out to be 0xc12c9e90.Now I wrote the module as below.</p>
  
  <pre><code>#include&lt;linux/kernel.h&gt;
  #include&lt;linux/module.h&gt;
  #include&lt;linux/unistd.h&gt;
  #include&lt;linux/semaphore.h&gt;
  #include&lt;asm/cacheflush.h&gt;
  MODULE_LICENSE("GPL");
  void **sys_call_table;
  unsigned long addr;
  asmlinkage int (*original_call)(struct pt_regs);
  asmlinkage int our_call(struct pt_regs regs)
  {
          printk("Intercepted sys_fork");
          return original_call(regs);
  }
  static int __init p_entry(void)
  {
          struct page *pg;
          printk(KERN_ALERT "Module Intercept inserted");
          sys_call_table=(void *)0xc12c9e90;
          pg=virt_to_page(sys_call_table);
          addr=(unsigned long)page_address(pg);
          set_memory_rw(addr,1);
          original_call=sys_call_table[__NR_fork];
          sys_call_table[__NR_fork]=our_call;
          set_memory_ro(addr,1);
          return 0;
  }
  static void __exit p_exit(void)
  {
          sys_call_table[__NR_fork]=original_call;
          set_memory_ro(addr,1);
          printk(KERN_ALERT "Module Intercept removed");
  }
  module_init(p_entry);
  module_exit(p_exit);
  </code></pre>
  
  <p>I compiled the module and tried to insert it to the kernel.Unfortunately the dmesg output gave me a message as follows <strong>BUG:unable to handle kernel paging request at c12c9e98</strong> and here is the ellaborate dmesg out put</p>
  
  <p><img src="https://i.stack.imgur.com/WEtt4.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/HayYe.png" alt="enter image description here"></p>
  
  <p>As an experiment to find out the problem, I simply commented out the line</p>
  
  <pre><code> sys_call_table[__NR_fork]=our_call;
  </code></pre>
  
  <p>After that I repeated the compilation and followed by insertion.And it didn't show up any errors. So I concluded that ,the above specified line which assigns the new function in to sys_call_table is the problem. But I don't know what could be causing it and how to solve it.Can any one help me out to solve it?</p>