]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
vhost: return EINVAL if iovecs size does not match the message size
authorPavel Tikhomirov <ptikhomirov@virtuozzo.com>
Thu, 13 Dec 2018 14:53:50 +0000 (17:53 +0300)
committerMichael S. Tsirkin <mst@redhat.com>
Tue, 15 Jan 2019 01:28:07 +0000 (20:28 -0500)
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: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
drivers/vhost/vhost.c

index 9f7942cbcbb22a9f09eb0dd4d052b8d0c562004d..bac939af8dbb149e4998f18a35f80a12455a52f9 100644 (file)
@@ -1034,8 +1034,10 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev,
        int type, ret;
 
        ret = copy_from_iter(&type, sizeof(type), from);
-       if (ret != sizeof(type))
+       if (ret != sizeof(type)) {
+               ret = -EINVAL;
                goto done;
+       }
 
        switch (type) {
        case VHOST_IOTLB_MSG:
@@ -1054,8 +1056,10 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev,
 
        iov_iter_advance(from, offset);
        ret = copy_from_iter(&msg, sizeof(msg), from);
-       if (ret != sizeof(msg))
+       if (ret != sizeof(msg)) {
+               ret = -EINVAL;
                goto done;
+       }
        if (vhost_process_iotlb_msg(dev, &msg)) {
                ret = -EFAULT;
                goto done;