This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Re: [PATCH tip/master] [BUGFIX] kprobes/x86: Fix to clear TF bit in fault-on-single-stepping
- From: Ananth N Mavinakayanahalli <ananth at linux dot vnet dot ibm dot com>
- To: Masami Hiramatsu <mhiramat at kernel dot org>
- Cc: Ingo Molnar <mingo at redhat dot com>, linux-kernel at vger dot kernel dot org, Peter Zijlstra <peterz at infradead dot org>, Thomas Gleixner <tglx at linutronix dot de>, "H . Peter Anvin" <hpa at zytor dot com>, Andy Lutomirski <luto at kernel dot org>, systemtap at sourceware dot org, Steven Rostedt <rostedt at goodmis dot org>
- Date: Mon, 13 Jun 2016 10:00:33 +0530
- Subject: Re: [PATCH tip/master] [BUGFIX] kprobes/x86: Fix to clear TF bit in fault-on-single-stepping
- Authentication-results: sourceware.org; auth=none
- References: <20160611140648 dot 25885 dot 37482 dot stgit at devbox>
- Reply-to: ananth at linux dot vnet dot ibm dot com
On Sat, Jun 11, 2016 at 11:06:53PM +0900, Masami Hiramatsu wrote:
> Fix kprobe_fault_handler to clear TF (trap flag) bit of
> flags register in the case of fault fixup on single-stepping.
>
> If we put a kprobe on the instruction which can cause a
> page fault (e.g. actual mov instructions in copy_user_*),
> that fault happens on a single-stepping buffer. In this
> case, kprobes resets running instance so that the CPU can
> retry execution on the original ip address.
> However, current code forgets reset TF bit. Since this
> fault happens with TF bit set for enabling single-stepping,
> when it retries, it causes a debug exception and kprobes
> can not handle it because it already reset itself.
>
> On the most of x86-64 platform, it can be easily reproduced
> by using kprobe tracer. E.g.
>
> # cd /sys/kernel/debug/tracing
> # echo p copy_user_enhanced_fast_string+5 > kprobe_events
> # echo 1 > events/kprobes/enable
>
> And you'll see a kernel panic on do_debug(), since the debug
> trap is not handled by kprobes.
>
> To fix this problem, we just need to clear the TF bit when
> resetting running kprobe.
>
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Good catch!
Reviewed-by: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>