Skip to contentSkip to conversation

ring-buffer: Check for uninitialized cpu buffer before resizing

PATCH In review Vaibhav Nagarnaik 1 participant 2 messages Oct 10, 2012 – Oct 21, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ring-buffer: Check for uninitialized cpu buffer before resizing

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.

---
 kernel/trace/ring_buffer.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
kernel/trace/ring_buffer.c +4 -0
index b32ed0e..b979426 100644
@@ -1567,6 +1567,10 @@ int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size,
 
 		put_online_cpus();
 	} 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)
Signature · 1 line
1.7.7.3
#1 lore raw
Commit-ID:  8e49f418c9632790bf456634742d34d97120a784
Gitweb:     http://git.kernel.org/tip/8e49f418c9632790bf456634742d34d97120a784
Author:     Vaibhav Nagarnaik <[email protected]>
AuthorDate: Wed, 10 Oct 2012 16:40:27 -0700
Committer:  Steven Rostedt <[email protected]>
CommitDate: Thu, 11 Oct 2012 12:21:48 -0400

ring-buffer: Check for uninitialized cpu buffer before resizing

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.

---
 kernel/trace/ring_buffer.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
kernel/trace/ring_buffer.c +4 -0
index b32ed0e..b979426 100644
@@ -1567,6 +1567,10 @@ int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size,
 
 		put_online_cpus();
 	} 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)