lkml.org 
[lkml]   [2018]   [Jan]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] x86/kprobe: unbalanced preempt counter with CONFIG_PREEMPT=y
Date
From: Yang Bo <yangbo@deepin.com>

For each kprobe hook, preempt_disable() is called twice, but
preempt_enable() is called once, when CONFIG_PREEMPT=y. No
matter kprobe uses ftrace or int3. Then the preempt counter
overflows, the process might be preempted and migrate to another
cpu. It causes the kprobe int3 being treated as not kprobe's int3,
kernel dies.

The backtrace looks like this:

int3: 0000 [#1] PREEMPT SMP
Modules linkedd in: ...
CPU: 1 PID: 2618 COMM: ...
Hardware: ...
task: ...
RIP: 0010[<ffffffff81457cd5>] [<ffffffff81457cd5>] jprobe_return_end+0x0/0xb
...
RIP [<ffffffff81457cd5>] jprobe_return_end+0x0/0xb
RSP ...

Signed-off-by: Yang Bo <yangbo@deepin.com>
---
arch/x86/kernel/kprobes/core.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
index bd36f3c33cd0..1ea5c9caa8f1 100644
--- a/arch/x86/kernel/kprobes/core.c
+++ b/arch/x86/kernel/kprobes/core.c
@@ -611,6 +611,7 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
regs->ip = (unsigned long)p->addr;
else
regs->ip = (unsigned long)p->ainsn.insn;
+ preempt_enable_no_resched();
}
NOKPROBE_SYMBOL(setup_singlestep);

--
2.15.1


\
 
 \ /
  Last update: 2018-01-15 05:25    [W:0.066 / U:1.496 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site