aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2018-08-27 05:12:25 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2018-08-30 13:49:23 -0400
commitbd14406b78e6daa1ea3c1673bda1ffc9efdeead0 (patch)
treec4957e82922f7772b726673a63b273733d3851ac
parent9b3579fc6c6ac45502de1fa9a1fdf873805c2157 (diff)
perf/hw_breakpoint: Modify breakpoint even if the new attr has disabled set
We need to change the breakpoint even if the attr with new fields has disabled set to true. Current code prevents following user code to change the breakpoint address: ptrace(PTRACE_POKEUSER, child, offsetof(struct user, u_debugreg[0]), addr_1) ptrace(PTRACE_POKEUSER, child, offsetof(struct user, u_debugreg[0]), addr_2) ptrace(PTRACE_POKEUSER, child, offsetof(struct user, u_debugreg[7]), dr7) The first PTRACE_POKEUSER creates the breakpoint with attr.disabled set to true: ptrace_set_breakpoint_addr(nr = 0) struct perf_event *bp = t->ptrace_bps[nr]; ptrace_register_breakpoint(..., disabled = true) ptrace_fill_bp_fields(..., disabled) register_user_hw_breakpoint So the second PTRACE_POKEUSER will be omitted: ptrace_set_breakpoint_addr(nr = 0) struct perf_event *bp = t->ptrace_bps[nr]; struct perf_event_attr attr = bp->attr; modify_user_hw_breakpoint(bp, &attr) if (!attr->disabled) modify_user_hw_breakpoint_check Reported-by: Milind Chabbi <chabbi.milind@gmail.com> Signed-off-by: Jiri Olsa <jolsa@kernel.org> Acked-by: Frederic Weisbecker <frederic@kernel.org> Acked-by: Oleg Nesterov <oleg@redhat.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/20180827091228.2878-3-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--kernel/events/hw_breakpoint.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/kernel/events/hw_breakpoint.c b/kernel/events/hw_breakpoint.c
index b3814fce5ecb..fb229d9c7f3c 100644
--- a/kernel/events/hw_breakpoint.c
+++ b/kernel/events/hw_breakpoint.c
@@ -509,6 +509,8 @@ modify_user_hw_breakpoint_check(struct perf_event *bp, struct perf_event_attr *a
509 */ 509 */
510int modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *attr) 510int modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *attr)
511{ 511{
512 int err;
513
512 /* 514 /*
513 * modify_user_hw_breakpoint can be invoked with IRQs disabled and hence it 515 * modify_user_hw_breakpoint can be invoked with IRQs disabled and hence it
514 * will not be possible to raise IPIs that invoke __perf_event_disable. 516 * will not be possible to raise IPIs that invoke __perf_event_disable.
@@ -520,11 +522,11 @@ int modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *att
520 else 522 else
521 perf_event_disable(bp); 523 perf_event_disable(bp);
522 524
523 if (!attr->disabled) { 525 err = modify_user_hw_breakpoint_check(bp, attr, false);
524 int err = modify_user_hw_breakpoint_check(bp, attr, false); 526 if (err)
527 return err;
525 528
526 if (err) 529 if (!attr->disabled) {
527 return err;
528 perf_event_enable(bp); 530 perf_event_enable(bp);
529 bp->attr.disabled = 0; 531 bp->attr.disabled = 0;
530 } 532 }