linux kernel - register_kretprobe fails with a return value of -2 -


i have written kretprobe hook on randomize_stack_top() function mentioned in fs/binfmt_elf.c file. on loading lkm insmod register_kretprobe() call fails return value of -2. how go debugging/rectifying in order module started ?

#include <linux/kernel.h> #include <linux/slab.h> #include <linux/module.h> #include <linux/kprobes.h> #include <linux/binfmts.h> #include <linux/elf.h> #include <linux/types.h> #include <linux/errno.h> #include <asm/uaccess.h> #include <asm/current.h> #include <asm/param.h>  /* global variables */ int randomize_stack_retval;  //  randomize_stack_top() kretprobe specific declarations  static char stack_name[name_max] = "randomize_stack_top";  static int randomize_stack_top_entry_handler(struct kretprobe_instance *ri, struct pt_regs *regs) {     return 0; }  static int randomize_stack_top_ret_handler(struct kretprobe_instance *ri, struct pt_regs *regs) {     randomize_stack_retval = regs_return_value(regs);   //store in global variable     printk(kern_info "%d\n",randomize_stack_retval);     return 0; }  //randomize_stack_top return probe static struct kretprobe randomize_kretprobe = {     .handler = randomize_stack_top_ret_handler,     .entry_handler = randomize_stack_top_entry_handler,     .maxactive = nr_cpus, };  /* register kretprobe */ static int __init kretprobe_init(void) {     int ret;      randomize_kretprobe.kp.symbol_name = stack_name;      ret = register_kretprobe(&randomize_kretprobe);     if (ret < 0) {         printk(kern_info "register_kretprobe failed, returned %d\n",                 ret);         return -1;     }     printk(kern_info "planted return probe @ %s: %p\n",             randomize_kretprobe.kp.symbol_name, randomize_kretprobe.kp.addr);      return 0; }  /* unregister kretprobe */ static void __exit kretprobe_exit(void) {     unregister_kretprobe(&randomize_kretprobe);     printk(kern_info "kretprobe @ %p unregistered\n",             randomize_kretprobe.kp.addr);      //  nmissed > 0 suggests maxactive set low.      printk(kern_info "missed probing %d instances of %s\n",   randomize_kretprobe.nmissed, randomize_kretprobe.kp.symbol_name);  }  module_init(kretprobe_init); module_exit(kretprobe_exit); module_license("gpl"); 

-2 corresponds -enoent (you can check in include/uapi/asm-generic/errno-base.h). probably, means kprobe cannot find symbol given name.

note, randomize_stack_top static function short implementation , used once. can inlined gcc.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -