Skip to content

Commit 6c17607

Browse files
amit3sgregkh
authored andcommitted
virtio: console: fix race in port_fops_open() and port unplug
commit 671bdea upstream. Between open() being called and processed, the port can be unplugged. Check if this happened, and bail out. A simple test script to reproduce this is: while true; do for i in $(seq 1 100); do echo $i > /dev/vport0p3; done; done; This opens and closes the port a lot of times; unplugging the port while this is happening triggers the bug. 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>
1 parent e3a5a43 commit 6c17607

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/char/virtio_console.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,10 @@ static int port_fops_open(struct inode *inode, struct file *filp)
786786

787787
/* We get the port with a kref here */
788788
port = find_port_by_devt(cdev->dev);
789+
if (!port) {
790+
/* Port was unplugged before we could proceed */
791+
return -ENXIO;
792+
}
789793
filp->private_data = port;
790794

791795
/*

0 commit comments

Comments
 (0)