tracing: Add ptr-hash option to show the hashed pointer value
authorMasami Hiramatsu <mhiramat@kernel.org>
Thu, 15 Oct 2020 14:55:25 +0000 (23:55 +0900)
committerSteven Rostedt (VMware) <rostedt@goodmis.org>
Thu, 11 Feb 2021 21:31:57 +0000 (16:31 -0500)
Add tracefs/options/hash-ptr option to show hashed pointer
value by %p in event printk format string.

For the security reason, normal printk will show the hashed
pointer value (encrypted by random number) with %p to printk
buffer to hide the real address. But the tracefs/trace always
shows real address for debug. To bridge those outputs, add an
option to switch the output format. Ftrace users can use it
to find the hashed value corresponding to the real address
in trace log.

Link: https://lkml.kernel.org/r/160277372504.29307.14909828808982012211.stgit@devnote2
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Documentation/trace/ftrace.rst
kernel/trace/trace.c
kernel/trace/trace.h

index 87cf5c010d5dda9f54d80d2f4da2eb26762d4e1b..62c98e9bbdd9d86e9141c12b6f86082e5e1a7ab6 100644 (file)
@@ -1159,6 +1159,12 @@ Here are the available options:
        This simulates the original behavior of the trace file.
        When the file is closed, tracing will be enabled again.
 
+  hash-ptr
+        When set, "%p" in the event printk format displays the
+        hashed pointer value instead of real address.
+        This will be useful if you want to find out which hashed
+        value is corresponding to the real value in trace log.
+
   record-cmd
        When any event or tracer is enabled, a hook is enabled
        in the sched_switch trace point to fill comm cache
index 39f8a537196ed65379cd9604a55eec3cf5ece258..16e252d39016954c15355e774355efcb03b0b14d 100644 (file)
@@ -3558,6 +3558,9 @@ const char *trace_event_format(struct trace_iterator *iter, const char *fmt)
        if (WARN_ON_ONCE(!fmt))
                return fmt;
 
+       if (iter->tr->trace_flags & TRACE_ITER_HASH_PTR)
+               return fmt;
+
        p = fmt;
        new_fmt = q = iter->fmt;
        while (*p) {
index 6c3ea6f95e680bb5171e520abb3bfecc3f977562..dec13ff66077e5a8dd281d5f13ac0c05842f558a 100644 (file)
@@ -1175,6 +1175,7 @@ extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
                C(MARKERS,              "markers"),             \
                C(EVENT_FORK,           "event-fork"),          \
                C(PAUSE_ON_TRACE,       "pause-on-trace"),      \
+               C(HASH_PTR,             "hash-ptr"),    /* Print hashed pointer */ \
                FUNCTION_FLAGS                                  \
                FGRAPH_FLAGS                                    \
                STACK_FLAGS                                     \