Commit 0b0122fa authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Ingo Molnar

x86: kprobes bugfix

Kprobes for x86-64 may cause a kernel crash if it inserted on "iret"
instruction. "call absolute" is invalid on x86-64, so we don't need
treat it.

 - Change the processing order as same as x86-32.
 - Add "iret"(0xcf) case.
 - Remove next_rip local variable.
Signed-off-by: default avatarMasami Hiramatsu <mhiramat@redhat.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent 29b6cd79
...@@ -485,7 +485,6 @@ static void __kprobes resume_execution(struct kprobe *p, ...@@ -485,7 +485,6 @@ static void __kprobes resume_execution(struct kprobe *p,
struct pt_regs *regs, struct kprobe_ctlblk *kcb) struct pt_regs *regs, struct kprobe_ctlblk *kcb)
{ {
unsigned long *tos = (unsigned long *)regs->rsp; unsigned long *tos = (unsigned long *)regs->rsp;
unsigned long next_rip = 0;
unsigned long copy_rip = (unsigned long)p->ainsn.insn; unsigned long copy_rip = (unsigned long)p->ainsn.insn;
unsigned long orig_rip = (unsigned long)p->addr; unsigned long orig_rip = (unsigned long)p->addr;
kprobe_opcode_t *insn = p->ainsn.insn; kprobe_opcode_t *insn = p->ainsn.insn;
...@@ -494,46 +493,42 @@ static void __kprobes resume_execution(struct kprobe *p, ...@@ -494,46 +493,42 @@ static void __kprobes resume_execution(struct kprobe *p,
if (*insn >= 0x40 && *insn <= 0x4f) if (*insn >= 0x40 && *insn <= 0x4f)
insn++; insn++;
regs->eflags &= ~TF_MASK;
switch (*insn) { switch (*insn) {
case 0x9c: /* pushfl */ case 0x9c: /* pushfl */
*tos &= ~(TF_MASK | IF_MASK); *tos &= ~(TF_MASK | IF_MASK);
*tos |= kcb->kprobe_old_rflags; *tos |= kcb->kprobe_old_rflags;
break; break;
case 0xc3: /* ret/lret */ case 0xc2: /* iret/ret/lret */
case 0xcb: case 0xc3:
case 0xc2:
case 0xca: case 0xca:
regs->eflags &= ~TF_MASK; case 0xcb:
/* rip is already adjusted, no more changes required*/ case 0xcf:
return; case 0xea: /* jmp absolute -- ip is correct */
case 0xe8: /* call relative - Fix return addr */ /* ip is already adjusted, no more changes required */
goto no_change;
case 0xe8: /* call relative - Fix return addr */
*tos = orig_rip + (*tos - copy_rip); *tos = orig_rip + (*tos - copy_rip);
break; break;
case 0xff: case 0xff:
if ((insn[1] & 0x30) == 0x10) { if ((insn[1] & 0x30) == 0x10) {
/* call absolute, indirect */ /* call absolute, indirect */
/* Fix return addr; rip is correct. */ /* Fix return addr; ip is correct. */
next_rip = regs->rip;
*tos = orig_rip + (*tos - copy_rip); *tos = orig_rip + (*tos - copy_rip);
goto no_change;
} else if (((insn[1] & 0x31) == 0x20) || /* jmp near, absolute indirect */ } else if (((insn[1] & 0x31) == 0x20) || /* jmp near, absolute indirect */
((insn[1] & 0x31) == 0x21)) { /* jmp far, absolute indirect */ ((insn[1] & 0x31) == 0x21)) { /* jmp far, absolute indirect */
/* rip is correct. */ /* ip is correct. */
next_rip = regs->rip; goto no_change;
} }
break;
case 0xea: /* jmp absolute -- rip is correct */
next_rip = regs->rip;
break;
default: default:
break; break;
} }
regs->eflags &= ~TF_MASK; regs->rip = orig_rip + (regs->rip - copy_rip);
if (next_rip) { no_change:
regs->rip = next_rip;
} else { return;
regs->rip = orig_rip + (regs->rip - copy_rip);
}
} }
int __kprobes post_kprobe_handler(struct pt_regs *regs) int __kprobes post_kprobe_handler(struct pt_regs *regs)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment