Skip to content

Commit 24f2aaf

Browse files
Jing Xiarostedt
authored andcommitted
tracing: Fix crash when it fails to alloc ring buffer
Double free of the ring buffer happens when it fails to alloc new ring buffer instance for max_buffer if TRACER_MAX_TRACE is configured. The root cause is that the pointer is not set to NULL after the buffer is freed in allocate_trace_buffers(), and the freeing of the ring buffer is invoked again later if the pointer is not equal to Null, as: instance_mkdir() |-allocate_trace_buffers() |-allocate_trace_buffer(tr, &tr->trace_buffer...) |-allocate_trace_buffer(tr, &tr->max_buffer...) // allocate fail(-ENOMEM),first free // and the buffer pointer is not set to null |-ring_buffer_free(tr->trace_buffer.buffer) // out_free_tr |-free_trace_buffers() |-free_trace_buffer(&tr->trace_buffer); //if trace_buffer is not null, free again |-ring_buffer_free(buf->buffer) |-rb_free_cpu_buffer(buffer->buffers[cpu]) // ring_buffer_per_cpu is null, and // crash in ring_buffer_per_cpu->pages Link: http://lkml.kernel.org/r/[email protected] Cc: [email protected] Fixes: 737223f ("tracing: Consolidate buffer allocation code") Signed-off-by: Jing Xia <[email protected]> Signed-off-by: Chunyan Zhang <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent ae415fa commit 24f2aaf

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

kernel/trace/trace.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7603,7 +7603,9 @@ static int allocate_trace_buffers(struct trace_array *tr, int size)
76037603
allocate_snapshot ? size : 1);
76047604
if (WARN_ON(ret)) {
76057605
ring_buffer_free(tr->trace_buffer.buffer);
7606+
tr->trace_buffer.buffer = NULL;
76067607
free_percpu(tr->trace_buffer.data);
7608+
tr->trace_buffer.data = NULL;
76077609
return -ENOMEM;
76087610
}
76097611
tr->allocated_snapshot = allocate_snapshot;

0 commit comments

Comments
 (0)