Skip to contentSkip to conversation

Kprobes: Incorrect handling of probes on ret/lret instruction

PATCH New Prasanna S Panchamukhi 1 participant 1 message Apr 1, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Kprobes: Incorrect handling of probes on ret/lret instruction

Hi,

Kprobes could not handle the insertion of a probe on the ret/lret instruction and used to oops after single stepping since kprobes was modifying eip/rip incorrectly. Adjustment of eip/rip is not required after single stepping in case of ret/lret instruction, because eip/rip points to the correct location after execution of the ret/lret instruction. This patch fixes the above problem.

---

---

 linux-2.6.12-rc1-prasanna/arch/i386/kernel/kprobes.c   |    7 +++++++
 linux-2.6.12-rc1-prasanna/arch/x86_64/kernel/kprobes.c |    7 +++++++
 2 files changed, 14 insertions(+)
arch/i386/kernel/kprobes.c renamed from arch/i386/kernel/kprobes.c~kprobes-ret-address-fix +7 -0
diff -puN arch/i386/kernel/kprobes.c~kprobes-ret-address-fix arch/i386/kernel/kprobes.c
@@ -218,6 +218,13 @@ static void resume_execution(struct kpro
 		*tos &= ~(TF_MASK | IF_MASK);
 		*tos |= kprobe_old_eflags;
 		break;
+	case 0xc3:		/* ret/lret */
+	case 0xcb:
+	case 0xc2:
+	case 0xca:
+		regs->eflags &= ~TF_MASK;
+		/* eip is already adjusted, no more changes required*/
+		return;
 	case 0xe8:		/* call relative - Fix return addr */
 		*tos = orig_eip + (*tos - copy_eip);
 		break;
arch/x86_64/kernel/kprobes.c renamed from arch/x86_64/kernel/kprobes.c~kprobes-ret-address-fix +7 -0
diff -puN arch/x86_64/kernel/kprobes.c~kprobes-ret-address-fix arch/x86_64/kernel/kprobes.c
@@ -231,6 +231,13 @@ static void resume_execution(struct kpro
 		*tos &= ~(TF_MASK | IF_MASK);
 		*tos |= kprobe_old_rflags;
 		break;
+	case 0xc3:		/* ret/lret */
+	case 0xcb:
+	case 0xc2:
+	case 0xca:
+		regs->eflags &= ~TF_MASK;
+		/* rip is already adjusted, no more changes required*/
+		return;
 	case 0xe8:		/* call relative - Fix return addr */
 		*tos = orig_rip + (*tos - copy_rip);
 		break;

_

Thanks
Prasanna

Signature · 5 lines
Prasanna S Panchamukhi
Linux Technology Center
India Software Labs, IBM Bangalore
Ph: 91-80-25044636
<[email protected]>