Skip to contentSkip to conversation

kprobe: make kreturn probe handler stack unwind correct

PATCH New Shaohua Li 1 participant 1 message Nov 13, 2007

lore
Share & tools
lore

Shaohua Li

author
#0 lore raw

PATCH 1/1 kprobe: make kreturn probe handler stack unwind correct

Restore regs->ccr_iip before kreturn probe handler runs. In this way, if probe handler does unwind, unwind can correctly get the stack trace.

http://sourceware.org/bugzilla/show_bug.cgi?idP51

Index: linux/arch/ia64/kernel/kprobes.c
=================================--- linux.orig/arch/ia64/kernel/kprobes.c 2007-10-17 10:33:45.000000000 +0800
+++ linux/arch/ia64/kernel/kprobes.c 2007-11-13 14:39:50.000000000 +0800
@@ -435,6 +435,23 @@ int __kprobes trampoline_probe_handler(s
/* another task is sharing our hash bucket */ continue;

+ orig_ret_address = (unsigned long)ri->ret_addr;
+ if (orig_ret_address != trampoline_address)
+ /*
+ * This is the real return address. Any other
+ * instances associated with this task are for
+ * other calls deeper on the call stack
+ */
+ break;
+ }
+
+ regs->cr_iip = orig_ret_address;
+
+ hlist_for_each_entry_safe(ri, node, tmp, head, hlist) {
+ if (ri->task != current)
+ /* another task is sharing our hash bucket */
+ continue;
+
if (ri->rp && ri->rp->handler)
ri->rp->handler(ri, regs);

@@ -452,8 +469,6 @@ int __kprobes trampoline_probe_handler(s

kretprobe_assert(ri, orig_ret_address, trampoline_address);

- regs->cr_iip = orig_ret_address;
-
reset_current_kprobe(); spin_unlock_irqrestore(&kretprobe_lock, flags); preempt_enable_no_resched();