]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
tracing: Have type enum modifications copy the strings
authorSteven Rostedt (Google) <rostedt@goodmis.org>
Fri, 18 Mar 2022 19:34:32 +0000 (15:34 -0400)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 20 May 2022 12:40:20 +0000 (14:40 +0200)
commit6c2b55a15d2b8eb81f4b210c7065508f2d421c24
treec2a0a4c5efde709210f87b96b1a60dc836a0e488
parent244563bf2af8d2e73840e334e407c768058bcb0c
tracing: Have type enum modifications copy the strings

BugLink: https://bugs.launchpad.net/bugs/1969110
commit 795301d3c28996219d555023ac6863401b6076bc upstream.

When an enum is used in the visible parts of a trace event that is
exported to user space, the user space applications like perf and
trace-cmd do not have a way to know what the value of the enum is. To
solve this, at boot up (or module load) the printk formats are modified to
replace the enum with their numeric value in the string output.

Array fields of the event are defined by [<nr-elements>] in the type
portion of the format file so that the user space parsers can correctly
parse the array into the appropriate size chunks. But in some trace
events, an enum is used in defining the size of the array, which once
again breaks the parsing of user space tooling.

This was solved the same way as the print formats were, but it modified
the type strings of the trace event. This caused crashes in some
architectures because, as supposed to the print string, is a const string
value. This was not detected on x86, as it appears that const strings are
still writable (at least in boot up), but other architectures this is not
the case, and writing to a const string will cause a kernel fault.

To fix this, use kstrdup() to copy the type before modifying it. If the
trace event is for the core kernel there's no need to free it because the
string will be in use for the life of the machine being on line. For
modules, create a link list to store all the strings being allocated for
modules and when the module is removed, free them.

Link: https://lore.kernel.org/all/yt9dr1706b4i.fsf@linux.ibm.com/
Link: https://lkml.kernel.org/r/20220318153432.3984b871@gandalf.local.home
Tested-by: Marc Zyngier <maz@kernel.org>
Tested-by: Sven Schnelle <svens@linux.ibm.com>
Reported-by: Sven Schnelle <svens@linux.ibm.com>
Fixes: b3bc8547d3be ("tracing: Have TRACE_DEFINE_ENUM affect trace event types as well")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 14d552ab31ede4027e8a7d2eb3dd7670e2bdc007)
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
kernel/trace/trace_events.c