Skip to content

Commit f74bb74

Browse files
rostedtgregkh
authored andcommitted
tracing: Check if tracing is enabled in trace_puts()
commit 3132e10 upstream. 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. Fixes: 09ae723 "tracing: Add trace_puts() for even faster trace_printk() tracing" Signed-off-by: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent fb23eaf commit f74bb74

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎kernel/trace/trace.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,9 @@ int __trace_puts(unsigned long ip, const char *str, int size)
424424
unsigned long irq_flags;
425425
int alloc;
426426

427+
if (unlikely(tracing_selftest_running || tracing_disabled))
428+
return 0;
429+
427430
alloc = sizeof(*entry) + size + 2; /* possible \n added */
428431

429432
local_save_flags(irq_flags);
@@ -464,6 +467,9 @@ int __trace_bputs(unsigned long ip, const char *str)
464467
unsigned long irq_flags;
465468
int size = sizeof(struct bputs_entry);
466469

470+
if (unlikely(tracing_selftest_running || tracing_disabled))
471+
return 0;
472+
467473
local_save_flags(irq_flags);
468474
buffer = global_trace.trace_buffer.buffer;
469475
event = trace_buffer_lock_reserve(buffer, TRACE_BPUTS, size,

0 commit comments

Comments
 (0)