title: Change address of kernel function pointer
body: <p>I'm written a module to try and change the address of the exported symbol 'do_fork' to point to my function first before calling the original do_fork address. So far I can't seem to change the address as it gives me the error 'lvalue required as left operand of assignment.'</p>
  
  <p>I'm not sure how to change the pointer to do_fork() to my function fake_fork();</p>
  
  <pre><code>#include &lt;linux/fs.h&gt;
  #include &lt;linux/init.h&gt;
  #include &lt;linux/proc_fs.h&gt;
  #include &lt;linux/seq_file.h&gt;
  #include &lt;linux/sched.h&gt;
  #include &lt;linux/module.h&gt;
  
  int c=0;
  
  long fake_fork(unsigned long a, unsigned long b, unsigned long c, int __user *d, int __user *e)
  {
      ++c;
  
      return do_fork(a, b, c, d, e);
  }
  
  EXPORT_SYMBOL(fake_fork);
  
  static int fork_proc_show(struct seq_file *m, void *v)
  {
      seq_printf(m, "System Call fork called: %d times.\n", c);
      return 0;
  }
  
  static int fork_proc_open(struct inode *inode, struct file *file)
  {
      return single_open(file, fork_proc_show, NULL);
  }
  
  static const struct file_operations fork_proc_fops = {
      .open       = fork_proc_open,
      .read       = seq_read,
      .llseek     = seq_lseek,
      .release    = single_release,
  };
  
  static int __init proc_fork_init(void)
  {
      do_fork = fake_fork;  // &lt;-- Not working
  
      printk("init proc forkcounter\n");
      proc_create("forkcounter", 0, NULL, &amp;fork_proc_fops);
      return 0;
  }
  
  static void __exit cleanup_fork_module(void)
  {
      remove_proc_entry("forkcounter",NULL);
  
      printk("cleanup proc forkcounter\n");
  }
  
  module_init(proc_fork_init);
  module_exit(cleanup_fork_module);
  </code></pre>