All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Greg KH <gregkh@suse.de>, Alan Cox <alan@lxorguk.ukuu.org.uk>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [PATCH] tty, serial: Fix race and NULL check in uart_close()
Date: Mon, 12 Oct 2009 19:13:54 +0200	[thread overview]
Message-ID: <20091012171354.GA6918@elte.hu> (raw)
In-Reply-To: <alpine.LFD.2.01.0910120926110.3438@localhost.localdomain>


* Linus Torvalds <torvalds@linux-foundation.org> wrote:

> On Mon, 12 Oct 2009, Linus Torvalds wrote:
> > 
> > Commit 46d57a449 (which you then bisected to) looks really irritating, 
> > since it just renamed variables in annoying ways (ie the old "port" is now 
> > "uport", and there's a new "port" that means something else). That thing 
> > should have been split up to do the renaming separately, so that a mis-use 
> > of "port" would have caused a compile error.
> > 
> > I'm not seeing anything obvious. Alan obviously found one bug already.
> 
> Ok, so I did the "do it as two commits", and when doing that (and 
> being fairly careful at all stages to do everything as no-op 
> conversions), I get this diff.
> 
> It looks like there is not just the wrong lock, but also a test for 
> NULL state got dropped by commit 46d57a449.
> 
> NOTE! This patch is against that original bad commit. The flags have since 
> been moved from 'state' to 'port', so the test for UIF_INITIALIZED is now
> 
> 	if (port->flags & UIF_INITIALIZED)
> 
> rather than
> 
> 	if (state->flags & UIF_INITIALIZED)
> 
> and you need to either edit the patch or apply it with "git apply -C1" to 
> make it apply to current git.

And UIF_INITIALIZED changed to ASYNC_INITIALIZED as well.

> Does that missing test for NULL 'state' fix your oops?

Yes it does! Find below the combo patch against your tree.

	Ingo

-------------------->

Subject: tty, serial: Fix race and NULL check in uart_close()
From: Linus Torvalds <torvalds@linux-foundation.org>

Commit 46d57a449aa1 ("serial: use tty_port pointers in the core code") 
contained two bugs that causes (rare) crashes:

 - the rename typoed one site

 - a NULL check was missed

Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index 1689bda..dcc7244 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -1270,6 +1270,9 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
 
 	BUG_ON(!kernel_locked());
 
+	if (!state)
+		return;
+
 	uport = state->uart_port;
 	port = &state->port;
 
@@ -1316,9 +1319,9 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
 	 */
 	if (port->flags & ASYNC_INITIALIZED) {
 		unsigned long flags;
-		spin_lock_irqsave(&port->lock, flags);
+		spin_lock_irqsave(&uport->lock, flags);
 		uport->ops->stop_rx(uport);
-		spin_unlock_irqrestore(&port->lock, flags);
+		spin_unlock_irqrestore(&uport->lock, flags);
 		/*
 		 * Before we drop DTR, make sure the UART transmitter
 		 * has completely drained; this is especially



  reply	other threads:[~2009-10-12 17:14 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-11 21:58 Linux 2.6.32-rc4 Linus Torvalds
2009-10-12  7:42 ` [origin tree build failure] [PATCH] Revert "USB: musb: make HAVE_CLK support optional" Ingo Molnar
2009-10-12 13:05   ` Mike Frysinger
2009-10-12 14:29     ` Greg KH
2009-10-12 14:39       ` Mike Frysinger
2009-10-12 15:00         ` Ingo Molnar
2009-10-12 15:09           ` Mike Frysinger
2009-10-12 13:49   ` [PATCH] USB: musb: invert arch depend string Mike Frysinger
2009-10-12 14:28     ` Greg KH
2009-10-12 15:02       ` Ingo Molnar
2009-10-12  8:05 ` [crash] NULL pointer dereference at IP: [<ffffffff812e9ccb>] uart_close+0x2a/0x1e4 Ingo Molnar
2009-10-12  9:19   ` Ingo Molnar
2009-10-12  9:27     ` Ingo Molnar
2009-10-12 11:25       ` Ingo Molnar
2009-10-12 11:45         ` Alan Cox
2009-10-12 11:55           ` Ingo Molnar
2009-10-12 12:22             ` Ingo Molnar
2009-10-12 13:06               ` Alan Cox
2009-10-12 14:23                 ` Ingo Molnar
2009-10-12 16:19   ` Linus Torvalds
2009-10-12 16:26     ` Ingo Molnar
2009-10-12 16:28     ` Ingo Molnar
2009-10-12 16:37     ` Linus Torvalds
2009-10-12 17:13       ` Ingo Molnar [this message]
2009-10-12  8:29 ` Linux 2.6.32-rc4 Ingo Molnar
2009-10-12  8:30   ` [origin tree build failure] [PATCH] headers: Fix build in drivers/pci/hotplug/cpqphp.h Ingo Molnar
2009-10-12  8:32   ` [origin tree build failure] [PATCH] headers: Fix build in drivers/char/rtc.c Ingo Molnar
2009-10-12  8:40   ` [origin tree build failure] [PATCH] headers: Fix build in drivers/net/wan/pci200syn.c Ingo Molnar
2009-10-12  9:11   ` [origin tree build failure] [PATCH] headers: Fix build in drivers/net/wan/n2.c Ingo Molnar
2009-10-12  9:16   ` [origin tree build failure] [PATCH] headers: Fix build in drivers/net/wan/c101.c Ingo Molnar
2009-10-12 10:06   ` [origin tree build failure] [PATCH] headers: Fix build in drivers/char/genrtc.c Ingo Molnar
2009-10-12 13:29   ` Linux 2.6.32-rc4 Alexey Dobriyan
2009-10-12  9:43     ` Ingo Molnar
2009-10-12 13:34   ` Alexey Dobriyan
2009-10-12  9:48     ` Ingo Molnar
2009-10-12 14:22   ` [origin tree build failure] [PATCH] headers: Fix build in drivers/char/sonypi.c Ingo Molnar
2009-10-12 13:01 ` Linux 2.6.32-rc4 Thomas Meyer

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=20091012171354.GA6918@elte.hu \
    --to=mingo@elte.hu \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.