瀏覽代碼

virtio: console: Prevent userspace from submitting NULL buffers

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>
CC: stable@kernel.org
Amit Shah 15 年之前
父節點
當前提交
65745422a8
共有 1 個文件被更改,包括 4 次插入0 次删除
  1. 4 0
      drivers/char/virtio_console.c

+ 4 - 0
drivers/char/virtio_console.c

@@ -596,6 +596,10 @@ static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
 	ssize_t ret;
 	ssize_t ret;
 	bool nonblock;
 	bool nonblock;
 
 
+	/* Userspace could be out to fool us */
+	if (!count)
+		return 0;
+
 	port = filp->private_data;
 	port = filp->private_data;
 
 
 	nonblock = filp->f_flags & O_NONBLOCK;
 	nonblock = filp->f_flags & O_NONBLOCK;