summaryrefslogtreecommitdiffstats
path: root/kernel/trace/trace.c
diff options
context:
space:
mode:
authorSteven Rostedt2009-03-17 00:20:15 +0100
committerSteven Rostedt2009-03-17 04:27:06 +0100
commit4ca530852346be239b7c19e7bec5d2b78855bebe (patch)
tree96e5252faaf362115a96ed6df7c4e4f698a027dc /kernel/trace/trace.c
parenttracing/ftrace: fix the check on nopped sites (diff)
downloadkernel-qcow2-linux-4ca530852346be239b7c19e7bec5d2b78855bebe.tar.gz
kernel-qcow2-linux-4ca530852346be239b7c19e7bec5d2b78855bebe.tar.xz
kernel-qcow2-linux-4ca530852346be239b7c19e7bec5d2b78855bebe.zip
tracing: protect reader of cmdline output
Impact: fix to one cause of incorrect comm outputs in trace The spinlock only protected the creation of a comm <=> pid pair. But it was possible that a reader could look up a pid, and get the wrong comm because it had no locking. This also required changing trace_find_cmdline to copy the comm cache and not just send back a pointer to it. Signed-off-by: Steven Rostedt <srostedt@redhat.com>
Diffstat (limited to 'kernel/trace/trace.c')
-rw-r--r--kernel/trace/trace.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index efe3202c0209..2796bd2b17e4 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -770,25 +770,29 @@ static void trace_save_cmdline(struct task_struct *tsk)
__raw_spin_unlock(&trace_cmdline_lock);
}
-char *trace_find_cmdline(int pid)
+void trace_find_cmdline(int pid, char comm[])
{
- char *cmdline = "<...>";
unsigned map;
- if (!pid)
- return "<idle>";
+ if (!pid) {
+ strcpy(comm, "<idle>");
+ return;
+ }
- if (pid > PID_MAX_DEFAULT)
- goto out;
+ if (pid > PID_MAX_DEFAULT) {
+ strcpy(comm, "<...>");
+ return;
+ }
+ __raw_spin_lock(&trace_cmdline_lock);
map = map_pid_to_cmdline[pid];
if (map >= SAVED_CMDLINES)
goto out;
- cmdline = saved_cmdlines[map];
+ strcpy(comm, saved_cmdlines[map]);
out:
- return cmdline;
+ __raw_spin_unlock(&trace_cmdline_lock);
}
void tracing_record_cmdline(struct task_struct *tsk)