From: Amit Shah <amit.shah@redhat.com>
To: Virtualization List <virtualization@lists.linux-foundation.org>
Cc: Amit Shah <amit.shah@redhat.com>, stable@vger.kernel.org
Subject: [PATCH v2 02/11] virtio: console: fix race in port_fops_open() and port unplug
Date: Fri, 19 Jul 2013 16:51:55 +0530 [thread overview]
Message-ID: <18b14516fa1badb08dbfc3e892080b27127ff00f.1374232738.git.amit.shah@redhat.com> (raw)
In-Reply-To: <cover.1374232738.git.amit.shah@redhat.com>
In-Reply-To: <cover.1374232738.git.amit.shah@redhat.com>
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 race condition.
CC: <stable@vger.kernel.org>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
drivers/char/virtio_console.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 291f437..b04ec95 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -1024,6 +1024,10 @@ static int port_fops_open(struct inode *inode, struct file *filp)
/* We get the port with a kref here */
port = find_port_by_devt(cdev->dev);
+ if (!port) {
+ /* Port was unplugged before we could proceed */
+ return -ENXIO;
+ }
filp->private_data = port;
/*
--
1.8.1.4
next prev parent reply other threads:[~2013-07-19 11:21 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-19 11:21 [PATCH v2 00/11] virtio: console: fixes for port unplug Amit Shah
2013-07-19 11:21 ` [PATCH v2 01/11] virtio: console: fix race with port unplug and open/close Amit Shah
2013-07-19 11:21 ` Amit Shah [this message]
2013-07-19 11:21 ` [PATCH v2 03/11] virtio: console: clean up port data immediately at time of unplug Amit Shah
2013-07-19 11:21 ` [PATCH v2 04/11] virtio: console: return -ENODEV on all read operations after unplug Amit Shah
2013-07-19 11:21 ` [PATCH v2 05/11] virtio: console: update private_data in struct file only on successful open Amit Shah
2013-07-19 11:21 ` [PATCH v2 06/11] virtio: console: fix race in port_fops_poll() and port unplug Amit Shah
2013-07-19 11:22 ` [PATCH v2 07/11] virtio: console: fix raising SIGIO after " Amit Shah
2013-07-19 11:22 ` [PATCH v2 08/11] virtio: console: add locks around buffer removal in port unplug path Amit Shah
2013-07-19 11:22 ` [PATCH v2 09/11] virtio: console: add locking " Amit Shah
2013-07-19 11:22 ` [PATCH v2 10/11] virtio: console: fix locking around send_sigio_to_port() Amit Shah
2013-07-19 11:22 ` [PATCH v2 11/11] virtio: console: prevent use-after-free of port name in port unplug Amit Shah
2013-07-22 6:30 ` [PATCH v2 00/11] virtio: console: fixes for " Jason Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=18b14516fa1badb08dbfc3e892080b27127ff00f.1374232738.git.amit.shah@redhat.com \
--to=amit.shah@redhat.com \
--cc=stable@vger.kernel.org \
--cc=virtualization@lists.linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).