lkml.org 
[lkml]   [2018]   [Aug]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 5/5] perf/hw_breakpoint: Add fallback code for ptrace_set_breakpoint_addr
Date
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/tip-h9ut835vl297roen0v163zg6@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
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
\
 
 \ /
  Last update: 2018-08-09 14:04    [W:0.054 / U:7.248 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site