From cbc61f87f510d6b3ff33f35c6505b2e291df2232 Mon Sep 17 00:00:00 2001 From: Vyacheslav Cherkashin Date: Wed, 3 Apr 2013 11:29:51 +0400 Subject: [PATCH] [REFACTOR] remove field 'rp2' from 'struct kretprobe_instance' --- kprobe/arch/asm-arm/dbi_kprobes.c | 56 -------------------------------------- kprobe/arch/asm-mips/dbi_kprobes.c | 34 +---------------------- kprobe/arch/asm-x86/dbi_kprobes.c | 46 +------------------------------ kprobe/dbi_kprobes.c | 6 ---- kprobe/dbi_kprobes.h | 1 - 5 files changed, 2 insertions(+), 141 deletions(-) diff --git a/kprobe/arch/asm-arm/dbi_kprobes.c b/kprobe/arch/asm-arm/dbi_kprobes.c index f8ab08e..ab30b0a 100644 --- a/kprobe/arch/asm-arm/dbi_kprobes.c +++ b/kprobe/arch/asm-arm/dbi_kprobes.c @@ -554,13 +554,6 @@ int trampoline_probe_handler (struct kprobe *p, struct pt_regs *regs) break; } kretprobe_assert (ri, orig_ret_address, trampoline_address); - //BUG_ON(!orig_ret_address || (orig_ret_address == trampoline_address)); - //E.G. Check this code in case of __switch_to function instrumentation -- currently this code generates dump in this case - //if (trampoline_address != (unsigned long) &kretprobe_trampoline){ - //if (ri->rp2) BUG_ON (ri->rp2->kp.tgid == 0); - //if (ri->rp) BUG_ON (ri->rp->kp.tgid == 0); - //else if (ri->rp2) BUG_ON (ri->rp2->kp.tgid == 0); - //} regs->uregs[14] = orig_ret_address; DBPRINTF ("regs->uregs[14] = 0x%lx\n", regs->uregs[14]); @@ -587,54 +580,6 @@ int trampoline_probe_handler (struct kprobe *p, struct pt_regs *regs) } } - //TODO: test - enter function, delete us retprobe, exit function - // for user space retprobes only - deferred deletion - - if (trampoline_address != (unsigned long) &kretprobe_trampoline) - { - // if we are not at the end of the list and current retprobe should be disarmed - if (node && ri->rp2) - { - struct hlist_node *current_node = node; - crp = ri->rp2; - /*sprintf(die_msg, "deferred disarm p->addr = %p [%lx %lx %lx]\n", - crp->kp.addr, *kaddrs[0], *kaddrs[1], *kaddrs[2]); - DIE(die_msg, regs); */ - // look for other instances for the same retprobe - hlist_for_each_entry_safe (ri, node, tmp, head, hlist) - { - /* - * Trying to find another retprobe instance associated with - * the same retprobe. - */ - if (ri->rp2 == crp && node != current_node) - break; - } - - if (!node) - { - // if there are no more instances for this retprobe - // delete retprobe - struct kprobe *is_p = &crp->kp; - DBPRINTF ("defered retprobe deletion p->addr = %p", crp->kp.addr); - /* - If there is no any retprobe instances of this retprobe - we can free the resources related to the probe. - */ - if (!(hlist_unhashed(&is_p->is_hlist_arm))) { - hlist_del_rcu(&is_p->is_hlist_arm); - } - if (!(hlist_unhashed(&is_p->is_hlist_thumb))) { - hlist_del_rcu(&is_p->is_hlist_thumb); - } - - dbi_unregister_kprobe(&crp->kp, current); - kfree (crp); - } - hlist_del(current_node); - } - } - if (kcb->kprobe_status == KPROBE_REENTER) { restore_previous_kprobe(kcb); } else { @@ -663,7 +608,6 @@ void __arch_prepare_kretprobe (struct kretprobe *rp, struct pt_regs *regs) if ((ri = get_free_rp_inst (rp)) != NULL) { ri->rp = rp; - ri->rp2 = NULL; ri->task = current; ri->ret_addr = (kprobe_opcode_t *) regs->uregs[14]; ri->sp = (kprobe_opcode_t *)regs->ARM_sp; //uregs[13]; diff --git a/kprobe/arch/asm-mips/dbi_kprobes.c b/kprobe/arch/asm-mips/dbi_kprobes.c index 834a683..8737ae5 100644 --- a/kprobe/arch/asm-mips/dbi_kprobes.c +++ b/kprobe/arch/asm-mips/dbi_kprobes.c @@ -655,11 +655,9 @@ int trampoline_probe_handler (struct kprobe *p, struct pt_regs *regs) kretprobe_assert (ri, orig_ret_address, trampoline_address); //BUG_ON(!orig_ret_address || (orig_ret_address == trampoline_address)); if (trampoline_address != (unsigned long) &kretprobe_trampoline){ - if (ri->rp2) BUG_ON (ri->rp2->kp.tgid == 0); if (ri->rp) BUG_ON (ri->rp->kp.tgid == 0); - else if (ri->rp2) BUG_ON (ri->rp2->kp.tgid == 0); } - if ((ri->rp && ri->rp->kp.tgid) || (ri->rp2 && ri->rp2->kp.tgid)) + if (ri->rp && ri->rp->kp.tgid) BUG_ON (trampoline_address == (unsigned long) &kretprobe_trampoline); regs->regs[31] = orig_ret_address; @@ -676,35 +674,6 @@ int trampoline_probe_handler (struct kprobe *p, struct pt_regs *regs) restore_previous_kprobe (kcb); else reset_current_kprobe (); - - //TODO: test - enter function, delete us retprobe, exit function - // for user space retprobes only - deferred deletion - if (trampoline_address != (unsigned long) &kretprobe_trampoline) - { - // if we are not at the end of the list and current retprobe should be disarmed - if (node && ri->rp2) - { - crp = ri->rp2; - /*sprintf(die_msg, "deferred disarm p->addr = %p [%lx %lx %lx]\n", - crp->kp.addr, *kaddrs[0], *kaddrs[1], *kaddrs[2]); - DIE(die_msg, regs); */ - // look for other instances for the same retprobe - hlist_for_each_entry_continue (ri, node, hlist) - { - if (ri->task != current) - continue; /* another task is sharing our hash bucket */ - if (ri->rp2 == crp) //if instance belong to the same retprobe - break; - } - if (!node) - { // if there are no more instances for this retprobe - // delete retprobe - DBPRINTF ("defered retprobe deletion p->addr = %p", crp->kp.addr); - unregister_uprobe (&crp->kp, current, 1); - kfree (crp); - } - } - } } spin_unlock_irqrestore (&kretprobe_lock, flags); @@ -732,7 +701,6 @@ void __arch_prepare_kretprobe (struct kretprobe *rp, struct pt_regs *regs) if ((ri = get_free_rp_inst (rp)) != NULL) { ri->rp = rp; - ri->rp2 = NULL; ri->task = current; ri->ret_addr = (kprobe_opcode_t *) regs->regs[31]; if (rp->kp.tgid) diff --git a/kprobe/arch/asm-x86/dbi_kprobes.c b/kprobe/arch/asm-x86/dbi_kprobes.c index fe226c4..6bb303f 100644 --- a/kprobe/arch/asm-x86/dbi_kprobes.c +++ b/kprobe/arch/asm-x86/dbi_kprobes.c @@ -1233,11 +1233,9 @@ int trampoline_probe_handler (struct kprobe *p, struct pt_regs *regs) kretprobe_assert (ri, orig_ret_address, trampoline_address); //BUG_ON(!orig_ret_address || (orig_ret_address == trampoline_address)); if (trampoline_address != (unsigned long) &kretprobe_trampoline){ - if (ri->rp2) BUG_ON (ri->rp2->kp.tgid == 0); if (ri->rp) BUG_ON (ri->rp->kp.tgid == 0); - else if (ri->rp2) BUG_ON (ri->rp2->kp.tgid == 0); } - if ((ri->rp && ri->rp->kp.tgid) || (ri->rp2 && ri->rp2->kp.tgid)) + if (ri->rp && ri->rp->kp.tgid) BUG_ON (trampoline_address == (unsigned long) &kretprobe_trampoline); if(p){ // X86 user space @@ -1250,47 +1248,6 @@ int trampoline_probe_handler (struct kprobe *p, struct pt_regs *regs) restore_previous_kprobe (kcb); else reset_current_kprobe (); - - //TODO: test - enter function, delete us retprobe, exit function - // for user space retprobes only - deferred deletion - if (trampoline_address != (unsigned long) &kretprobe_trampoline) - { - // if we are not at the end of the list and current retprobe should be disarmed - if (node && ri->rp2) - { - struct hlist_node *current_node = node; - crp = ri->rp2; - /*sprintf(die_msg, "deferred disarm p->addr = %p [%lx %lx %lx]\n", - crp->kp.addr, *kaddrs[0], *kaddrs[1], *kaddrs[2]); - DIE(die_msg, regs); */ - // look for other instances for the same retprobe - hlist_for_each_entry_safe (ri, node, tmp, head, hlist) - { - /* - * Trying to find another retprobe instance associated with - * the same retprobe. - */ - if (ri->rp2 == crp && node != current_node) - break; - } - if (!node) - { // if there are no more instances for this retprobe - // delete retprobe - DBPRINTF ("defered retprobe deletion p->addr = %p", crp->kp.addr); - /* - If there is no any retprobe instances of this retprobe - we can free the resources related to the probe. - */ - struct kprobe *is_p = &crp->kp; - if (!(hlist_unhashed(&is_p->is_hlist))) { - hlist_del_rcu(&is_p->is_hlist); - } - unregister_uprobe (&crp->kp, current, 1); - kfree (crp); - } - hlist_del(current_node); - } - } } hlist_for_each_entry_safe (ri, node, tmp, &empty_rp, hlist) @@ -1321,7 +1278,6 @@ void __arch_prepare_kretprobe (struct kretprobe *rp, struct pt_regs *regs) if ((ri = get_free_rp_inst (rp)) != NULL) { ri->rp = rp; - ri->rp2 = NULL; ri->task = current; ri->sp = (kprobe_opcode_t *)regs->EREG(sp); diff --git a/kprobe/dbi_kprobes.c b/kprobe/dbi_kprobes.c index 1a629de..bce27e5 100644 --- a/kprobe/dbi_kprobes.c +++ b/kprobe/dbi_kprobes.c @@ -310,11 +310,6 @@ void recycle_rp_inst(struct kretprobe_instance *ri) /* put rp inst back onto the free list */ INIT_HLIST_NODE(&ri->uflist); hlist_add_head(&ri->uflist, &ri->rp->free_instances); - } else if (!ri->rp2) { - /* - * This is __switch_to retprobe instance. It has neither rp nor rp2. - */ - hlist_del(&ri->hlist); } } EXPORT_SYMBOL_GPL(recycle_rp_inst); @@ -830,7 +825,6 @@ int patch_suspended_task(struct kretprobe *rp, struct task_struct *task) return -ENOMEM; ri->rp = rp; - ri->rp2 = NULL; ri->task = task; ri->sp = NULL; set_task_trampoline(task, ri, (unsigned long)tramp); diff --git a/kprobe/dbi_kprobes.h b/kprobe/dbi_kprobes.h index 1bcdf73..06d8bd5 100644 --- a/kprobe/dbi_kprobes.h +++ b/kprobe/dbi_kprobes.h @@ -202,7 +202,6 @@ struct kretprobe_instance struct kretprobe *rp; kprobe_opcode_t *ret_addr; kprobe_opcode_t *sp; - struct kretprobe *rp2; struct task_struct *task; }; -- 2.7.4