aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVaibhav Nagarnaik <vnagarnaik@google.com>2011-06-20 20:19:38 -0400
committerSteven Rostedt <rostedt@goodmis.org>2011-06-29 11:26:53 -0400
commitaac14bf600784eb13d24fc93ca1838a7c4f187df (patch)
tree9a9df33202b795f6f7d3dbfa942a4687a44d08fd
parent1e57b57502e47eff379cfe8347bab61eadbcf3c0 (diff)
trace-cmd: Add check for truncated files
If the trace data file that is being read is truncated, mmap'ing its non-existent page does not give any error. When the page is read, the process dies with a SIGBUS. This patch adds a file size check while initializing the trace data and makes sure that the file size matches the expected size; otherwise an error is returned. Cc: Michael Rubin <mrubin@google.com> Cc: David Sharp <dhsharp@google.com> Signed-off-by: Vaibhav Nagarnaik <vnagarnaik@google.com> Link: http://lkml.kernel.org/r/1308615578-556-1-git-send-email-vnagarnaik@google.com Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--trace-input.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/trace-input.c b/trace-input.c
index f537ef5..723d47f 100644
--- a/trace-input.c
+++ b/trace-input.c
@@ -92,6 +92,7 @@ struct tracecmd_input {
92 size_t header_files_start; 92 size_t header_files_start;
93 size_t ftrace_files_start; 93 size_t ftrace_files_start;
94 size_t event_files_start; 94 size_t event_files_start;
95 size_t total_file_size;
95}; 96};
96 97
97__thread struct tracecmd_input *tracecmd_curr_thread_handle; 98__thread struct tracecmd_input *tracecmd_curr_thread_handle;
@@ -2085,6 +2086,15 @@ int tracecmd_init_data(struct tracecmd_input *handle)
2085 handle->cpu_data[cpu].file_offset = offset; 2086 handle->cpu_data[cpu].file_offset = offset;
2086 handle->cpu_data[cpu].file_size = size; 2087 handle->cpu_data[cpu].file_size = size;
2087 2088
2089 if (offset + size > handle->total_file_size) {
2090 /* this happens if the file got truncated */
2091 printf("File possibly truncated. "
2092 "Need at least %llu, but file size is %lu.\n",
2093 offset + size, handle->total_file_size);
2094 errno = EINVAL;
2095 return -1;
2096 }
2097
2088 if (init_cpu(handle, cpu)) 2098 if (init_cpu(handle, cpu))
2089 return -1; 2099 return -1;
2090 } 2100 }
@@ -2189,6 +2199,12 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd)
2189 handle->header_files_start = 2199 handle->header_files_start =
2190 lseek64(handle->fd, 0, SEEK_CUR); 2200 lseek64(handle->fd, 0, SEEK_CUR);
2191 2201
2202 handle->total_file_size =
2203 lseek64(handle->fd, 0, SEEK_END);
2204
2205 handle->header_files_start =
2206 lseek64(handle->fd, handle->header_files_start, SEEK_SET);
2207
2192 return handle; 2208 return handle;
2193 2209
2194 failed_read: 2210 failed_read: