Skip to content

Commit 5604fdc

Browse files
Snorchgregkh
authored andcommitted
vhost: return EINVAL if iovecs size does not match the message size
[ Upstream commit 74ad741 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 096a317 commit 5604fdc

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎drivers/vhost/vhost.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,8 +1035,10 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev,
10351035
int type, ret;
10361036

10371037
ret = copy_from_iter(&type, sizeof(type), from);
1038-
if (ret != sizeof(type))
1038+
if (ret != sizeof(type)) {
1039+
ret = -EINVAL;
10391040
goto done;
1041+
}
10401042

10411043
switch (type) {
10421044
case VHOST_IOTLB_MSG:
@@ -1055,8 +1057,10 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev,
10551057

10561058
iov_iter_advance(from, offset);
10571059
ret = copy_from_iter(&msg, sizeof(msg), from);
1058-
if (ret != sizeof(msg))
1060+
if (ret != sizeof(msg)) {
1061+
ret = -EINVAL;
10591062
goto done;
1063+
}
10601064
if (vhost_process_iotlb_msg(dev, &msg)) {
10611065
ret = -EFAULT;
10621066
goto done;

0 commit comments

Comments
 (0)