浏览代码

perf tools: Check we are able to read the event size on mmap

Check we have enough mmaped space to read the current event
size from its headers, otherwise we may dereference some
hell there.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Stephane Eranian <eranian@google.com>
Frederic Weisbecker 14 年之前
父节点
当前提交
eac9eacee1
共有 1 个文件被更改,包括 7 次插入0 次删除
  1. 7 0
      tools/perf/util/session.c

+ 7 - 0
tools/perf/util/session.c

@@ -1007,6 +1007,13 @@ remap:
 	file_pos = file_offset + head;
 	file_pos = file_offset + head;
 
 
 more:
 more:
+	/*
+	 * Ensure we have enough space remaining to read
+	 * the size of the event in the headers.
+	 */
+	if (head + sizeof(event->header) > mmap_size)
+		goto remap;
+
 	event = (union perf_event *)(buf + head);
 	event = (union perf_event *)(buf + head);
 
 
 	if (session->header.needs_swap)
 	if (session->header.needs_swap)