From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Subject: [PATCH 8/9 v2] trace-cmd input: Add validation updates to the copy of a handle
Date: Fri, 05 Mar 2021 17:52:31 -0500 [thread overview]
Message-ID: <20210305225948.439772410@goodmis.org> (raw)
In-Reply-To: 20210305225223.794554327@goodmis.org
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
When copying the input handle the file descriptor is changed. Change its
state along with that.
Currently the tracecmd_copy_headers() restores the original state, but does
not restore the file descriptor. That may need to change.
Link: https://lore.kernel.org/linux-trace-devel/20210301143857.841258346@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
lib/trace-cmd/trace-input.c | 48 ++++++++++++++++++++++---------------
1 file changed, 29 insertions(+), 19 deletions(-)
diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
index b4d18209fe2d..24b3aa4001d3 100644
--- a/lib/trace-cmd/trace-input.c
+++ b/lib/trace-cmd/trace-input.c
@@ -3528,12 +3528,14 @@ 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);
+ /* Now that the file handle has moved, change its state */
+ handle->file_state = TRACECMD_FILE_HEADERS;
+
/* "header_page" */
if (read_copy_data(handle, 12, fd) < 0)
return -1;
@@ -3563,8 +3565,7 @@ 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)
+ if (handle->file_state != TRACECMD_FILE_FTRACE_EVENTS - 1)
return -1;
if (read_copy_size4(handle, fd, &count) < 0)
@@ -3579,6 +3580,8 @@ static int copy_ftrace_files(struct tracecmd_input *handle, int fd)
return -1;
}
+ handle->file_state = TRACECMD_FILE_FTRACE_EVENTS;
+
return 0;
}
@@ -3590,8 +3593,7 @@ 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)
+ if (handle->file_state != TRACECMD_FILE_ALL_EVENTS - 1)
return -1;
if (read_copy_size4(handle, fd, &systems) < 0)
@@ -3619,6 +3621,8 @@ static int copy_event_files(struct tracecmd_input *handle, int fd)
}
}
+ handle->file_state = TRACECMD_FILE_ALL_EVENTS;
+
return 0;
}
@@ -3626,8 +3630,7 @@ 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)
+ if (handle->file_state != TRACECMD_FILE_KALLSYMS - 1)
return -1;
if (read_copy_size4(handle, fd, &size) < 0)
@@ -3638,6 +3641,8 @@ static int copy_proc_kallsyms(struct tracecmd_input *handle, int fd)
if (read_copy_data(handle, size, fd) < 0)
return -1;
+ handle->file_state = TRACECMD_FILE_KALLSYMS;
+
return 0;
}
@@ -3645,8 +3650,7 @@ 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)
+ if (handle->file_state != TRACECMD_FILE_PRINTK - 1)
return -1;
if (read_copy_size4(handle, fd, &size) < 0)
@@ -3657,6 +3661,8 @@ static int copy_ftrace_printk(struct tracecmd_input *handle, int fd)
if (read_copy_data(handle, size, fd) < 0)
return -1;
+ handle->file_state = TRACECMD_FILE_PRINTK;
+
return 0;
}
@@ -3664,8 +3670,7 @@ 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)
+ if (handle->file_state != TRACECMD_FILE_CMD_LINES - 1)
return -1;
if (read_copy_size8(handle, fd, &size) < 0)
@@ -3676,6 +3681,8 @@ static int copy_command_lines(struct tracecmd_input *handle, int fd)
if (read_copy_data(handle, size, fd) < 0)
return -1;
+ handle->file_state = TRACECMD_FILE_CMD_LINES;
+
return 0;
}
@@ -3683,31 +3690,34 @@ int tracecmd_copy_headers(struct tracecmd_input *handle, int fd)
{
int ret;
+ /* Make sure that the input handle is up to cmd lines */
+ if (handle->file_state < TRACECMD_FILE_CMD_LINES)
+ return -1;
+
ret = copy_header_files(handle, fd);
if (ret < 0)
- return -1;
+ goto out;
ret = copy_ftrace_files(handle, fd);
if (ret < 0)
- return -1;
+ goto out;
ret = copy_event_files(handle, fd);
if (ret < 0)
- return -1;
+ goto out;
ret = copy_proc_kallsyms(handle, fd);
if (ret < 0)
- return -1;
+ goto out;
ret = copy_ftrace_printk(handle, fd);
if (ret < 0)
- return -1;
+ goto out;
ret = copy_command_lines(handle, fd);
- if (ret < 0)
- return -1;
- return 0;
+ out:
+ return ret < 0 ? -1 : 0;
}
/**
--
2.30.0
next prev parent reply other threads:[~2021-03-05 23:00 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-05 22:52 [PATCH 0/9 v2] trace-cmd: Fixes for trace-cmd restore Steven Rostedt
2021-03-05 22:52 ` [PATCH 1/9 v2] trace-cmd restore: Fix to add saved cmdlines after calling tracecmd_create_init_file_override() Steven Rostedt
2021-03-05 22:52 ` [PATCH 2/9 v2] trace-cmd: Move tracecmd_write_cmdlines() out of tracecmd_append_cpu_data() Steven Rostedt
2021-03-05 22:52 ` [PATCH 3/9 v2] trace-cmd: Move the output state updates into the functions that change the state Steven Rostedt
2021-03-05 22:52 ` [PATCH 4/9 v2] trace-cmd: Move the input " Steven Rostedt
2021-03-05 22:52 ` [PATCH 5/9 v2] trace-cmd input: Validate the input handle when copying from it Steven Rostedt
2021-03-05 22:52 ` [PATCH 6/9 v2] trace-cmd: Have tracecmd_read_headers() specify the state to read up to Steven Rostedt
2021-03-05 22:52 ` [PATCH 7/9 v2] trace-cmd: Have tracecmd_get_file_state() return the enum Steven Rostedt
2021-03-05 22:52 ` Steven Rostedt [this message]
2021-03-05 22:52 ` [PATCH 9/9 v2] trace-cmd: Have tracecmd_copy_headers() have a start and stop state Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210305225948.439772410@goodmis.org \
--to=rostedt@goodmis.org \
--cc=linux-trace-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).