[26/80] virtio: console: Prevent userspace from submitting NULL buffers

Greg KH
2010-09-24T16:28:16Z

From: Amit Shah <amit.shah@redhat.com>

commit 65745422a898741ee0e7068ef06624ab06e8aefa upstream.

A userspace could submit a buffer with 0 length to be written to the
host. Prevent such a situation.

This was not needed previously, but recent changes in the way write()
works exposed this condition to trigger a virtqueue event to the host,
causing a NULL buffer to be sent across.

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@suse.de>

---
drivers/char/virtio_console.c | 4 ++++
1 file changed, 4 insertions(+)

--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -596,6 +596,10 @@ static ssize_t port_fops_write(struct fi
ssize_t ret;
bool nonblock;

+ /* Userspace could be out to fool us */
+ if (!count)
+ return 0;
+
port = filp->private_data;

nonblock = filp->f_flags & O_NONBLOCK;