[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v4 47/48] libvhost-user: return early on virtqueue errors
From: |
Michael S. Tsirkin |
Subject: |
[PULL v4 47/48] libvhost-user: return early on virtqueue errors |
Date: |
Tue, 29 Sep 2020 03:23:08 -0400 |
From: Stefan Hajnoczi <stefanha@redhat.com>
vu_panic() is not guaranteed to exit the program. Return early when
errors are encountered.
Note that libvhost-user does not have an "unmap" operation for mapped
descriptors. Therefore it is correct to return without explicit cleanup.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20200921113420.154378-2-stefanha@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
contrib/libvhost-user/libvhost-user.c | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/contrib/libvhost-user/libvhost-user.c
b/contrib/libvhost-user/libvhost-user.c
index 70055c98b7..4ebfa4cc40 100644
--- a/contrib/libvhost-user/libvhost-user.c
+++ b/contrib/libvhost-user/libvhost-user.c
@@ -2416,7 +2416,7 @@ vu_queue_set_notification(VuDev *dev, VuVirtq *vq, int
enable)
}
}
-static void
+static bool
virtqueue_map_desc(VuDev *dev,
unsigned int *p_num_sg, struct iovec *iov,
unsigned int max_num_sg, bool is_write,
@@ -2428,7 +2428,7 @@ virtqueue_map_desc(VuDev *dev,
if (!sz) {
vu_panic(dev, "virtio: zero sized buffers are not allowed");
- return;
+ return false;
}
while (sz) {
@@ -2436,13 +2436,13 @@ virtqueue_map_desc(VuDev *dev,
if (num_sg == max_num_sg) {
vu_panic(dev, "virtio: too many descriptors in indirect table");
- return;
+ return false;
}
iov[num_sg].iov_base = vu_gpa_to_va(dev, &len, pa);
if (iov[num_sg].iov_base == NULL) {
vu_panic(dev, "virtio: invalid address for buffers");
- return;
+ return false;
}
iov[num_sg].iov_len = len;
num_sg++;
@@ -2451,6 +2451,7 @@ virtqueue_map_desc(VuDev *dev,
}
*p_num_sg = num_sg;
+ return true;
}
static void *
@@ -2488,6 +2489,7 @@ vu_queue_map_desc(VuDev *dev, VuVirtq *vq, unsigned int
idx, size_t sz)
if (lduw_le_p(&desc[i].flags) & VRING_DESC_F_INDIRECT) {
if (ldl_le_p(&desc[i].len) % sizeof(struct vring_desc)) {
vu_panic(dev, "Invalid size for indirect buffer table");
+ return NULL;
}
/* loop over the indirect descriptor table */
@@ -2515,22 +2517,29 @@ vu_queue_map_desc(VuDev *dev, VuVirtq *vq, unsigned int
idx, size_t sz)
/* Collect all the descriptors */
do {
if (lduw_le_p(&desc[i].flags) & VRING_DESC_F_WRITE) {
- virtqueue_map_desc(dev, &in_num, iov + out_num,
+ if (!virtqueue_map_desc(dev, &in_num, iov + out_num,
VIRTQUEUE_MAX_SIZE - out_num, true,
- ldq_le_p(&desc[i].addr),
ldl_le_p(&desc[i].len));
+ ldq_le_p(&desc[i].addr),
+ ldl_le_p(&desc[i].len))) {
+ return NULL;
+ }
} else {
if (in_num) {
vu_panic(dev, "Incorrect order for descriptors");
return NULL;
}
- virtqueue_map_desc(dev, &out_num, iov,
+ if (!virtqueue_map_desc(dev, &out_num, iov,
VIRTQUEUE_MAX_SIZE, false,
- ldq_le_p(&desc[i].addr),
ldl_le_p(&desc[i].len));
+ ldq_le_p(&desc[i].addr),
+ ldl_le_p(&desc[i].len))) {
+ return NULL;
+ }
}
/* If we've got too many, that implies a descriptor loop. */
if ((in_num + out_num) > max) {
vu_panic(dev, "Looped descriptor");
+ return NULL;
}
rc = virtqueue_read_next_desc(dev, desc, i, max, &i);
} while (rc == VIRTQUEUE_READ_DESC_MORE);
--
MST
- [PULL v4 44/48] piix4: don't reserve hw resources when hotplug is off globally, (continued)
- [PULL v4 44/48] piix4: don't reserve hw resources when hotplug is off globally, Michael S. Tsirkin, 2020/09/29
- [PULL v4 43/48] Add ACPI DSDT tables for q35 that are being updated by the next patch, Michael S. Tsirkin, 2020/09/29
- [PULL v4 46/48] hw: virtio-pmem: detach the element fromt the virtqueue when error occurs, Michael S. Tsirkin, 2020/09/29
- [PULL v4 48/48] libvhost-user: return on error in vu_log_queue_fill(), Michael S. Tsirkin, 2020/09/29
- [PULL v4 12/48] virtio-pmem-pci: force virtio version 1, Michael S. Tsirkin, 2020/09/29
- [PULL v4 01/48] linux headers: sync to 5.9-rc4, Michael S. Tsirkin, 2020/09/29
- [PULL v4 23/48] x86: cpuhp: refuse cpu hot-unplug request earlier if not supported, Michael S. Tsirkin, 2020/09/29
- [PULL v4 30/48] tests: acpi: update acpi blobs with new AML, Michael S. Tsirkin, 2020/09/29
- [PULL v4 20/48] virtio: update MemoryRegionCaches when guest set bad features, Michael S. Tsirkin, 2020/09/29
- [PULL v4 02/48] vhost: switch to use IOTLB v2 format, Michael S. Tsirkin, 2020/09/29
- [PULL v4 47/48] libvhost-user: return early on virtqueue errors,
Michael S. Tsirkin <=
- [PULL v4 45/48] tests/acpi: update golden master DSDT binary table blobs for q35, Michael S. Tsirkin, 2020/09/29
- Re: [PULL v4 00/48] virtio,pc,acpi: fixes, tests, no-reply, 2020/09/29
- Re: [PULL v4 00/48] virtio,pc,acpi: fixes, tests, no-reply, 2020/09/29
- Re: [PULL v4 00/48] virtio,pc,acpi: fixes, tests, Peter Maydell, 2020/09/29
- Re: [PULL v4 00/48] virtio,pc,acpi: fixes, tests, Michael S. Tsirkin, 2020/09/29