提交 d7a62cd0 编写于 作者: A Amit Shah 提交者: Linus Torvalds

virtio: console: Don't access vqs if device was unplugged

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: Njuzhang <juzhang@redhat.com>
CC: stable@kernel.org
Signed-off-by: NAmit Shah <amit.shah@redhat.com>
Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 fb62c00a
...@@ -388,6 +388,10 @@ static void discard_port_data(struct port *port) ...@@ -388,6 +388,10 @@ static void discard_port_data(struct port *port)
unsigned int len; unsigned int len;
int ret; int ret;
if (!port->portdev) {
/* Device has been unplugged. vqs are already gone. */
return;
}
vq = port->in_vq; vq = port->in_vq;
if (port->inbuf) if (port->inbuf)
buf = port->inbuf; buf = port->inbuf;
...@@ -470,6 +474,10 @@ static void reclaim_consumed_buffers(struct port *port) ...@@ -470,6 +474,10 @@ static void reclaim_consumed_buffers(struct port *port)
void *buf; void *buf;
unsigned int len; unsigned int len;
if (!port->portdev) {
/* Device has been unplugged. vqs are already gone. */
return;
}
while ((buf = virtqueue_get_buf(port->out_vq, &len))) { while ((buf = virtqueue_get_buf(port->out_vq, &len))) {
kfree(buf); kfree(buf);
port->outvq_full = false; port->outvq_full = false;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册