[PATCH 06/10] libperf: Do not allow PERF_FORMAT_GROUP in perf_evsel__read

From: Jiri Olsa
Date: Tue Jun 22 2021 - 11:39:51 EST


The struct perf_counts_values can hold only first three
read_format bits. We can't allow PERF_FORMAT_GROUP,
otherwise we get segfault.

Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
tools/lib/perf/evsel.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c
index bd8c2f19ef74..04e8386b3ed4 100644
--- a/tools/lib/perf/evsel.c
+++ b/tools/lib/perf/evsel.c
@@ -260,8 +260,12 @@ int perf_evsel__read_size(struct perf_evsel *evsel)
int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread,
struct perf_counts_values *count)
{
+ u64 read_format = evsel->attr.read_format;
size_t size = perf_evsel__read_size(evsel);

+ if (read_format & PERF_FORMAT_GROUP)
+ return -EINVAL;
+
memset(count, 0, sizeof(*count));

if (FD(evsel, cpu, thread) < 0)
--
2.31.1