Commit d7a62cd0332115d4c7c4689abea0d889a30d8349

Authored by Amit Shah
Committed by Linus Torvalds
1 parent fb62c00a6d

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: 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>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 8 additions and 0 deletions Side-by-side Diff

drivers/char/virtio_console.c
... ... @@ -388,6 +388,10 @@
388 388 unsigned int len;
389 389 int ret;
390 390  
  391 + if (!port->portdev) {
  392 + /* Device has been unplugged. vqs are already gone. */
  393 + return;
  394 + }
391 395 vq = port->in_vq;
392 396 if (port->inbuf)
393 397 buf = port->inbuf;
... ... @@ -470,6 +474,10 @@
470 474 void *buf;
471 475 unsigned int len;
472 476  
  477 + if (!port->portdev) {
  478 + /* Device has been unplugged. vqs are already gone. */
  479 + return;
  480 + }
473 481 while ((buf = virtqueue_get_buf(port->out_vq, &len))) {
474 482 kfree(buf);
475 483 port->outvq_full = false;