mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Daney <ddaney@caviumnetworks.com>
To: rostedt@goodmis.org
Cc: linux-kernel@vger.kernel.org, David Daney <ddaney@caviumnetworks.com>
Subject: [PATCH 1/2] trace-cmd: Don't try to read unmapped memory (v2).
Date: Mon, 19 Jul 2010 17:46:49 -0700	[thread overview]
Message-ID: <1279586810-29859-2-git-send-email-ddaney@caviumnetworks.com> (raw)
In-Reply-To: <1279586810-29859-1-git-send-email-ddaney@caviumnetworks.com>

Under some circumstances, I'm not sure exactly which, a trace.dat file
may contain a bunch of zeros at the end of one or more of the trace
logs.  This can lead to tracecmd_peek_data() attempting to read past
the end of the mmaped log, causing SIGSEGV.

This is a two part fix.

1) For 'new format' data, we always try to read 8 bytes of data.  Make
sure that they are all on the current page.

2) In pevent_print_event(), if record->size is negative, warn and then
skip attempting to print it.

Signed-off-by: David Daney <ddaney@caviumnetworks.com>
---
 parse-events.c |    5 +++++
 trace-input.c  |    3 ++-
 2 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/parse-events.c b/parse-events.c
index 16fff12..52b68f0 100644
--- a/parse-events.c
+++ b/parse-events.c
@@ -3881,6 +3881,11 @@ void pevent_print_event(struct pevent *pevent, struct trace_seq *s,
 	usecs = record->ts - secs * NSECS_PER_SEC;
 	usecs = (usecs + 500) / NSECS_PER_USEC;
 
+	if (record->size < 0) {
+		do_warning("ug! negative record size %d", record->size);
+		return;
+	}
+
 	type = trace_parse_common_type(pevent, data);
 
 	event = pevent_find_event(pevent, type);
diff --git a/trace-input.c b/trace-input.c
index 398d0f9..7241197 100644
--- a/trace-input.c
+++ b/trace-input.c
@@ -1511,7 +1511,8 @@ read_again:
 	if (index < 0)
 		die("negative index on cpu record %d", cpu);
 
-	if (index >= handle->cpu_data[cpu].page_size + pevent->header_page_data_offset) {
+	if (index + (pevent->old_format ? 0 : 4) >=
+	    handle->cpu_data[cpu].page_size + pevent->header_page_data_offset) {
 		if (get_next_page(handle, cpu))
 			return NULL;
 		return tracecmd_peek_data(handle, cpu);
-- 
1.7.1.1


  reply	other threads:[~2010-07-20  0:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-20  0:46 [PATCH 0/2] trace-cmd: Fix a couple of crashes David Daney
2010-07-20  0:46 ` David Daney [this message]
2010-07-20  0:46 ` [PATCH 2/2] trace-cmd: Don't SIGSEGV in trace-graph.c:load_handle David Daney
2010-07-20 19:55 ` [PATCH 0/2] trace-cmd: Fix a couple of crashes 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=1279586810-29859-2-git-send-email-ddaney@caviumnetworks.com \
    --to=ddaney@caviumnetworks.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.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

all inboxes | Powered by JetHome®