Skip to content

Commit 03c8a4a

Browse files
mhiramatingomolnar
authored andcommitted
csky: kprobes: Use generic kretprobe trampoline handler
Use the generic kretprobe trampoline handler. Don't use framepointer verification. Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Acked-by: Guo Ren <guoren@kernel.org> Link: https://lore.kernel.org/r/159870605775.1229682.2627276871589951304.stgit@devnote2
1 parent f75dd13 commit 03c8a4a

1 file changed

Lines changed: 2 additions & 75 deletions

File tree

‎arch/csky/kernel/probes/kprobes.c‎

Lines changed: 2 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -404,87 +404,14 @@ int __init arch_populate_kprobe_blacklist(void)
404404

405405
void __kprobes __used *trampoline_probe_handler(struct pt_regs *regs)
406406
{
407-
struct kretprobe_instance *ri = NULL;
408-
struct hlist_head *head, empty_rp;
409-
struct hlist_node *tmp;
410-
unsigned long flags, orig_ret_address = 0;
411-
unsigned long trampoline_address =
412-
(unsigned long)&kretprobe_trampoline;
413-
kprobe_opcode_t *correct_ret_addr = NULL;
414-
415-
INIT_HLIST_HEAD(&empty_rp);
416-
kretprobe_hash_lock(current, &head, &flags);
417-
418-
/*
419-
* It is possible to have multiple instances associated with a given
420-
* task either because multiple functions in the call path have
421-
* return probes installed on them, and/or more than one
422-
* return probe was registered for a target function.
423-
*
424-
* We can handle this because:
425-
* - instances are always pushed into the head of the list
426-
* - when multiple return probes are registered for the same
427-
* function, the (chronologically) first instance's ret_addr
428-
* will be the real return address, and all the rest will
429-
* point to kretprobe_trampoline.
430-
*/
431-
hlist_for_each_entry_safe(ri, tmp, head, hlist) {
432-
if (ri->task != current)
433-
/* another task is sharing our hash bucket */
434-
continue;
435-
436-
orig_ret_address = (unsigned long)ri->ret_addr;
437-
438-
if (orig_ret_address != trampoline_address)
439-
/*
440-
* This is the real return address. Any other
441-
* instances associated with this task are for
442-
* other calls deeper on the call stack
443-
*/
444-
break;
445-
}
446-
447-
kretprobe_assert(ri, orig_ret_address, trampoline_address);
448-
449-
correct_ret_addr = ri->ret_addr;
450-
hlist_for_each_entry_safe(ri, tmp, head, hlist) {
451-
if (ri->task != current)
452-
/* another task is sharing our hash bucket */
453-
continue;
454-
455-
orig_ret_address = (unsigned long)ri->ret_addr;
456-
if (ri->rp && ri->rp->handler) {
457-
__this_cpu_write(current_kprobe, &ri->rp->kp);
458-
get_kprobe_ctlblk()->kprobe_status = KPROBE_HIT_ACTIVE;
459-
ri->ret_addr = correct_ret_addr;
460-
ri->rp->handler(ri, regs);
461-
__this_cpu_write(current_kprobe, NULL);
462-
}
463-
464-
recycle_rp_inst(ri, &empty_rp);
465-
466-
if (orig_ret_address != trampoline_address)
467-
/*
468-
* This is the real return address. Any other
469-
* instances associated with this task are for
470-
* other calls deeper on the call stack
471-
*/
472-
break;
473-
}
474-
475-
kretprobe_hash_unlock(current, &flags);
476-
477-
hlist_for_each_entry_safe(ri, tmp, &empty_rp, hlist) {
478-
hlist_del(&ri->hlist);
479-
kfree(ri);
480-
}
481-
return (void *)orig_ret_address;
407+
return (void *)kretprobe_trampoline_handler(regs, &kretprobe_trampoline, NULL);
482408
}
483409

484410
void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
485411
struct pt_regs *regs)
486412
{
487413
ri->ret_addr = (kprobe_opcode_t *)regs->lr;
414+
ri->fp = NULL;
488415
regs->lr = (unsigned long) &kretprobe_trampoline;
489416
}
490417

0 commit comments

Comments
 (0)