summaryrefslogtreecommitdiff
path: root/tools/perf/util
diff options
context:
space:
mode:
authorVince Weaver <vincent.weaver@maine.edu>2019-07-23 11:06:01 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-08-25 10:50:11 +0200
commit577b3ccbb8259a4e76177cedb837c076f5e69111 (patch)
tree2e76c4194de000ad62e8ffcd9c410476ec9bbc53 /tools/perf/util
parent31afdd903a1d6738f503694e1bb38af3e9b98fea (diff)
perf header: Fix divide by zero error if f_header.attr_size==0
[ Upstream commit 7622236ceb167aa3857395f9bdaf871442aa467e ] So I have been having lots of trouble with hand-crafted perf.data files causing segfaults and the like, so I have started fuzzing the perf tool. First issue found: If f_header.attr_size is 0 in the perf.data file, then perf will crash with a divide-by-zero error. Committer note: Added a pr_err() to tell the user why the command failed. Signed-off-by: Vince Weaver <vincent.weaver@maine.edu> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/alpine.DEB.2.21.1907231100440.14532@macbook-air Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'tools/perf/util')
-rw-r--r--tools/perf/util/header.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index c892a28e7b04..cad15254c031 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2901,6 +2901,13 @@ int perf_session__read_header(struct perf_session *session)
file->path);
}
+ if (f_header.attr_size == 0) {
+ pr_err("ERROR: The %s file's attr size field is 0 which is unexpected.\n"
+ "Was the 'perf record' command properly terminated?\n",
+ file->path);
+ return -EINVAL;
+ }
+
nr_attrs = f_header.attrs.size / f_header.attr_size;
lseek(fd, f_header.attrs.offset, SEEK_SET);