[lkml]   [2017]   [Dec]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH 4/5] tracing: Fix crash when it fails to alloc ring buffer
From: Jing Xia <>

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,

|-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

// out_free_tr

//if trace_buffer is not null, free again
// ring_buffer_per_cpu is null, and
// crash in ring_buffer_per_cpu->pages


Fixes: 737223fbca3b1 ("tracing: Consolidate buffer allocation code")
Signed-off-by: Jing Xia <>
Signed-off-by: Chunyan Zhang <>
Signed-off-by: Steven Rostedt (VMware) <>
kernel/trace/trace.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 73652d5318b2..0e53d46544b8 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -7603,7 +7603,9 @@ static int allocate_trace_buffers(struct trace_array *tr, int size)
allocate_snapshot ? size : 1);
if (WARN_ON(ret)) {
+ tr->trace_buffer.buffer = NULL;
+ tr-> = NULL;
return -ENOMEM;
tr->allocated_snapshot = allocate_snapshot;

 \ /
  Last update: 2017-12-27 20:36    [W:0.033 / U:14.204 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site