Skip to content

Commit

Permalink
perf session: Avoid infinite loop when seeing invalid header.size
Browse files Browse the repository at this point in the history
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 <[email protected]>
Tested-by: Vince Weaver <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
acmel committed Aug 12, 2019
1 parent 272172b commit 57fc032
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tools/perf/util/session.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
#include <errno.h>
#include <inttypes.h>
#include <linux/err.h>
#include <linux/kernel.h>
#include <linux/zalloc.h>
#include <traceevent/event-parse.h>
Expand Down Expand Up @@ -1955,7 +1956,9 @@ fetch_mmaped_event(struct perf_session *session,
/* We're not fetching the event so swap back again */
if (session->header.needs_swap)
perf_event_header__bswap(&event->header);
return NULL;
pr_debug("%s: head=%#" PRIx64 " event->header_size=%#x, mmap_size=%#zx: fuzzed perf.data?\n",
__func__, head, event->header.size, mmap_size);
return ERR_PTR(-EINVAL);
}

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

if (IS_ERR(event))
return PTR_ERR(event);

if (!event)
break;

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

more:
event = fetch_mmaped_event(session, head, mmap_size, buf);
if (IS_ERR(event))
return PTR_ERR(event);

if (!event) {
if (mmaps[map_idx]) {
munmap(mmaps[map_idx], mmap_size);
Expand Down

0 comments on commit 57fc032

Please sign in to comment.