Skip to content

Commit 8948080

Browse files
Martin SchwidefskyMartin Schwidefsky
authored andcommitted
[S390] kprobes: Fix the return address of multiple kretprobes
Analog to git commit 737480a fix the return address of subsequent kretprobes when multiple kretprobes are set on the same function. Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent adb4583 commit 8948080

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

‎arch/s390/kernel/kprobes.c‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ static int __kprobes trampoline_probe_handler(struct kprobe *p,
349349
struct hlist_node *node, *tmp;
350350
unsigned long flags, orig_ret_address = 0;
351351
unsigned long trampoline_address = (unsigned long)&kretprobe_trampoline;
352+
kprobe_opcode_t *correct_ret_addr = NULL;
352353

353354
INIT_HLIST_HEAD(&empty_rp);
354355
kretprobe_hash_lock(current, &head, &flags);
@@ -371,10 +372,32 @@ static int __kprobes trampoline_probe_handler(struct kprobe *p,
371372
/* another task is sharing our hash bucket */
372373
continue;
373374

374-
if (ri->rp && ri->rp->handler)
375-
ri->rp->handler(ri, regs);
375+
orig_ret_address = (unsigned long)ri->ret_addr;
376+
377+
if (orig_ret_address != trampoline_address)
378+
/*
379+
* This is the real return address. Any other
380+
* instances associated with this task are for
381+
* other calls deeper on the call stack
382+
*/
383+
break;
384+
}
385+
386+
kretprobe_assert(ri, orig_ret_address, trampoline_address);
387+
388+
correct_ret_addr = ri->ret_addr;
389+
hlist_for_each_entry_safe(ri, node, tmp, head, hlist) {
390+
if (ri->task != current)
391+
/* another task is sharing our hash bucket */
392+
continue;
376393

377394
orig_ret_address = (unsigned long)ri->ret_addr;
395+
396+
if (ri->rp && ri->rp->handler) {
397+
ri->ret_addr = correct_ret_addr;
398+
ri->rp->handler(ri, regs);
399+
}
400+
378401
recycle_rp_inst(ri, &empty_rp);
379402

380403
if (orig_ret_address != trampoline_address) {
@@ -386,7 +409,7 @@ static int __kprobes trampoline_probe_handler(struct kprobe *p,
386409
break;
387410
}
388411
}
389-
kretprobe_assert(ri, orig_ret_address, trampoline_address);
412+
390413
regs->psw.addr = orig_ret_address | PSW_ADDR_AMODE;
391414

392415
reset_current_kprobe();

0 commit comments

Comments
 (0)