Restoring the breakpoint after unsuccesfull address change, so following user code no longer produces disabled breakpoint.
ptrace(PTRACE_POKEUSER, child, offsetof(struct user, u_debugreg[0]), addr_1) ptrace(PTRACE_POKEUSER, child, offsetof(struct user, u_debugreg[7]), dr7) ptrace(PTRACE_POKEUSER, child, offsetof(struct user, u_debugreg[0]), -1) The first 2 ptrace calls set breakpoint on addr_1. The 3rd ptrace call tries to set it to bogus address (-1). This would normaly end up with disabled breakpoint. This patch adds the code that restores the breakpoint to its original state. Link: http://lkml.kernel.org/n/[email protected] Signed-off-by: Jiri Olsa <[email protected]> --- arch/x86/kernel/ptrace.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c index e2ee403865eb..22c06d0a38d1 100644 --- a/arch/x86/kernel/ptrace.c +++ b/arch/x86/kernel/ptrace.c @@ -693,9 +693,14 @@ static int ptrace_set_breakpoint_addr(struct task_struct *tsk, int nr, t->ptrace_bps[nr] = bp; } else { struct perf_event_attr attr = bp->attr; + bool disabled = attr.disabled; attr.bp_addr = addr; err = modify_user_hw_breakpoint(bp, &attr); + if (err && !disabled) { + bp->attr.disabled = false; + WARN_ON(modify_user_hw_breakpoint(bp, &bp->attr)); + } } return err; -- 2.17.1

