[lkml]   [2018]   [Jan]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH 4.9 04/75] tracing: Fix crash when it fails to alloc ring buffer
4.9-stable review patch.  If anyone has any objections, please let me know.


From: Jing Xia <>

commit 24f2aaf952ee0b59f31c3a18b8b36c9e3d3c2cf5 upstream.

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) <>
Signed-off-by: Greg Kroah-Hartman <>

kernel/trace/trace.c | 2 ++
1 file changed, 2 insertions(+)

--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -6979,7 +6979,9 @@ static int allocate_trace_buffers(struct
allocate_snapshot ? size : 1);
if (WARN_ON(ret)) {
+ tr->trace_buffer.buffer = NULL;
+ tr-> = NULL;
return -ENOMEM;
tr->allocated_snapshot = allocate_snapshot;

 \ /
  Last update: 2018-01-01 16:21    [W:0.198 / U:7.620 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site