Skip to content

Commit

Permalink
tracing: Check if tracing is enabled in trace_puts()
Browse files Browse the repository at this point in the history
If trace_puts() is used very early in boot up, it can crash the machine
if it is called before the ring buffer is allocated. If a trace_printk()
is used with no arguments, then it will be converted into a trace_puts()
and suffer the same fate.

Cc: stable@vger.kernel.org # 3.10+
Fixes: 09ae723 "tracing: Add trace_puts() for even faster trace_printk() tracing"
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
  • Loading branch information
rostedt committed Jan 23, 2014
1 parent 71485c4 commit 3132e10
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,9 @@ int __trace_puts(unsigned long ip, const char *str, int size)
unsigned long irq_flags;
int alloc;

if (unlikely(tracing_selftest_running || tracing_disabled))
return 0;

alloc = sizeof(*entry) + size + 2; /* possible \n added */

local_save_flags(irq_flags);
Expand Down Expand Up @@ -495,6 +498,9 @@ int __trace_bputs(unsigned long ip, const char *str)
unsigned long irq_flags;
int size = sizeof(struct bputs_entry);

if (unlikely(tracing_selftest_running || tracing_disabled))
return 0;

local_save_flags(irq_flags);
buffer = global_trace.trace_buffer.buffer;
event = trace_buffer_lock_reserve(buffer, TRACE_BPUTS, size,
Expand Down

0 comments on commit 3132e10

Please sign in to comment.