All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Subject: [PATCH 1/2] trace-cmd: Duplicate trace_clock in tracecmd_input handle
Date: Thu, 19 Dec 2019 16:48:06 -0500	[thread overview]
Message-ID: <20191219214858.137902679@goodmis.org> (raw)
In-Reply-To: 20191219214805.821145530@goodmis.org

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

The following crashes:

 # trace-cmd record -C local -e sched -B foo -e irq sleep 1
 # trace-cmd report

The issue is that new instances are copied from the top instance descriptor
and their values are set. This means that the trace_clock field is also
copied which is a pointer to a string.

On freeing of the tracecmd_input handlers, the trace_clock is freed. This
is an issue if the trace_clock was added as an option, because the instance
just has a copy of the top instance, and when the instance descriptor is
freed, it will free the same pointer that was already freed by the
descruction of the top instance descriptor and we have a double free.

Have the creation of the instance tracecmd_input handler descriptor perform
a strdup() and have its own copy of the trace_clock.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 lib/trace-cmd/trace-input.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
index 3b187e3f135b..5688610fe082 100644
--- a/lib/trace-cmd/trace-input.c
+++ b/lib/trace-cmd/trace-input.c
@@ -3398,6 +3398,13 @@ tracecmd_buffer_instance_handle(struct tracecmd_input *handle, int indx)
 	new_handle->nr_buffers = 0;
 	new_handle->buffers = NULL;
 	new_handle->ref = 1;
+	if (handle->trace_clock) {
+		new_handle->trace_clock = strdup(handle->trace_clock);
+		if (!new_handle->trace_clock) {
+			free(new_handle);
+			return NULL;
+		}
+	}
 	new_handle->parent = handle;
 	new_handle->cpustats = NULL;
 	new_handle->hooks = NULL;
-- 
2.24.0



  reply	other threads:[~2019-12-19 21:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-19 21:48 [PATCH 0/2] trace-cmd: A couple of fixes Steven Rostedt
2019-12-19 21:48 ` Steven Rostedt [this message]
2019-12-19 21:48 ` [PATCH 2/2] tools lib traceevent: Add builtin handler for trace_marker_raw 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=20191219214858.137902679@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.