Patchwork [180/270] ring-buffer: Check for uninitialized cpu buffer before resizing

mail settings
Submitter Herton Ronaldo Krzesinski
Date Nov. 26, 2012, 4:57 p.m.
Message ID <>
Download mbox | patch
Permalink /patch/201912/
State New
Headers show


Herton Ronaldo Krzesinski - Nov. 26, 2012, 4:57 p.m.
3.5.7u1 -stable review patch.  If anyone has any objections, please let me know.


From: Vaibhav Nagarnaik <>

commit 8e49f418c9632790bf456634742d34d97120a784 upstream.

With a system where, num_present_cpus < num_possible_cpus, even if all
CPUs are online, non-present CPUs don't have per_cpu buffers allocated.
If per_cpu/<cpu>/buffer_size_kb is modified for such a CPU, it can cause
a panic due to NULL dereference in ring_buffer_resize().

To fix this, resize operation is allowed only if the per-cpu buffer has
been initialized.


Signed-off-by: Vaibhav Nagarnaik <>
Signed-off-by: Steven Rostedt <>
Signed-off-by: Herton Ronaldo Krzesinski <>
 kernel/trace/ring_buffer.c |    4 ++++
 1 file changed, 4 insertions(+)


diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index f765465..db6dff1 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -1567,6 +1567,10 @@  int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size,
 	} else {
+		/* Make sure this CPU has been intitialized */
+		if (!cpumask_test_cpu(cpu_id, buffer->cpumask))
+			goto out;
 		cpu_buffer = buffer->buffers[cpu_id];
 		if (nr_pages == cpu_buffer->nr_pages)