[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <tip-705feaf321c37e4dca3637fd5cb3b275f17a06c9@git.kernel.org>
Date: Mon, 12 Mar 2018 23:20:47 -0700
From: tip-bot for Jiri Olsa <tipbot@...or.com>
To: linux-tip-commits@...r.kernel.org
Cc: hbathini@...ux.vnet.ibm.com, a.p.zijlstra@...llo.nl, hpa@...or.com,
kan.liang@...el.com, onestero@...hat.com, mpe@...erman.id.au,
peterz@...radead.org, jolsa@...hat.com,
linux-kernel@...r.kernel.org, jolsa@...nel.org,
will.deacon@....com, alexander.shishkin@...ux.intel.com,
mingo@...nel.org, torvalds@...ux-foundation.org,
namhyung@...nel.org, acme@...hat.com, dsahern@...il.com,
tglx@...utronix.de, chabbi.milind@...il.com,
sukadev@...ux.vnet.ibm.com, yao.jin@...ux.intel.com,
fweisbec@...il.com
Subject: [tip:perf/core] hw_breakpoint: Add perf_event_attr fields check in
__modify_user_hw_breakpoint()
Commit-ID: 705feaf321c37e4dca3637fd5cb3b275f17a06c9
Gitweb: https://git.kernel.org/tip/705feaf321c37e4dca3637fd5cb3b275f17a06c9
Author: Jiri Olsa <jolsa@...nel.org>
AuthorDate: Mon, 12 Mar 2018 14:45:45 +0100
Committer: Ingo Molnar <mingo@...nel.org>
CommitDate: Tue, 13 Mar 2018 06:56:08 +0100
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@...radead.org>
Signed-off-by: Jiri Olsa <jolsa@...nel.org>
Cc: Alexander Shishkin <alexander.shishkin@...ux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@...hat.com>
Cc: David Ahern <dsahern@...il.com>
Cc: Frederic Weisbecker <fweisbec@...il.com>
Cc: Hari Bathini <hbathini@...ux.vnet.ibm.com>
Cc: Jin Yao <yao.jin@...ux.intel.com>
Cc: Jiri Olsa <jolsa@...hat.com>
Cc: Kan Liang <kan.liang@...el.com>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Michael Ellerman <mpe@...erman.id.au>
Cc: Milind Chabbi <chabbi.milind@...il.com>
Cc: Namhyung Kim <namhyung@...nel.org>
Cc: Oleg Nesterov <onestero@...hat.com>
Cc: Peter Zijlstra <a.p.zijlstra@...llo.nl>
Cc: Sukadev Bhattiprolu <sukadev@...ux.vnet.ibm.com>
Cc: Thomas Gleixner <tglx@...utronix.de>
Cc: Will Deacon <will.deacon@....com>
Link: http://lkml.kernel.org/r/20180312134548.31532-6-jolsa@kernel.org
Signed-off-by: Ingo Molnar <mingo@...nel.org>
---
kernel/events/hw_breakpoint.c | 9 +++++++--
1 file 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,
}
EXPORT_SYMBOL_GPL(register_user_hw_breakpoint);
-static int __modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *attr)
+static int
+modify_user_hw_breakpoint_check(struct perf_event *bp, struct perf_event_attr *attr,
+ bool check)
{
u64 old_addr = bp->attr.bp_addr;
u64 old_len = bp->attr.bp_len;
@@ -468,6 +470,9 @@ static int __modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_
bp->attr.bp_type = attr->bp_type;
bp->attr.bp_len = attr->bp_len;
+ if (check && memcmp(&bp->attr, attr, sizeof(*attr)))
+ return -EINVAL;
+
err = validate_hw_breakpoint(bp);
if (!err && modify)
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
else
perf_event_disable(bp);
- err = __modify_user_hw_breakpoint(bp, attr);
+ err = modify_user_hw_breakpoint_check(bp, attr, false);
if (err) {
if (!bp->attr.disabled)
Powered by blists - more mailing lists