linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	alan@lxorguk.ukuu.org.uk, Steven Rostedt <rostedt@goodmis.org>
Subject: [ 22/27] ring-buffer: Fix race between integrity check and readers
Date: Fri, 14 Dec 2012 15:01:35 -0800	[thread overview]
Message-ID: <20121214222256.119472251@linuxfoundation.org> (raw)
In-Reply-To: <20121214222251.229078963@linuxfoundation.org>

3.7-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Steven Rostedt <srostedt@redhat.com>

commit 9366c1ba13fbc41bdb57702e75ca4382f209c82f upstream.

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.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 kernel/trace/ring_buffer.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -3783,12 +3783,17 @@ void
 ring_buffer_read_finish(struct ring_buffer_iter *iter)
 {
 	struct ring_buffer_per_cpu *cpu_buffer = iter->cpu_buffer;
+	unsigned long flags;
 
 	/*
 	 * Ring buffer is disabled from recording, here's a good place
-	 * to check the integrity of the ring buffer. 
+	 * to check the integrity of the ring buffer.
+	 * Must prevent readers from trying to read, as the check
+	 * clears the HEAD page and readers require it.
 	 */
+	raw_spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
 	rb_check_pages(cpu_buffer);
+	raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
 
 	atomic_dec(&cpu_buffer->record_disabled);
 	atomic_dec(&cpu_buffer->buffer->resize_disabled);



  parent reply	other threads:[~2012-12-14 23:08 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-14 23:01 [ 00/27] 3.7.1-stable review Greg Kroah-Hartman
2012-12-14 23:01 ` [ 01/27] mm: dmapool: use provided gfp flags for all dma_alloc_coherent() calls Greg Kroah-Hartman
2012-12-14 23:01 ` [ 02/27] clk: ux500: fix bit error Greg Kroah-Hartman
2012-12-14 23:01 ` [ 03/27] x86,AMD: Power driver support for AMDs family 16h processors Greg Kroah-Hartman
2012-12-14 23:01 ` [ 04/27] telephony: ijx: buffer overflow in ixj_write_cid() Greg Kroah-Hartman
2012-12-14 23:01 ` [ 05/27] ezusb: add dependency to USB Greg Kroah-Hartman
2012-12-14 23:01 ` [ 06/27] x86: hpet: Fix masking of MSI interrupts Greg Kroah-Hartman
2012-12-14 23:01 ` [ 07/27] USB: add new zte 3g-dongles pid to option.c Greg Kroah-Hartman
2012-12-14 23:01 ` [ 08/27] USB: option: blacklist network interface on Huawei E173 Greg Kroah-Hartman
2012-12-14 23:01 ` [ 09/27] USB: ftdi_sio: Add support for Newport AGILIS motor drivers Greg Kroah-Hartman
2012-12-14 23:01 ` [ 10/27] usb: ftdi_sio: fixup BeagleBone A5+ quirk Greg Kroah-Hartman
2012-12-14 23:01 ` [ 11/27] USB: cp210x: add Virtenio Preon32 device id Greg Kroah-Hartman
2012-12-14 23:01 ` [ 12/27] USB: mark uas driver as BROKEN Greg Kroah-Hartman
2012-12-14 23:01 ` [ 13/27] ACPI / battery: Correct battery capacity values on Thinkpads Greg Kroah-Hartman
2012-12-14 23:01 ` [ 14/27] ACPI / PM: Add Sony Vaio VPCEB1S1E to nonvs blacklist Greg Kroah-Hartman
2012-12-14 23:01 ` [ 15/27] ACPI / PNP: Do not crash due to stale pointer use during system resume Greg Kroah-Hartman
2012-12-14 23:01 ` [ 16/27] ACPI / video: ignore BIOS initial backlight value for HP Folio 13-2000 Greg Kroah-Hartman
2012-12-14 23:01 ` [ 17/27] ACPI / video: Add "Asus UL30VT" to ACPI video detect blacklist Greg Kroah-Hartman
2012-12-14 23:01 ` [ 18/27] USB: OHCI: workaround for hardware bug: retired TDs not added to the Done Queue Greg Kroah-Hartman
2012-12-14 23:01 ` [ 19/27] xhci: Extend Fresco Logic MSI quirk Greg Kroah-Hartman
2012-12-14 23:01 ` [ 20/27] ftrace: Clear bits properly in reset_iter_read() Greg Kroah-Hartman
2012-12-14 23:01 ` [ 21/27] ring-buffer: Fix NULL pointer if rb_set_head_page() fails Greg Kroah-Hartman
2012-12-14 23:01 ` Greg Kroah-Hartman [this message]
2012-12-14 23:01 ` [ 23/27] cdc-acm: implement TIOCSSERIAL to avoid blocking close(2) Greg Kroah-Hartman
2012-12-14 23:01 ` [ 24/27] perf test: fix a build error on builtin-test Greg Kroah-Hartman
2012-12-14 23:01 ` [ 25/27] USB: EHCI: bugfix: urb->hcpriv should not be NULL Greg Kroah-Hartman
2012-12-14 23:01 ` [ 26/27] rcu: Fix batch-limit size problem Greg Kroah-Hartman
2012-12-14 23:01 ` [ 27/27] Staging: bcm: Add two products and remove an existing product Greg Kroah-Hartman
2012-12-15 14:22 ` [ 00/27] 3.7.1-stable review Shuah Khan
2012-12-15 20:47   ` Shuah Khan
2012-12-15 14:53 ` Satoru Takeuchi
2012-12-16 19:52 ` Nikola Ciprich
2012-12-17 22:07 ` Mariusz Kozlowski
2012-12-17 22:14   ` Greg Kroah-Hartman
2012-12-17 22:38     ` Mariusz Kozlowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121214222256.119472251@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).