Commit 5604fdcf authored by Pavel Tikhomirov's avatar Pavel Tikhomirov Committed by Greg Kroah-Hartman

vhost: return EINVAL if iovecs size does not match the message size

[ Upstream commit 74ad7419 ]

We've failed to copy and process vhost_iotlb_msg so let userspace at
least know about it. For instance before these patch the code below runs
without any error:

int main()
{
  struct vhost_msg msg;
  struct iovec iov;
  int fd;

  fd = open("/dev/vhost-net", O_RDWR);
  if (fd == -1) {
    perror("open");
    return 1;
  }

  iov.iov_base = &msg;
  iov.iov_len = sizeof(msg)-4;

  if (writev(fd, &iov,1) == -1) {
    perror("writev");
    return 1;
  }

  return 0;
}
Signed-off-by: default avatarPavel Tikhomirov <ptikhomirov@virtuozzo.com>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 096a3170
...@@ -1035,8 +1035,10 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev, ...@@ -1035,8 +1035,10 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev,
int type, ret; int type, ret;
ret = copy_from_iter(&type, sizeof(type), from); ret = copy_from_iter(&type, sizeof(type), from);
if (ret != sizeof(type)) if (ret != sizeof(type)) {
ret = -EINVAL;
goto done; goto done;
}
switch (type) { switch (type) {
case VHOST_IOTLB_MSG: case VHOST_IOTLB_MSG:
...@@ -1055,8 +1057,10 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev, ...@@ -1055,8 +1057,10 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev,
iov_iter_advance(from, offset); iov_iter_advance(from, offset);
ret = copy_from_iter(&msg, sizeof(msg), from); ret = copy_from_iter(&msg, sizeof(msg), from);
if (ret != sizeof(msg)) if (ret != sizeof(msg)) {
ret = -EINVAL;
goto done; goto done;
}
if (vhost_process_iotlb_msg(dev, &msg)) { if (vhost_process_iotlb_msg(dev, &msg)) {
ret = -EFAULT; ret = -EFAULT;
goto done; goto done;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment