Exemple #1
0
static void
stapkp_unregister_probe(struct stap_dwarf_probe *sdp)
{
   struct stap_dwarf_kprobe *sdk = sdp->kprobe;

   if (!sdp->registered_p)
      return;

   if (sdp->return_p) {
      unregister_kretprobe (&sdk->u.krp);
      dbug_stapkp("-kretprobe %p\n", sdk->u.krp.kp.addr);
   } else {
      unregister_kprobe (&sdk->u.kp);
      dbug_stapkp("-kprobe %p\n", sdk->u.kp.addr);
   }

#if defined(__ia64__)
   unregister_kprobe (&sdk->dummy);
   dbug_stapkp("-kprobe %p\n", sdk->dummy.addr);
#endif

   sdp->registered_p = 0;

   stapkp_add_missed(sdp);

   // PR16861: kprobes may have left some things in the k[ret]probe struct.
   // Let's reset it to be sure it's safe for re-use.
   memset(sdk, 0, sizeof(struct stap_dwarf_kprobe));
}
Exemple #2
0
void cleanup_module(void)
{
    unregister_kprobe(&kp1);
    unregister_kretprobe(&kp1_ret);
    if (is_kp2) {
        unregister_kprobe(&kp2);
        unregister_kretprobe(&kp2_ret);
    }
    printk("kprobe unregistered\n");
}
Exemple #3
0
static void __exit my_exit (void)
{
    unregister_kprobe (&kp_mod_timer);
    unregister_kprobe (&kp_del_timer);
#ifdef CONFIG_SMP
    unregister_kprobe (&kp_del_timer_sync);
#endif
    printk (KERN_INFO "\n\n FINAL STATISTICS:\n\n");
    printk (KERN_INFO "count_mod_timer = %d\n", count_mod_timer);
    printk (KERN_INFO "count_del_timer = %d\n", count_del_timer);
    printk (KERN_INFO "count_del_timer_sync = %d\n", count_del_timer_sync);
    printk (KERN_INFO "Bye: module unloaded from 0x%p\n", my_exit);
}
Exemple #4
0
// The probed addr is given by the user script
// The user script scan /proc/kallsyms
int init_module(void)
{
    int	ret;

    kp1.pre_handler = kp1_pre_handler;
//	kp1.post_handler = kp1_post_handler;
    kp1_ret.handler = kp1_ret_handler;

    if (NULL == (long *) addr_1st) {
        printk("must provide an instructmented addr\n");
        return 1;
    } else {
        printk("addr_1st is %lx\n", addr_1st);
    }
    // need to export kallsyms_lookup_name first
    kp1.addr = kp1_ret.kp.addr = (kprobe_opcode_t *)addr_1st;

    if ((ret = register_kprobe(&kp1)) < 0) {
        printk("register_kprobe failed, ret %d\n", ret);
        return ret;
    }
    if ((ret = register_kretprobe(&kp1_ret)) < 0) {
        printk("register_kretprobe failed, ret %d\n", ret);
        unregister_kprobe(&kp1);
        return ret;
    }
    printk("kprobe 1 registered\n");

    if (NULL == (long *) addr_2nd) {
        printk("2nd param is ignored\n");
    } else {
        printk("addr_2nd is %lx\n", addr_2nd);

        // need to export kallsyms_lookup_name first
        kp2.addr = kp2_ret.kp.addr = (kprobe_opcode_t *)addr_2nd;

        if ((ret = register_kprobe(&kp1)) < 0) {
            printk("register_kprobe failed, ret %d\n", ret);
            return ret;
        }
        if ((ret = register_kretprobe(&kp1_ret)) < 0) {
            printk("register_kretprobe failed, ret %d\n", ret);
            unregister_kprobe(&kp1);
            return ret;
        }

        is_kp2 = true;
        printk("kprobe 2 registered\n");
    }
    return 0;
}
static void
stapkp_unregister_probe(struct stap_kprobe_probe *skp)
{
    struct stap_kprobe *sk = skp->kprobe;

    if (!skp->registered_p)
        return;

    if (skp->return_p) {
        unregister_kretprobe (&sk->u.krp);
        if (skp->symbol_name)
            dbug_stapkp("-kretprobe %s:%d\n", sk->u.krp.kp.symbol_name,
                        sk->u.krp.kp.offset);
        else
            dbug_stapkp("-kretprobe %p\n", sk->u.krp.kp.addr);
    } else {
        unregister_kprobe (&sk->u.kp);
        if (skp->symbol_name)
            dbug_stapkp("-kprobe %s:%u\n", sk->u.kp.symbol_name,
                        sk->u.kp.offset);
        else
            dbug_stapkp("-kprobe %p\n", sk->u.kp.addr);
    }

#if defined(__ia64__)
    unregister_kprobe (&sk->dummy);
    dbug_stapkp("-kprobe %p\n", sk->dummy.addr);
#endif

    skp->registered_p = 0;

    stapkp_add_missed(skp);

#if LINUX_VERSION_CODE < KERNEL_VERSION(3,11,0)
    if (skp->symbol_name != NULL) {
        if (skp->return_p) {
            if (sk->u.krp.kp.symbol_name != NULL)
                kfree(sk->u.krp.kp.symbol_name);
        }
        else {
            if (sk->u.kp.symbol_name != NULL)
                kfree(sk->u.kp.symbol_name);
        }
    }
#endif

    // PR16861: kprobes may have left some things in the k[ret]probe struct.
    // Let's reset it to be sure it's safe for re-use.
    memset(sk, 0, sizeof(struct stap_kprobe));
}
void cleanup_module(void)
{
    while(log_queue->head != NULL){
        node* temp = log_queue->head->next;
        kfree(log_queue->head);
        log_queue->head = temp;
    }
    kfree(log_queue);

    remove_proc_entry("logger", NULL);
    unregister_kprobe(&open_probe);
    unregister_kprobe(&send_probe);
    unregister_kprobe(&receive_probe);
    printk(KERN_INFO MODULE_NAME "unloaded\n");
}
static void __exit my_exit(void)
{

	unregister_jprobe(&jp);
	unregister_kprobe(&kp);
	printk(KERN_INFO "k,jprobes unregistered\n");
}
Exemple #8
0
void cleanup_module(void)
{
	unregister_kprobe(&kp);
	do_gettimeofday(&end);
	printk("Scheduling times is %d during of %ld milliseconds.\n", schedule_counter, ((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec))/1000);
	printk(KERN_ALERT"kprobe unregistered\n");
}
static int test_kprobe(void)
{
	int ret;

	ret = register_kprobe(&kp);
	if (ret < 0) {
		printk(KERN_ERR "Kprobe smoke test failed: "
				"register_kprobe returned %d\n", ret);
		return ret;
	}

	ret = target(rand1);
	unregister_kprobe(&kp);

	if (preh_val == 0) {
		printk(KERN_ERR "Kprobe smoke test failed: "
				"kprobe pre_handler not called\n");
		handler_errors++;
	}

	if (posth_val == 0) {
		printk(KERN_ERR "Kprobe smoke test failed: "
				"kprobe post_handler not called\n");
		handler_errors++;
	}

	return 0;
}
Exemple #10
0
static void mvmhyper_exit(void)
{
	printk("mvmhyper exit.\n");
	for(i=0;i<hypernum;++i)
		unregister_kprobe(&kphyper[i]);
	unregister_kretprobe(&rphyper);
}
Exemple #11
0
static void __exit my_exit(void)
{

	unregister_jprobe(&jp);
	unregister_kprobe(&kp);
	pr_info("k,jprobes unregistered\n");
}
static int
stapkp_arch_register_kprobe(struct stap_kprobe_probe *skp)
{
    int ret = 0;
    struct kprobe *kp = &skp->kprobe->u.kp;

#ifndef __ia64__
    ret = register_kprobe(kp);
    if (ret == 0) {
        if (skp->symbol_name)
            dbug_stapkp("+kprobe %s+%u\n", kp->symbol_name, kp->offset);
        else
            dbug_stapkp("+kprobe %p\n", kp->addr);
    }
#else // PR6028
    ret = register_kprobe(&skp->kprobe->dummy);
    if (ret == 0) {
        ret = register_kprobe(kp);
        if (ret != 0)
            unregister_kprobe(&skp->kprobe->dummy);
    }
    dbug_stapkp_cond(ret == 0, "+kprobe %p\n", skp->kprobe->dummy.addr);
    dbug_stapkp_cond(ret == 0, "+kprobe %p\n", kp->addr);
#endif

    skp->registered_p = (ret ? 0 : 1);

    return ret;
}
void process_notify_remove(void)
{
	unregister_kretprobe(&compat_exec_kretprobe);
	unregister_kretprobe(&exec_kretprobe);
	unregister_kretprobe(&fork_kretprobe);
	unregister_kprobe(&exit_kprobe);
}
Exemple #14
0
static void __exit myexit(void) 
{ 
    unregister_kprobe(&kp); 

    printk(KERN_INFO "kprobe at %p unregistered\n", kp.addr);

    printk("module removed\n "); 
} 
void process_notify_remove(void)
{
#ifdef CONFIG_COMPAT
	unregister_kretprobe(&compat_exec_kretprobe);
#endif
	unregister_kretprobe(&exec_kretprobe);
	unregister_kretprobe(&fork_kretprobe);
	unregister_kprobe(&exit_kprobe);
}
static void __exit kprobe_exit(void)
{
	unregister_kprobe(&kp);
#ifdef CONFIG_DEBUG_PRINTK
	printk(KERN_INFO "kprobe at %p unregistered\n", kp.addr);
#else
	;
#endif
}
Exemple #17
0
/* Unregister a trace_probe and probe_event: call with locking probe_lock */
static void unregister_trace_probe(struct trace_probe *tp)
{
	if (probe_is_return(tp))
		unregister_kretprobe(&tp->rp);
	else
		unregister_kprobe(&tp->rp.kp);
	list_del(&tp->list);
	unregister_probe_event(tp);
}
Exemple #18
0
static __exit void cleanup_mykp(void)
{
	int idx;
	for  (idx = NUM_SYMS - 1; idx >= 0; idx--) {
		struct kprobe *kp = &kp_array[idx];
		printk("[%s] Unregister: %s\n", __func__, kp->symbol_name);
		unregister_kprobe(kp);
	}
}
Exemple #19
0
static void __exit exit_modanalizer(void)
{
        unsigned int i;
        remove_proc_entry(MODULE_NAME_STR, NULL);

        for (i = 0; i < ma_symbols_count; ++i)
                if (ma_symbols[i].kp.addr)
                        unregister_kprobe(&ma_symbols[i].kp);

        kfree(ma_symbols);
}
Exemple #20
0
static int __init my_init (void)
{
    /* set the handler functions */

    if (setup_probe (&kp_mod_timer, "__mod_timer", h_mod_timer))
        return -1;
    if (setup_probe (&kp_del_timer, "del_timer", h_del_timer)) {
        unregister_kprobe (&kp_mod_timer);
        return -1;
    }
#ifdef CONFIG_SMP
    if (setup_probe (&kp_del_timer_sync, "del_timer_sync", h_del_timer_sync)) {
        unregister_kprobe (&kp_mod_timer);
        unregister_kprobe (&kp_del_timer);
        return -1;
    }
#endif

    printk (KERN_INFO "Hello: module loaded at 0x%p\n", my_init);

    return 0;
}
Exemple #21
0
/**
 * If an illegal slot instruction exception occurs for an address
 * containing a kprobe, remove the probe.
 *
 * Returns 0 if the exception was handled successfully, 1 otherwise.
 */
int __kprobes kprobe_handle_illslot(unsigned long pc)
{
	struct kprobe *p = get_kprobe((kprobe_opcode_t *) pc + 1);

	if (p != NULL) {
		printk("Warning: removing kprobe from delay slot: 0x%.8x\n",
		       (unsigned int)pc + 2);
		unregister_kprobe(p);
		return 0;
	}

	return 1;
}
void my_cleanup_module(void) { 
    int i = 0;

    for ( ; i < NUM_KPROBES; i++) {
        unregister_kprobe(&kprobes[i]); 
    }

    kfree(log);
    remove_proc_entry(SYSMON_TOGGLE, NULL);
    remove_proc_entry(SYSMON_UID, NULL);
    remove_proc_entry(SYSMON_LOG, NULL);    

    printk(KERN_INFO "Sysmon log module removed.\n"); 
} 
Exemple #23
0
static void __exit profiler_exit(void)
{  
        int i;

        printk(KERN_INFO "%s\n",__func__);
        device_remove_file(pdevice, &dev_attr_stats);
        device_remove_file(pdevice, &dev_attr_memleaks);
        device_remove_file(pdevice, &dev_attr_scan_start_addr);
        device_remove_file(pdevice, &dev_attr_scan_end_addr);
        cdev_del(&cdev);
        unregister_chrdev_region(dev, 1);
        device_destroy(pclass, dev);
        class_destroy(pclass);
        for(i=0; i<argc; i++) {
              unregister_kprobe(&kp[i]);
              printk(KERN_INFO "kprobe for %s unregistered\n",funcs[i]);
        }
}
int process_notify_init(void)
{
	int err;

	if ((err = register_kprobe(&exit_kprobe))) {
		printk(KERN_ERR "%s: exit register_kprobe() failed with error %d\n",
				THIS_MODULE->name, err);
		goto exit_failed;
	}
	if ((err = register_kretprobe(&fork_kretprobe))) {
		printk(KERN_ERR "%s: fork register_kretprobe() failed with error %d\n",
				THIS_MODULE->name, err);
		goto fork_failed;
	}
	if ((err = register_kretprobe(&exec_kretprobe))) {
		printk(KERN_ERR "%s: exec register_kretprobe() failed with error %d\n",
				THIS_MODULE->name, err);
		goto exec_failed;
	}
#ifdef CONFIG_COMPAT
	if ((err = register_kretprobe(&compat_exec_kretprobe))) {
		printk(KERN_ERR "%s: compat_exec register_kretprobe() failed with error %d\n",
				THIS_MODULE->name, err);
		if (err != -EINVAL)
			goto compat_exec_failed;
	}
#endif
	return 0;

#ifdef CONFIG_COMPAT
compat_exec_failed:
	unregister_kretprobe(&exec_kretprobe);
#endif
exec_failed:
	unregister_kretprobe(&fork_kretprobe);
fork_failed:
	unregister_kprobe(&exit_kprobe);
exit_failed:
	return err;
}
Exemple #25
0
static int
stapkp_arch_register_kretprobe(struct stap_dwarf_probe *sdp)
{
   int ret = 0;
   struct kretprobe *krp = &sdp->kprobe->u.krp;

#ifndef __ia64__
   ret = register_kretprobe(krp);
   dbug_stapkp_cond(ret == 0, "+kretprobe %p\n", krp->kp.addr);
#else // PR6028
   ret = register_kprobe(&sdp->kprobe->dummy);
   if (ret == 0) {
      ret = register_kretprobe(krp);
      if (ret != 0)
         unregister_kprobe(&sdp->kprobe->dummy);
   }
   dbug_stapkp_cond(ret == 0, "+kprobe %p\n", sdp->kprobe->dummy.addr);
   dbug_stapkp_cond(ret == 0, "+kretprobe %p\n", krp->kp.addr);
#endif

   sdp->registered_p = (ret ? 0 : 1);

   return ret;
}
Exemple #26
0
static __init int init_mykp(void)
{
	int idx;
	int ret;
	for  (idx = 0; idx < NUM_SYMS; idx++) {
		struct kprobe *kp = &kp_array[idx];
		printk("%s: sym_name: %s\n", __func__, symbols[idx]);
		kp->pre_handler = pre_handler;
		kp->symbol_name = symbols[idx];
		if ((ret = register_kprobe(kp)) < 0) {
			printk("register_kprobe failed, returned %d\n", ret);
			goto error;
		}
		printk("  => Addr: %p\n", kp->addr);
	}
	return 0;

error:
	for (idx--; idx >= 0; idx--) {
		struct kprobe *kp = &kp_array[idx];
		unregister_kprobe(kp);
	}
	return 0;
}
static void __exit kprobe_exit(void)
{
	unregister_kprobe(&kp);
	printk(KERN_INFO "kprobe at %p unregistered\n", kp.addr);
}
Exemple #28
0
static void hello_exit(void) {
  unregister_kprobe(&my_kprobe);
  printk(KERN_ALERT "bye\n");
}
Exemple #29
0
void __exit kprobe_cleanup_module(void)
{
    unregister_kprobe(&kp);
    printk("kprobe unregistered \n");
}
void myexit(void) 
{ 
    unregister_kprobe(&kp); 
    printk("module removed\n "); 
}