Skip to content

Commit 57fc032

Browse files
committed
perf session: Avoid infinite loop when seeing invalid header.size
Vince reported that when fuzzing the userland perf tool with a bogus perf.data file he got into a infinite loop in 'perf report'. Changing the return of fetch_mmaped_event() to ERR_PTR(-EINVAL) for that case gets us out of that infinite loop. Reported-by: Vince Weaver <vincent.weaver@maine.edu> Tested-by: Vince Weaver <vincent.weaver@maine.edu> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://lkml.kernel.org/r/20190726211415.GE24867@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 272172b commit 57fc032

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎tools/perf/util/session.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0
22
#include <errno.h>
33
#include <inttypes.h>
4+
#include <linux/err.h>
45
#include <linux/kernel.h>
56
#include <linux/zalloc.h>
67
#include <traceevent/event-parse.h>
@@ -1955,7 +1956,9 @@ fetch_mmaped_event(struct perf_session *session,
19551956
/* We're not fetching the event so swap back again */
19561957
if (session->header.needs_swap)
19571958
perf_event_header__bswap(&event->header);
1958-
return NULL;
1959+
pr_debug("%s: head=%#" PRIx64 " event->header_size=%#x, mmap_size=%#zx: fuzzed perf.data?\n",
1960+
__func__, head, event->header.size, mmap_size);
1961+
return ERR_PTR(-EINVAL);
19591962
}
19601963

19611964
return event;
@@ -1973,6 +1976,9 @@ static int __perf_session__process_decomp_events(struct perf_session *session)
19731976
while (decomp->head < decomp->size && !session_done()) {
19741977
union perf_event *event = fetch_mmaped_event(session, decomp->head, decomp->size, decomp->data);
19751978

1979+
if (IS_ERR(event))
1980+
return PTR_ERR(event);
1981+
19761982
if (!event)
19771983
break;
19781984

@@ -2072,6 +2078,9 @@ reader__process_events(struct reader *rd, struct perf_session *session,
20722078

20732079
more:
20742080
event = fetch_mmaped_event(session, head, mmap_size, buf);
2081+
if (IS_ERR(event))
2082+
return PTR_ERR(event);
2083+
20752084
if (!event) {
20762085
if (mmaps[map_idx]) {
20772086
munmap(mmaps[map_idx], mmap_size);

0 commit comments

Comments
 (0)