diff options
author | Jiri Olsa <jolsa@kernel.org> | 2018-03-12 09:45:45 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2018-03-13 01:56:08 -0400 |
commit | 705feaf321c37e4dca3637fd5cb3b275f17a06c9 (patch) | |
tree | a85a2b9fce79cfee9abd3794c719c4b75b701431 | |
parent | 18ff57b220610a699947f20b156a8245ca7eee98 (diff) |
hw_breakpoint: Add perf_event_attr fields check in __modify_user_hw_breakpoint()
And rename it to modify_user_hw_breakpoint_check().
We are about to use modify_user_hw_breakpoint_check() for user space
breakpoints modification, we must be very strict to check only the
fields we can change have changed. As Peter explained:
"Suppose someone does:
attr = malloc(sizeof(*attr)); // uninitialized memory
attr->type = BP;
attr->bp_addr = new_addr;
attr->bp_type = bp_type;
attr->bp_len = bp_len;
ioctl(fd, PERF_IOC_MOD_ATTR, &attr);
And feeds absolute shite for the rest of the fields.
Then we later want to extend IOC_MOD_ATTR to allow changing
attr::sample_type but we can't, because that would break the
above application."
I'm making this check optional because we already export
modify_user_hw_breakpoint() and with this check we could
break existing users.
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Hari Bathini <hbathini@linux.vnet.ibm.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Milind Chabbi <chabbi.milind@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Oleg Nesterov <onestero@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will.deacon@arm.com>
Link: http://lkml.kernel.org/r/20180312134548.31532-6-jolsa@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r-- | kernel/events/hw_breakpoint.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/kernel/events/hw_breakpoint.c b/kernel/events/hw_breakpoint.c index a556aba223da..0c82663395f7 100644 --- a/kernel/events/hw_breakpoint.c +++ b/kernel/events/hw_breakpoint.c | |||
@@ -456,7 +456,9 @@ register_user_hw_breakpoint(struct perf_event_attr *attr, | |||
456 | } | 456 | } |
457 | EXPORT_SYMBOL_GPL(register_user_hw_breakpoint); | 457 | EXPORT_SYMBOL_GPL(register_user_hw_breakpoint); |
458 | 458 | ||
459 | static int __modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *attr) | 459 | static int |
460 | modify_user_hw_breakpoint_check(struct perf_event *bp, struct perf_event_attr *attr, | ||
461 | bool check) | ||
460 | { | 462 | { |
461 | u64 old_addr = bp->attr.bp_addr; | 463 | u64 old_addr = bp->attr.bp_addr; |
462 | u64 old_len = bp->attr.bp_len; | 464 | u64 old_len = bp->attr.bp_len; |
@@ -468,6 +470,9 @@ static int __modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_ | |||
468 | bp->attr.bp_type = attr->bp_type; | 470 | bp->attr.bp_type = attr->bp_type; |
469 | bp->attr.bp_len = attr->bp_len; | 471 | bp->attr.bp_len = attr->bp_len; |
470 | 472 | ||
473 | if (check && memcmp(&bp->attr, attr, sizeof(*attr))) | ||
474 | return -EINVAL; | ||
475 | |||
471 | err = validate_hw_breakpoint(bp); | 476 | err = validate_hw_breakpoint(bp); |
472 | if (!err && modify) | 477 | if (!err && modify) |
473 | err = modify_bp_slot(bp, old_type); | 478 | err = modify_bp_slot(bp, old_type); |
@@ -505,7 +510,7 @@ int modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *att | |||
505 | else | 510 | else |
506 | perf_event_disable(bp); | 511 | perf_event_disable(bp); |
507 | 512 | ||
508 | err = __modify_user_hw_breakpoint(bp, attr); | 513 | err = modify_user_hw_breakpoint_check(bp, attr, false); |
509 | 514 | ||
510 | if (err) { | 515 | if (err) { |
511 | if (!bp->attr.disabled) | 516 | if (!bp->attr.disabled) |