Skip to content

Commit 0b9e2ca

Browse files
Prasanna S PanchamukhiLinus Torvalds
authored andcommitted
[PATCH] Kprobes: Incorrect handling of probes on ret/lret instruction
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. Signed-off-by: Prasanna S Panchamukhi <prasanna@in.ibm.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 3a0a64e commit 0b9e2ca

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

‎arch/i386/kernel/kprobes.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,13 @@ static void resume_execution(struct kprobe *p, struct pt_regs *regs)
217217
*tos &= ~(TF_MASK | IF_MASK);
218218
*tos |= kprobe_old_eflags;
219219
break;
220+
case 0xc3: /* ret/lret */
221+
case 0xcb:
222+
case 0xc2:
223+
case 0xca:
224+
regs->eflags &= ~TF_MASK;
225+
/* eip is already adjusted, no more changes required*/
226+
return;
220227
case 0xe8: /* call relative - Fix return addr */
221228
*tos = orig_eip + (*tos - copy_eip);
222229
break;

‎arch/x86_64/kernel/kprobes.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,13 @@ static void resume_execution(struct kprobe *p, struct pt_regs *regs)
355355
*tos &= ~(TF_MASK | IF_MASK);
356356
*tos |= kprobe_old_rflags;
357357
break;
358+
case 0xc3: /* ret/lret */
359+
case 0xcb:
360+
case 0xc2:
361+
case 0xca:
362+
regs->eflags &= ~TF_MASK;
363+
/* rip is already adjusted, no more changes required*/
364+
return;
358365
case 0xe8: /* call relative - Fix return addr */
359366
*tos = orig_rip + (*tos - copy_rip);
360367
break;

0 commit comments

Comments
 (0)