Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tracing: Show printable characters in syscall arrays

When displaying the contents of the user space data passed to the kernel,
instead of just showing the array values, also print any printable
content.

Instead of just:

bash-1113 [003] ..... 3433.290654: sys_write(fd: 2, buf: 0x555a8deeddb0 (72:6f:6f:74:40:64:65:62:69:61:6e:2d:78:38:36:2d:36:34:3a:7e:23:20), count: 0x16)

Display:

bash-1113 [003] ..... 3433.290654: sys_write(fd: 2, buf: 0x555a8deeddb0 (72:6f:6f:74:40:64:65:62:69:61:6e:2d:78:38:36:2d:36:34:3a:7e:23:20) "root@debian-x86-64:~# ", count: 0x16)

This only affects tracing and does not affect perf, as this only updates
the output from the kernel. The output from perf is via user space. This
may change by an update to libtraceevent that will then update perf to
have this as well.

Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Takaya Saeki <takayas@google.com>
Cc: Tom Zanussi <zanussi@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ian Rogers <irogers@google.com>
Cc: Douglas Raillard <douglas.raillard@arm.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Link: https://lore.kernel.org/20251028231148.429422865@kernel.org
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

+21
+21
kernel/trace/trace_syscalls.c
··· 155 155 trace_seq_printf(s, "%s(", entry->name); 156 156 157 157 for (i = 0; i < entry->nb_args; i++) { 158 + bool printable = false; 159 + char *str; 158 160 159 161 if (trace_seq_has_overflowed(s)) 160 162 goto end; ··· 195 193 196 194 val = trace->args[entry->user_arg_size]; 197 195 196 + str = ptr; 198 197 trace_seq_puts(s, " ("); 199 198 for (int x = 0; x < len; x++, ptr++) { 199 + if (isascii(*ptr) && isprint(*ptr)) 200 + printable = true; 200 201 if (x) 201 202 trace_seq_putc(s, ':'); 202 203 trace_seq_printf(s, "%02x", *ptr); ··· 208 203 trace_seq_printf(s, ", %s", EXTRA); 209 204 210 205 trace_seq_putc(s, ')'); 206 + 207 + /* If nothing is printable, don't bother printing anything */ 208 + if (!printable) 209 + continue; 210 + 211 + trace_seq_puts(s, " \""); 212 + for (int x = 0; x < len; x++) { 213 + if (isascii(str[x]) && isprint(str[x])) 214 + trace_seq_putc(s, str[x]); 215 + else 216 + trace_seq_putc(s, '.'); 217 + } 218 + if (len < val) 219 + trace_seq_printf(s, "\"%s", EXTRA); 220 + else 221 + trace_seq_putc(s, '"'); 211 222 } 212 223 213 224 trace_seq_putc(s, ')');