Question

I'm writing a kernel module under Scientific Linux 6.3 x86_64 and I'm looking to use kprobes. In this module, I need access to the first argument of a function on return, so jprobes are out.

I found this very helpful post: Getting function arguments using kprobes

However, when I try accessing regs->rdi inside my probe, the compiler complains with

error: ‘struct pt_regs’ has no member named ‘rdi’

During my module initialization, I run this check with no problems:

#ifndef CONFIG_X86_64
 printk(KERN_ALERT "Error: this module only supports x86_64!\n");
 return -EINVAL;
#endif

Is there anything else I should be looking at? uname -r returns 2.6.32-279.14.1.el6.x86_64.debug

Here is a MWE:

#include <linux/module.h> 
#include <linux/kernel.h>
#include <linux/kprobes.h>
#include <linux/blkdev.h>

static int kprobe_test(struct kprobe *p, struct pt_regs *regs) {
  printk(KERN_INFO "rdi: %p\n", regs->rdi);
  return 0;
}

static struct kprobe myprobe = {
  .pre_handler = NULL,
  .post_handler = kprobe_test,
  .fault_handler = NULL,
  .addr = (kprobe_opcode_t *) generic_make_request,
};

int init_module(void) {
  register_kprobe(&myprobe);
  return 0;
}

void cleanup_module(void) {
  unregister_kprobe(&myprobe);
}

Which results in:

...
/home/user/kmod/kprobe_64_mwe/kprobe_mwe.c:7: error: ‘struct pt_regs’ has no member named ‘rdi’
...
Was it helpful?

Solution

The definition of pt_reg changes when __KERNEL__ is defined. Try using di instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top