virtio: console: fix race with port unplug and open/close
authorAmit Shah <amit.shah@redhat.com>
Mon, 29 Jul 2013 04:46:13 +0000 (14:16 +0930)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 15 Aug 2013 05:57:06 +0000 (22:57 -0700)
commitd0bfaacabec9c87b739c31662eaa96af0d1b404c
treeac6efba33bc2cfb70298c65f3e0154fcd0ef7935
parentb9ea0ce26ce42ee37891ede0ff6c0162005d53cb
virtio: console: fix race with port unplug and open/close

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 <mguzik@redhat.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/char/virtio_console.c