linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	"Steven Rostedt (VMware)" <rostedt@goodmis.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 12/32] tools lib traceevent: Handle new pointer processing of bprint strings
Date: Wed, 17 Jan 2018 13:12:02 -0300	[thread overview]
Message-ID: <20180117161222.15611-13-acme@kernel.org> (raw)
In-Reply-To: <20180117161222.15611-1-acme@kernel.org>

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

The Linux kernel printf() has some extended use cases that dereference
the pointer. This is dangerouse for tracing because the pointer that is
dereferenced can change or even be unmapped. It also causes issues when
the trace data is extracted, because user space does not have access to
the contents of the pointer even if it still exists.

To handle this, the kernel was updated to process these dereferenced
pointers at the time they are recorded, and not post processed. Now they
exist in the tracing buffer, and no dereference is needed at the time of
reading the trace.

The event parsing library needs to handle this new case.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Link: http://lkml.kernel.org/r/20180112004822.403349289@goodmis.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/lib/traceevent/event-parse.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 8757dd64e42c..344a034a8fbc 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -4300,6 +4300,26 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
 				goto process_again;
 			case 'p':
 				ls = 1;
+				if (isalnum(ptr[1])) {
+					ptr++;
+					/* Check for special pointers */
+					switch (*ptr) {
+					case 's':
+					case 'S':
+					case 'f':
+					case 'F':
+						break;
+					default:
+						/*
+						 * Older kernels do not process
+						 * dereferenced pointers.
+						 * Only process if the pointer
+						 * value is a printable.
+						 */
+						if (isprint(*(char *)bptr))
+							goto process_string;
+					}
+				}
 				/* fall through */
 			case 'd':
 			case 'u':
@@ -4352,6 +4372,7 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
 
 				break;
 			case 's':
+ process_string:
 				arg = alloc_arg();
 				if (!arg) {
 					do_warning_event(event, "%s(%d): not enough memory!",
@@ -4959,6 +4980,11 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
 				if (isalnum(ptr[1]))
 					ptr++;
 
+				if (arg->type == PRINT_BSTRING) {
+					trace_seq_puts(s, arg->string.string);
+					break;
+				}
+
 				if (*ptr == 'F' || *ptr == 'f' ||
 				    *ptr == 'S' || *ptr == 's') {
 					show_func = *ptr;
-- 
2.14.3

  parent reply	other threads:[~2018-01-17 16:13 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-17 16:11 [GIT PULL 00/32] perf/core improvements and fixes Arnaldo Carvalho de Melo
2018-01-17 16:11 ` [PATCH 01/32] perf evsel: Fix incorrect handling of type _TERM_DRV_CFG Arnaldo Carvalho de Melo
2018-01-17 16:11 ` [PATCH 02/32] perf evlist: Remove trailing semicolon Arnaldo Carvalho de Melo
2018-01-17 16:11 ` [PATCH 03/32] perf script python: Add script to profile and resolve physical mem type Arnaldo Carvalho de Melo
2018-01-17 16:11 ` [PATCH 04/32] perf trace: No need to set PERF_SAMPLE_IDENTIFIER explicitely Arnaldo Carvalho de Melo
2018-01-17 16:11 ` [PATCH 05/32] perf tools: Fix copyfile_offset update of output offset Arnaldo Carvalho de Melo
2018-01-17 16:11 ` [PATCH 06/32] perf evsel: Check if callchain is enabled before setting it up Arnaldo Carvalho de Melo
2018-01-17 16:11 ` [PATCH 07/32] perf trace: Fix setting of --call-graph/--max-stack for non-syscall events Arnaldo Carvalho de Melo
2018-01-17 16:11 ` [PATCH 08/32] tools lib traceevent: Fix bad force_token escape sequence Arnaldo Carvalho de Melo
2018-01-17 16:11 ` [PATCH 09/32] tools lib traceevent: Show value of flags that have not been parsed Arnaldo Carvalho de Melo
2018-01-17 16:12 ` [PATCH 10/32] tools lib traceevent: Print value of unknown symbolic fields Arnaldo Carvalho de Melo
2018-01-17 16:12 ` [PATCH 11/32] tools lib traceevent: Simplify pointer print logic and fix %pF Arnaldo Carvalho de Melo
2018-01-17 16:12 ` Arnaldo Carvalho de Melo [this message]
2018-01-17 16:12 ` [PATCH 13/32] tools lib traceevent: Show contents (in hex) of data of unrecognized type records Arnaldo Carvalho de Melo
2018-01-17 16:12 ` [PATCH 14/32] tools lib traceevent: Use asprintf when possible Arnaldo Carvalho de Melo
2018-01-17 16:12 ` [PATCH 15/32] tools lib traceevent: Add UL suffix to MISSING_EVENTS Arnaldo Carvalho de Melo
2018-01-17 16:12 ` [PATCH 16/32] tools lib traceevent: Fix missing break in FALSE case of pevent_filter_clear_trivial() Arnaldo Carvalho de Melo
2018-01-17 16:12 ` [PATCH 17/32] tools lib traceevent: Fix get_field_str() for dynamic strings Arnaldo Carvalho de Melo
2018-01-17 16:12 ` [PATCH 18/32] perf tools: Add ARM Statistical Profiling Extensions (SPE) support Arnaldo Carvalho de Melo
2018-01-17 16:12 ` [PATCH 19/32] perf callchain: Fix attr.sample_max_stack setting Arnaldo Carvalho de Melo
2018-01-17 16:12 ` [PATCH 20/32] perf unwind: Do not look just at the global callchain_param.record_mode Arnaldo Carvalho de Melo
2018-01-17 16:12 ` [PATCH 21/32] perf trace: Setup DWARF callchains for non-syscall events when --max-stack is used Arnaldo Carvalho de Melo
2018-01-17 16:12 ` [PATCH 22/32] perf trace: Allow overriding global --max-stack per event Arnaldo Carvalho de Melo
2018-01-17 16:12 ` [PATCH 23/32] perf callchains: Ask for PERF_RECORD_MMAP for data mmaps for DWARF unwinding Arnaldo Carvalho de Melo
2018-01-17 16:12 ` [PATCH 24/32] perf report: Improve error msg when no first/last sample time found Arnaldo Carvalho de Melo
2018-01-17 16:12 ` [PATCH 25/32] perf script: " Arnaldo Carvalho de Melo
2018-01-17 16:12 ` [PATCH 26/32] perf util: Improve error checking for time percent input Arnaldo Carvalho de Melo
2018-01-17 16:12 ` [PATCH 27/32] perf util: Support no index time percent slice Arnaldo Carvalho de Melo
2018-01-17 16:12 ` [PATCH 28/32] perf report: Add an indication of what time slices are used Arnaldo Carvalho de Melo
2018-01-17 16:12 ` [PATCH 29/32] perf util: Allocate time slices buffer according to number of comma Arnaldo Carvalho de Melo
2018-01-17 16:12 ` [PATCH 30/32] perf report: Remove the time slices number limitation Arnaldo Carvalho de Melo
2018-01-17 16:12 ` [PATCH 31/32] perf script: " Arnaldo Carvalho de Melo
2018-01-17 16:12 ` [PATCH 32/32] perf record: Fix failed memory allocation for get_cpuid_str Arnaldo Carvalho de Melo
2018-01-17 16:22 ` [GIT PULL 00/32] perf/core improvements and fixes Ingo Molnar

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=20180117161222.15611-13-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@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;
as well as URLs for NNTP newsgroup(s).