mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Douglas Raillard <douglas.raillard@arm.com>
To: Steven Rostedt <rostedt@kernel.org>,
	linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
	linux-perf-users@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Takaya Saeki <takayas@google.com>,
	Tom Zanussi <zanussi@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ian Rogers <irogers@google.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Jiri Olsa <jolsa@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Ingo Molnar <mingo@redhat.com>
Subject: Re: [PATCH v3 12/13] tracing: Check for printable characters when printing field dyn strings
Date: Mon, 20 Oct 2025 13:19:46 +0100	[thread overview]
Message-ID: <8d15e5a6-e80a-4707-a43a-4cbb6d810222@arm.com> (raw)
In-Reply-To: <20251015173550.062240695@kernel.org>

Hi Steve,

On 15-10-2025 18:32, Steven Rostedt wrote:
> From: Steven Rostedt <rostedt@goodmis.org>
> 
> When the "fields" option is enabled, it prints each trace event field
> based on its type. But a dynamic array and a dynamic string can both have
> a "char *" type. Printing it as a string can cause escape characters to be
> printed and mess up the output of the trace.

We faced the same issue when converting trace.dat to other formats that distinguish
between a byte buffer and an actual string. The current solution we have is to
reserve "char []" for actual string and use "u8 []"/"uint8_t []" for byte buffers.

Obviously it does not solve the problem for existing events but that could be worth
establishing a convention like that for new code and support it in trace_output.c ?
Most uses of trace data beyond direct printing would require knowing the data schema
from the header info, so value-based criteria are typically not suitable for that.

> For dynamic strings, test if there are any non-printable characters, and
> if so, print both the string with the non printable characters as '.', and
> the print the hex value of the array.
> 
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
>   kernel/trace/trace_output.c | 27 +++++++++++++++++++++++++--
>   1 file changed, 25 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
> index 97db0b0ccf3e..718b255b6fd8 100644
> --- a/kernel/trace/trace_output.c
> +++ b/kernel/trace/trace_output.c
> @@ -950,7 +950,9 @@ static void print_fields(struct trace_iterator *iter, struct trace_event_call *c
>   	int offset;
>   	int len;
>   	int ret;
> +	int i;
>   	void *pos;
> +	char *str;
>   
>   	list_for_each_entry_reverse(field, head, link) {
>   		trace_seq_printf(&iter->seq, " %s=", field->name);
> @@ -977,8 +979,29 @@ static void print_fields(struct trace_iterator *iter, struct trace_event_call *c
>   				trace_seq_puts(&iter->seq, "<OVERFLOW>");
>   				break;
>   			}
> -			pos = (void *)iter->ent + offset;
> -			trace_seq_printf(&iter->seq, "%.*s", len, (char *)pos);
> +			str = (char *)iter->ent + offset;
> +			/* Check if there's any non printable strings */
> +			for (i = 0; i < len; i++) {
> +				if (str[i] && !(isascii(str[i]) && isprint(str[i])))
> +					break;
> +			}
> +			if (i < len) {
> +				for (i = 0; i < len; i++) {
> +					if (isascii(str[i]) && isprint(str[i]))
> +						trace_seq_putc(&iter->seq, str[i]);
> +					else
> +						trace_seq_putc(&iter->seq, '.');
> +				}
> +				trace_seq_puts(&iter->seq, " (");
> +				for (i = 0; i < len; i++) {
> +					if (i)
> +						trace_seq_putc(&iter->seq, ':');
> +					trace_seq_printf(&iter->seq, "%02x", str[i]);
> +				}
> +				trace_seq_putc(&iter->seq, ')');
> +			} else {
> +				trace_seq_printf(&iter->seq, "%.*s", len, str);
> +			}
>   			break;
>   		case FILTER_PTR_STRING:
>   			if (!iter->fmt_size)

--

Douglas

  reply	other threads:[~2025-10-20 12:19 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-15 17:32 [PATCH v3 00/13] tracing: Show contents of syscall trace event user space fields Steven Rostedt
2025-10-15 17:32 ` [PATCH v3 01/13] tracing: Make trace_user_fault_read() exposed to rest of tracing Steven Rostedt
2025-10-15 17:32 ` [PATCH v3 02/13] tracing: Have syscall trace events read user space string Steven Rostedt
2025-10-15 17:32 ` [PATCH v3 03/13] perf: tracing: Simplify perf_sysenter_enable/disable() with guards Steven Rostedt
2025-10-16 11:05   ` kernel test robot
2025-10-15 17:32 ` [PATCH v3 04/13] perf: tracing: Have perf system calls read user space Steven Rostedt
2025-10-15 17:32 ` [PATCH v3 05/13] tracing: Have system call events record user array data Steven Rostedt
2025-10-15 17:32 ` [PATCH v3 06/13] tracing: Display some syscall arrays as strings Steven Rostedt
2025-10-15 17:32 ` [PATCH v3 07/13] tracing: Allow syscall trace events to read more than one user parameter Steven Rostedt
2025-10-15 17:32 ` [PATCH v3 08/13] tracing: Add a config and syscall_user_buf_size file to limit amount written Steven Rostedt
2025-10-15 17:32 ` [PATCH v3 09/13] tracing: Show printable characters in syscall arrays Steven Rostedt
2025-10-15 17:32 ` [PATCH v3 10/13] tracing: Add trace_seq_pop() and seq_buf_pop() Steven Rostedt
2025-10-15 17:32 ` [PATCH v3 11/13] tracing: Add parsing of flags to the sys_enter_openat trace event Steven Rostedt
2025-10-15 17:32 ` [PATCH v3 12/13] tracing: Check for printable characters when printing field dyn strings Steven Rostedt
2025-10-20 12:19   ` Douglas Raillard [this message]
2025-10-20 18:47     ` Steven Rostedt
2025-10-15 17:32 ` [PATCH v3 13/13] tracing: Have persistent ring buffer print syscalls normally Steven Rostedt
2025-10-16 10:33   ` kernel test robot
2025-10-16 11:36   ` kernel test robot

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=8d15e5a6-e80a-4707-a43a-4cbb6d810222@arm.com \
    --to=douglas.raillard@arm.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@kernel.org \
    --cc=takayas@google.com \
    --cc=tglx@linutronix.de \
    --cc=zanussi@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

all inboxes | Powered by JetHome®