aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/trace/ring_buffer.c
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2012-11-29 22:31:16 -0500
committerSteven Rostedt <rostedt@goodmis.org>2012-11-30 11:09:57 -0500
commit9366c1ba13fbc41bdb57702e75ca4382f209c82f (patch)
treef01489b009aedbba4de63cb37412c64aa4d8c1b3 /kernel/trace/ring_buffer.c
parent54f7be5b831254199522523ccab4c3d954bbf576 (diff)
ring-buffer: Fix race between integrity check and readers
The function rb_check_pages() was added to make sure the ring buffer's pages were sane. This check is done when the ring buffer size is modified as well as when the iterator is released (closing the "trace" file), as that was considered a non fast path and a good place to do a sanity check. The problem is that the check does not have any locks around it. If one process were to read the trace file, and another were to read the raw binary file, the check could happen while the reader is reading the file. The issues with this is that the check requires to clear the HEAD page before doing the full check and it restores it afterward. But readers require the HEAD page to exist before it can read the buffer, otherwise it gives a nasty warning and disables the buffer. By adding the reader lock around the check, this keeps the race from happening. Cc: stable@vger.kernel.org # 3.6 Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'kernel/trace/ring_buffer.c')
-rw-r--r--kernel/trace/ring_buffer.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index ec01803e0a55..4cb5e5147165 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -3783,12 +3783,17 @@ void
3783ring_buffer_read_finish(struct ring_buffer_iter *iter) 3783ring_buffer_read_finish(struct ring_buffer_iter *iter)
3784{ 3784{
3785 struct ring_buffer_per_cpu *cpu_buffer = iter->cpu_buffer; 3785 struct ring_buffer_per_cpu *cpu_buffer = iter->cpu_buffer;
3786 unsigned long flags;
3786 3787
3787 /* 3788 /*
3788 * Ring buffer is disabled from recording, here's a good place 3789 * Ring buffer is disabled from recording, here's a good place
3789 * to check the integrity of the ring buffer. 3790 * to check the integrity of the ring buffer.
3791 * Must prevent readers from trying to read, as the check
3792 * clears the HEAD page and readers require it.
3790 */ 3793 */
3794 raw_spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
3791 rb_check_pages(cpu_buffer); 3795 rb_check_pages(cpu_buffer);
3796 raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
3792 3797
3793 atomic_dec(&cpu_buffer->record_disabled); 3798 atomic_dec(&cpu_buffer->record_disabled);
3794 atomic_dec(&cpu_buffer->buffer->resize_disabled); 3799 atomic_dec(&cpu_buffer->buffer->resize_disabled);