diff options
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/kprobes.c | 9 | ||||
-rw-r--r-- | kernel/test_kprobes.c | 16 |
2 files changed, 22 insertions, 3 deletions
diff --git a/kernel/kprobes.c b/kernel/kprobes.c index d0493eafea3e..7a86e6432338 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -699,6 +699,12 @@ static int __kprobes pre_handler_kretprobe(struct kprobe *p, struct kretprobe_instance, uflist); ri->rp = rp; ri->task = current; + + if (rp->entry_handler && rp->entry_handler(ri, regs)) { + spin_unlock_irqrestore(&kretprobe_lock, flags); + return 0; + } + arch_prepare_kretprobe(ri, regs); /* XXX(hch): why is there no hlist_move_head? */ @@ -745,7 +751,8 @@ int __kprobes register_kretprobe(struct kretprobe *rp) INIT_HLIST_HEAD(&rp->used_instances); INIT_HLIST_HEAD(&rp->free_instances); for (i = 0; i < rp->maxactive; i++) { - inst = kmalloc(sizeof(struct kretprobe_instance), GFP_KERNEL); + inst = kmalloc(sizeof(struct kretprobe_instance) + + rp->data_size, GFP_KERNEL); if (inst == NULL) { free_rp_inst(rp); return -ENOMEM; diff --git a/kernel/test_kprobes.c b/kernel/test_kprobes.c index 88cdb109e13c..06b6395b45b2 100644 --- a/kernel/test_kprobes.c +++ b/kernel/test_kprobes.c @@ -135,6 +135,12 @@ static int test_jprobe(void) #ifdef CONFIG_KRETPROBES static u32 krph_val; +static int entry_handler(struct kretprobe_instance *ri, struct pt_regs *regs) +{ + krph_val = (rand1 / div_factor); + return 0; +} + static int return_handler(struct kretprobe_instance *ri, struct pt_regs *regs) { unsigned long ret = regs_return_value(regs); @@ -144,13 +150,19 @@ static int return_handler(struct kretprobe_instance *ri, struct pt_regs *regs) printk(KERN_ERR "Kprobe smoke test failed: " "incorrect value in kretprobe handler\n"); } + if (krph_val == 0) { + handler_errors++; + printk(KERN_ERR "Kprobe smoke test failed: " + "call to kretprobe entry handler failed\n"); + } - krph_val = (rand1 / div_factor); + krph_val = rand1; return 0; } static struct kretprobe rp = { .handler = return_handler, + .entry_handler = entry_handler, .kp.symbol_name = "kprobe_target" }; @@ -167,7 +179,7 @@ static int test_kretprobe(void) ret = kprobe_target(rand1); unregister_kretprobe(&rp); - if (krph_val == 0) { + if (krph_val != rand1) { printk(KERN_ERR "Kprobe smoke test failed: " "kretprobe handler not called\n"); handler_errors++; |