perf tools: Check we are able to read the event size on mmap
authorFrederic Weisbecker <[email protected]>
Sat, 21 May 2011 15:07:24 +0000 (17:07 +0200)
committerFrederic Weisbecker <[email protected]>
Sun, 22 May 2011 01:12:13 +0000 (03:12 +0200)
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 <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Stephane Eranian <[email protected]>
tools/perf/util/session.c

index fff66741f18d5db2ef85579eef21a5f3ff9ec46b..61746b5866d81d6b494be4dbca2916af1fc38b31 100644 (file)
@@ -1007,6 +1007,13 @@ remap:
        file_pos = file_offset + head;
 
 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);
 
        if (session->header.needs_swap)