Linux virtualization list
 help / color / mirror / Atom feed
* [PATCH] virtio: console: Don't access vqs if device was unplugged
@ 2011-03-04  3:34 Rusty Russell
  0 siblings, 0 replies; only message in thread
From: Rusty Russell @ 2011-03-04  3:34 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Amit Shah, virtualization

From: Amit Shah <amit.shah@redhat.com>

If a virtio-console device gets unplugged while a port is open, a
subsequent close() call on the port accesses vqs to free up buffers.
This can lead to a crash.

The buffers are already freed up as a result of the call to
unplug_ports() from virtcons_remove().  The fix is to simply not access
vq information if port->portdev is NULL.

Reported-by: juzhang <juzhang@redhat.com>
CC: stable@kernel.org
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 drivers/char/virtio_console.c |    8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 4903931..84b164d 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -388,6 +388,10 @@ static void discard_port_data(struct port *port)
 	unsigned int len;
 	int ret;
 
+	if (!port->portdev) {
+		/* Device has been unplugged.  vqs are already gone. */
+		return;
+	}
 	vq = port->in_vq;
 	if (port->inbuf)
 		buf = port->inbuf;
@@ -470,6 +474,10 @@ static void reclaim_consumed_buffers(struct port *port)
 	void *buf;
 	unsigned int len;
 
+	if (!port->portdev) {
+		/* Device has been unplugged.  vqs are already gone. */
+		return;
+	}
 	while ((buf = virtqueue_get_buf(port->out_vq, &len))) {
 		kfree(buf);
 		port->outvq_full = false;

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2011-03-04  3:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-04  3:34 [PATCH] virtio: console: Don't access vqs if device was unplugged Rusty Russell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox