From: "Steven Rostedt (VMware)" <rostedt@xxxxxxxxxxx> Now that there's validation states, make sure that the input handle is at the correct state to validate it. Link: https://lore.kernel.org/linux-trace-devel/20210301143857.694136727@xxxxxxxxxxx Signed-off-by: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx> --- lib/trace-cmd/trace-input.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index debc8160880e..b7166a9b1f40 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -3472,6 +3472,10 @@ static int copy_header_files(struct tracecmd_input *handle, int fd) { unsigned long long size; + /* The input handle has to have at least read the headers */ + if (handle->file_state < TRACECMD_FILE_HEADERS) + return -1; + lseek64(handle->fd, handle->header_files_start, SEEK_SET); /* "header_page" */ @@ -3503,6 +3507,10 @@ static int copy_ftrace_files(struct tracecmd_input *handle, int fd) unsigned int count; unsigned int i; + /* The input handle has to have at least read the ftrace events */ + if (handle->file_state < TRACECMD_FILE_FTRACE_EVENTS) + return -1; + if (read_copy_size4(handle, fd, &count) < 0) return -1; @@ -3526,6 +3534,10 @@ static int copy_event_files(struct tracecmd_input *handle, int fd) unsigned int count; unsigned int i,x; + /* The input handle has to have at least read all its events */ + if (handle->file_state < TRACECMD_FILE_ALL_EVENTS) + return -1; + if (read_copy_size4(handle, fd, &systems) < 0) return -1; @@ -3558,6 +3570,10 @@ static int copy_proc_kallsyms(struct tracecmd_input *handle, int fd) { unsigned int size; + /* The input handle has to have at least has kallsyms */ + if (handle->file_state < TRACECMD_FILE_KALLSYMS) + return -1; + if (read_copy_size4(handle, fd, &size) < 0) return -1; if (!size) @@ -3573,6 +3589,10 @@ static int copy_ftrace_printk(struct tracecmd_input *handle, int fd) { unsigned int size; + /* The input handle has to have at least has printk stored */ + if (handle->file_state < TRACECMD_FILE_PRINTK) + return -1; + if (read_copy_size4(handle, fd, &size) < 0) return -1; if (!size) @@ -3588,6 +3608,10 @@ static int copy_command_lines(struct tracecmd_input *handle, int fd) { unsigned long long size; + /* The input handle has to have at least read the cmdlines */ + if (handle->file_state < TRACECMD_FILE_CMD_LINES) + return -1; + if (read_copy_size8(handle, fd, &size) < 0) return -1; if (!size) -- 2.30.0