This is a note to let you know that I've just added the patch titled
virtio: console: fix race with port unplug and open/close
to the 3.10-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
virtio-console-fix-race-with-port-unplug-and-open-close.patch
and it can be found in the queue-3.10 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree,
please let <[email protected]> know about it.
>From 057b82be3ca3d066478e43b162fc082930a746c9 Mon Sep 17 00:00:00 2001
From: Amit Shah <[email protected]>
Date: Mon, 29 Jul 2013 14:16:13 +0930
Subject: virtio: console: fix race with port unplug and open/close
From: Amit Shah <[email protected]>
commit 057b82be3ca3d066478e43b162fc082930a746c9 upstream.
There's a window between find_port_by_devt() returning a port and us
taking a kref on the port, where the port could get unplugged. Fix it
by taking the reference in find_port_by_devt() itself.
Problem reported and analyzed by Mateusz Guzik.
Reported-by: Mateusz Guzik <[email protected]>
Signed-off-by: Amit Shah <[email protected]>
Signed-off-by: Rusty Russell <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/char/virtio_console.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -272,9 +272,12 @@ static struct port *find_port_by_devt_in
unsigned long flags;
spin_lock_irqsave(&portdev->ports_lock, flags);
- list_for_each_entry(port, &portdev->ports, list)
- if (port->cdev->dev == dev)
+ list_for_each_entry(port, &portdev->ports, list) {
+ if (port->cdev->dev == dev) {
+ kref_get(&port->kref);
goto out;
+ }
+ }
port = NULL;
out:
spin_unlock_irqrestore(&portdev->ports_lock, flags);
@@ -1036,14 +1039,10 @@ static int port_fops_open(struct inode *
struct port *port;
int ret;
+ /* We get the port with a kref here */
port = find_port_by_devt(cdev->dev);
filp->private_data = port;
- /* Prevent against a port getting hot-unplugged at the same time */
- spin_lock_irq(&port->portdev->ports_lock);
- kref_get(&port->kref);
- spin_unlock_irq(&port->portdev->ports_lock);
-
/*
* Don't allow opening of console port devices -- that's done
* via /dev/hvc
Patches currently in stable-queue which might be from [email protected] are
queue-3.10/virtio-console-fix-raising-sigio-after-port-unplug.patch
queue-3.10/virtio-console-clean-up-port-data-immediately-at-time-of-unplug.patch
queue-3.10/virtio-console-quit-from-splice_write-if-pipe-nrbufs-is-0.patch
queue-3.10/virtio-console-fix-race-in-port_fops_open-and-port-unplug.patch
queue-3.10/virtio-console-add-pipe_lock-unlock-for-splice_write.patch
queue-3.10/virtio-console-return-enodev-on-all-read-operations-after-unplug.patch
queue-3.10/virtio-console-fix-race-with-port-unplug-and-open-close.patch
--
To unsubscribe from this list: send the line "unsubscribe stable" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html