diff options
author | Steven Rostedt <srostedt@redhat.com> | 2009-03-16 19:20:15 -0400 |
---|---|---|
committer | Steven Rostedt <srostedt@redhat.com> | 2009-03-16 23:27:06 -0400 |
commit | 4ca530852346be239b7c19e7bec5d2b78855bebe (patch) | |
tree | 96e5252faaf362115a96ed6df7c4e4f698a027dc /kernel/trace/trace.c | |
parent | 03303549b1695dc024d4a653cc16bd79f78f9750 (diff) |
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.c | 20 |
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) | |||
770 | __raw_spin_unlock(&trace_cmdline_lock); | 770 | __raw_spin_unlock(&trace_cmdline_lock); |
771 | } | 771 | } |
772 | 772 | ||
773 | char *trace_find_cmdline(int pid) | 773 | void trace_find_cmdline(int pid, char comm[]) |
774 | { | 774 | { |
775 | char *cmdline = "<...>"; | ||
776 | unsigned map; | 775 | unsigned map; |
777 | 776 | ||
778 | if (!pid) | 777 | if (!pid) { |
779 | return "<idle>"; | 778 | strcpy(comm, "<idle>"); |
779 | return; | ||
780 | } | ||
780 | 781 | ||
781 | if (pid > PID_MAX_DEFAULT) | 782 | if (pid > PID_MAX_DEFAULT) { |
782 | goto out; | 783 | strcpy(comm, "<...>"); |
784 | return; | ||
785 | } | ||
783 | 786 | ||
787 | __raw_spin_lock(&trace_cmdline_lock); | ||
784 | map = map_pid_to_cmdline[pid]; | 788 | map = map_pid_to_cmdline[pid]; |
785 | if (map >= SAVED_CMDLINES) | 789 | if (map >= SAVED_CMDLINES) |
786 | goto out; | 790 | goto out; |
787 | 791 | ||
788 | cmdline = saved_cmdlines[map]; | 792 | strcpy(comm, saved_cmdlines[map]); |
789 | 793 | ||
790 | out: | 794 | out: |
791 | return cmdline; | 795 | __raw_spin_unlock(&trace_cmdline_lock); |
792 | } | 796 | } |
793 | 797 | ||
794 | void tracing_record_cmdline(struct task_struct *tsk) | 798 | void tracing_record_cmdline(struct task_struct *tsk) |