aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/vhost/vhost.c
diff options
context:
space:
mode:
authorPavel Tikhomirov <ptikhomirov@virtuozzo.com>2018-12-13 09:53:50 -0500
committerMichael S. Tsirkin <mst@redhat.com>2019-01-14 20:28:07 -0500
commit74ad7419489ddade8044e3c9ab064ad656520306 (patch)
tree6cb0e71ecb649c2b8061d85550d0c84098162e94 /drivers/vhost/vhost.c
parentbf4dc0b2beebfd9338df7c0bcf473b356f67cf66 (diff)
vhost: return EINVAL if iovecs size does not match the message size
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>
Diffstat (limited to 'drivers/vhost/vhost.c')
-rw-r--r--drivers/vhost/vhost.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 9f7942cbcbb2..bac939af8dbb 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -1034,8 +1034,10 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev,
1034 int type, ret; 1034 int type, ret;
1035 1035
1036 ret = copy_from_iter(&type, sizeof(type), from); 1036 ret = copy_from_iter(&type, sizeof(type), from);
1037 if (ret != sizeof(type)) 1037 if (ret != sizeof(type)) {
1038 ret = -EINVAL;
1038 goto done; 1039 goto done;
1040 }
1039 1041
1040 switch (type) { 1042 switch (type) {
1041 case VHOST_IOTLB_MSG: 1043 case VHOST_IOTLB_MSG:
@@ -1054,8 +1056,10 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev,
1054 1056
1055 iov_iter_advance(from, offset); 1057 iov_iter_advance(from, offset);
1056 ret = copy_from_iter(&msg, sizeof(msg), from); 1058 ret = copy_from_iter(&msg, sizeof(msg), from);
1057 if (ret != sizeof(msg)) 1059 if (ret != sizeof(msg)) {
1060 ret = -EINVAL;
1058 goto done; 1061 goto done;
1062 }
1059 if (vhost_process_iotlb_msg(dev, &msg)) { 1063 if (vhost_process_iotlb_msg(dev, &msg)) {
1060 ret = -EFAULT; 1064 ret = -EFAULT;
1061 goto done; 1065 goto done;