virtio-iommu: Do not process commands with bad size
PATCH 1/1 virtio-iommu: Do not process commands with bad size
The device should not handle the commands which have bad request/reply size, it should just report the error instead of raising an assertation.
--- hw/virtio/virtio-iommu.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
hw/virtio/virtio-iommu.c +3 -7
@@ -770,8 +770,8 @@ static void virtio_iommu_handle_command(VirtIODevice *vdev, VirtQueue *vq)return ; } -if (iov_size (elem->in_sg, elem->in_num) <sizeof (tail) || -iov_size (elem->out_sg, elem->out_num) <sizeof (head)) { +if (iov_size (elem->in_sg, elem->in_num) !=sizeof (tail) || +iov_size (elem->out_sg, elem->out_num) !=sizeof (head)) {virtio_error (vdev,"virtio-iommu bad head/tail size" );virtqueue_detach_element (vq, elem,0 );g_free (elem);
@@ -818,8 +818,6 @@ static void virtio_iommu_handle_command(VirtIODevice *vdev, VirtQueue *vq) out: sz =iov_from_buf (elem->in_sg, elem->in_num,0 , buf ? buf : &tail, output_size); -assert (sz == output_size); -virtqueue_push (vq, elem, sz);virtio_notify (vdev, vq);g_free (elem);
@@ -852,7 +850,7 @@ static void virtio_iommu_report_fault(VirtIOIOMMU *viommu, uint8_t reason,return ; } -if (iov_size (elem->in_sg, elem->in_num) <sizeof (fault)) { +if (iov_size (elem->in_sg, elem->in_num) !=sizeof (fault)) {virtio_error (vdev,"error buffer of wrong size" );virtqueue_detach_element (vq, elem,0 );g_free (elem);
@@ -861,8 +859,6 @@ static void virtio_iommu_report_fault(VirtIOIOMMU *viommu, uint8_t reason, sz =iov_from_buf (elem->in_sg, elem->in_num,0 , &fault,sizeof (fault)); -assert (sz ==sizeof (fault)); -trace_virtio_iommu_report_fault (reason, flags, endpoint, address);virtqueue_push (vq, elem, sz);virtio_notify (vdev, vq);
Signature · 1 line
2.34.1
Quoted 4 lines · Zheyu Ma
The device should not handle the commands which have bad request/reply size, it should just report the error instead of raising an assertation.
Signed-off-by Zheyu Ma <[email protected]>
I do not get what problem you are trying to solve here. Can guest trigger this assert? I do not see how.
Quoted 48 lines
--- hw/virtio/virtio-iommu.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)hw/virtio/virtio-iommu.c +3
-7@@ -770,8 +770,8 @@ static void virtio_iommu_handle_command(VirtIODevice *vdev, VirtQueue *vq)return ; } -if (iov_size (elem->in_sg, elem->in_num) <sizeof (tail) || -iov_size (elem->out_sg, elem->out_num) <sizeof (head)) { +if (iov_size (elem->in_sg, elem->in_num) !=sizeof (tail) || +iov_size (elem->out_sg, elem->out_num) !=sizeof (head)) {virtio_error (vdev,"virtio-iommu bad head/tail size" );virtqueue_detach_element (vq, elem,0 );g_free (elem);@@ -818,8 +818,6 @@ static void virtio_iommu_handle_command(VirtIODevice *vdev, VirtQueue *vq) out: sz =iov_from_buf (elem->in_sg, elem->in_num,0 , buf ? buf : &tail, output_size); -assert (sz == output_size); -virtqueue_push (vq, elem, sz);virtio_notify (vdev, vq);g_free (elem);@@ -852,7 +850,7 @@ static void virtio_iommu_report_fault(VirtIOIOMMU *viommu, uint8_t reason,return ; } -if (iov_size (elem->in_sg, elem->in_num) <sizeof (fault)) { +if (iov_size (elem->in_sg, elem->in_num) !=sizeof (fault)) {virtio_error (vdev,"error buffer of wrong size" );virtqueue_detach_element (vq, elem,0 );g_free (elem);@@ -861,8 +859,6 @@ static void virtio_iommu_report_fault(VirtIOIOMMU *viommu, uint8_t reason, sz =iov_from_buf (elem->in_sg, elem->in_num,0 , &fault,sizeof (fault)); -assert (sz ==sizeof (fault)); -trace_virtio_iommu_report_fault (reason, flags, endpoint, address);virtqueue_push (vq, elem, sz);virtio_notify (vdev, vq);Signature · 1 line
2.34.1
Quoted 4 lines · Zheyu Ma
The device should not handle the commands which have bad request/reply size, it should just report the error instead of raising an assertation.
Signed-off-by Zheyu Ma <[email protected]>
This fails test for cross-i686-tci
https://gitlab.com/mstredhat/qemu/-/jobs/6578222837
57/258 ERROR:../tests/qtest/libqos/virtio.c:230:qvirtio_wait_used_elem: assertion failed: (g_get_monotonic_time() - start_time <= timeout_us) ERROR
57/258 qemu:qtest+qtest-i386 / qtest-i386/qos-test ERROR 56.69s killed by signal 6 SIGABRT
Quoted 1 line
Quoted 1 line
Quoted 1 line
QTEST_QEMU_BINARY=./qemu-system-i386 PYTHON=/builds/mstredhat/qemu/build/pyvenv/bin/python3 MALLOC_PERTURB_=112 G_TEST_DBUS_DAEMON=/builds/mstredhat/qemu/tests/dbus-vmstate-daemon.sh /builds/mstredhat/qemu/build/tests/qtest/qos-test --tap -k
――――――――――――――――――――――――――――――――――――― ✀ ―――――――――――――――――――――――――――――――――――――
stderr:
Vhost user backend fails to broadcast fake RARP
qemu-system-i386: -chardev socket,id=chr-reconnect,path=/tmp/vhost-test-80QXL2/reconnect.sock,server=on: info: QEMU waiting for connection on: disconnected:unix:/tmp/vhost-test-80QXL2/reconnect.sock,server=on
qemu-system-i386: Failed to set msg fds.
qemu-system-i386: vhost VQ 0 ring restore failed: -22: Invalid argument (22)
qemu-system-i386: Failed to set msg fds.
qemu-system-i386: vhost VQ 1 ring restore failed: -22: Invalid argument (22)
qemu-system-i386: Failed to set msg fds.
qemu-system-i386: vhost VQ 0 ring restore failed: -22: Invalid argument (22)
qemu-system-i386: Failed to set msg fds.
qemu-system-i386: vhost VQ 1 ring restore failed: -22: Invalid argument (22)
qemu-system-i386: -chardev socket,id=chr-connect-fail,path=/tmp/vhost-test-CZMWL2/connect-fail.sock,server=on: info: QEMU waiting for connection on: disconnected:unix:/tmp/vhost-test-CZMWL2/connect-fail.sock,server=on
qemu-system-i386: -netdev vhost-user,id=hs0,chardev=chr-connect-fail,vhostforce=on: Failed to read msg header. Read 0 instead of 12. Original request 1.
qemu-system-i386: -netdev vhost-user,id=hs0,chardev=chr-connect-fail,vhostforce=on: vhost_backend_init failed: Protocol error
qemu-system-i386: -netdev vhost-user,id=hs0,chardev=chr-connect-fail,vhostforce=on: failed to init vhost_net for queue 0
qemu-system-i386: -netdev vhost-user,id=hs0,chardev=chr-connect-fail,vhostforce=on: info: QEMU waiting for connection on: disconnected:unix:/tmp/vhost-test-CZMWL2/connect-fail.sock,server=on
qemu-system-i386: Failed to write msg. Wrote -1 instead of 20.
qemu-system-i386: vhost VQ 0 ring restore failed: -22: Invalid argument (22)
qemu-system-i386: Failed to set msg fds.
qemu-system-i386: vhost VQ 1 ring restore failed: -22: Invalid argument (22)
qemu-system-i386: -chardev socket,id=chr-flags-mismatch,path=/tmp/vhost-test-CBHDM2/flags-mismatch.sock,server=on: info: QEMU waiting for connection on: disconnected:unix:/tmp/vhost-test-CBHDM2/flags-mismatch.sock,server=on
qemu-system-i386: Failed to write msg. Wrote -1 instead of 84.
qemu-system-i386: vhost_set_mem_table failed: Invalid argument (22)
qemu-system-i386: unable to start vhost net: 22: falling back on userspace virtio
vhost lacks feature mask 0x40000000 for backend
qemu-system-i386: failed to init vhost_net for queue 0
qemu-system-i386: Failed to set msg fds.
qemu-system-i386: vhost VQ 0 ring restore failed: -22: Invalid argument (22)
qemu-system-i386: Failed to set msg fds.
qemu-system-i386: vhost VQ 1 ring restore failed: -22: Invalid argument (22)
qemu-system-i386: Failed to write msg. Wrote -1 instead of 20.
qemu-system-i386: vhost VQ 0 ring restore failed: -22: Invalid argument (22)
qemu-system-i386: Failed to set msg fds.
qemu-system-i386: vhost VQ 1 ring restore failed: -22: Invalid argument (22)
qemu-system-i386: Failed to set msg fds.
qemu-system-i386: vhost VQ 2 ring restore failed: -22: Invalid argument (22)
qemu-system-i386: Failed to set msg fds.
qemu-system-i386: vhost VQ 3 ring restore failed: -22: Invalid argument (22)
qemu-system-i386: Failed to set msg fds.
qemu-system-i386: vhost VQ 0 ring restore failed: -22: Invalid argument (22)
qemu-system-i386: Failed to set msg fds.
qemu-system-i386: vhost VQ 1 ring restore failed: -22: Invalid argument (22)
qemu-system-i386: Failed to set msg fds.
qemu-system-i386: vhost VQ 0 ring restore failed: -22: Invalid argument (22)
qemu-system-i386: Failed to set msg fds.
qemu-system-i386: vhost VQ 1 ring restore failed: -22: Invalid argument (22)
qemu-system-i386: virtio-iommu bad head/tail size
**
ERROR:../tests/qtest/libqos/virtio.c:230:qvirtio_wait_used_elem: assertion failed: (g_get_monotonic_time() - start_time <= timeout_us)
(test program exited with status code -6)
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
So we hit the error where we did not previously hit the assert.
Dropped for now. Pls figure it out and resubmit.
Quoted 48 lines
--- hw/virtio/virtio-iommu.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)hw/virtio/virtio-iommu.c +3
-7@@ -770,8 +770,8 @@ static void virtio_iommu_handle_command(VirtIODevice *vdev, VirtQueue *vq)return ; } -if (iov_size (elem->in_sg, elem->in_num) <sizeof (tail) || -iov_size (elem->out_sg, elem->out_num) <sizeof (head)) { +if (iov_size (elem->in_sg, elem->in_num) !=sizeof (tail) || +iov_size (elem->out_sg, elem->out_num) !=sizeof (head)) {virtio_error (vdev,"virtio-iommu bad head/tail size" );virtqueue_detach_element (vq, elem,0 );g_free (elem);@@ -818,8 +818,6 @@ static void virtio_iommu_handle_command(VirtIODevice *vdev, VirtQueue *vq) out: sz =iov_from_buf (elem->in_sg, elem->in_num,0 , buf ? buf : &tail, output_size); -assert (sz == output_size); -virtqueue_push (vq, elem, sz);virtio_notify (vdev, vq);g_free (elem);@@ -852,7 +850,7 @@ static void virtio_iommu_report_fault(VirtIOIOMMU *viommu, uint8_t reason,return ; } -if (iov_size (elem->in_sg, elem->in_num) <sizeof (fault)) { +if (iov_size (elem->in_sg, elem->in_num) !=sizeof (fault)) {virtio_error (vdev,"error buffer of wrong size" );virtqueue_detach_element (vq, elem,0 );g_free (elem);@@ -861,8 +859,6 @@ static void virtio_iommu_report_fault(VirtIOIOMMU *viommu, uint8_t reason, sz =iov_from_buf (elem->in_sg, elem->in_num,0 , &fault,sizeof (fault)); -assert (sz ==sizeof (fault)); -trace_virtio_iommu_report_fault (reason, flags, endpoint, address);virtqueue_push (vq, elem, sz);virtio_notify (vdev, vq);Signature · 1 line
2.34.1
Quoted 4 lines · Zheyu Ma
The device should not handle the commands which have bad request/reply size, it should just report the error instead of raising an assertation.
Signed-off-by Zheyu Ma <[email protected]>
Seems to cause CI failures:
https://gitlab.com/mstredhat/qemu/-/jobs/7004894370
41/399 /riscv32/virt/generic-pcihost/pci-bus-generic/pci-bus/virtio-iommu-pci/virtio-iommu/virtio-iommu-tests/attach_detach - ERROR:../tests/qtest/libqos/virtio.c:230:qvirtio_wait_used_elem: assertion failed: (g_get_monotonic_time() - start_time <= timeout_us) FAIL
▶ 41/399 ERROR
41/399 qemu:qtest+qtest-riscv32 / qtest-riscv32/qos-test ERROR 76.80s killed by signal 6 SIGABRT
Quoted 53 lines
Quoted 1 line
Quoted 1 line
MALLOC_PERTURB_=235 QTEST_QEMU_STORAGE_DAEMON_BINARY=./storage-daemon/qemu-storage-daemon QTEST_QEMU_BINARY=./qemu-system-riscv32 G_TEST_DBUS_DAEMON=/builds/mstredhat/qemu/tests/dbus-vmstate-daemon.sh QTEST_QEMU_IMG=./qemu-img PYTHON=/builds/mstredhat/qemu/build/pyvenv/bin/python3 /builds/mstredhat/qemu/build/tests/qtest/qos-test --tap -k
--- hw/virtio/virtio-iommu.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)hw/virtio/virtio-iommu.c +3
-7@@ -770,8 +770,8 @@ static void virtio_iommu_handle_command(VirtIODevice *vdev, VirtQueue *vq)return ; } -if (iov_size (elem->in_sg, elem->in_num) <sizeof (tail) || -iov_size (elem->out_sg, elem->out_num) <sizeof (head)) { +if (iov_size (elem->in_sg, elem->in_num) !=sizeof (tail) || +iov_size (elem->out_sg, elem->out_num) !=sizeof (head)) {virtio_error (vdev,"virtio-iommu bad head/tail size" );virtqueue_detach_element (vq, elem,0 );g_free (elem);@@ -818,8 +818,6 @@ static void virtio_iommu_handle_command(VirtIODevice *vdev, VirtQueue *vq) out: sz =iov_from_buf (elem->in_sg, elem->in_num,0 , buf ? buf : &tail, output_size); -assert (sz == output_size); -virtqueue_push (vq, elem, sz);virtio_notify (vdev, vq);g_free (elem);@@ -852,7 +850,7 @@ static void virtio_iommu_report_fault(VirtIOIOMMU *viommu, uint8_t reason,return ; } -if (iov_size (elem->in_sg, elem->in_num) <sizeof (fault)) { +if (iov_size (elem->in_sg, elem->in_num) !=sizeof (fault)) {virtio_error (vdev,"error buffer of wrong size" );virtqueue_detach_element (vq, elem,0 );g_free (elem);@@ -861,8 +859,6 @@ static void virtio_iommu_report_fault(VirtIOIOMMU *viommu, uint8_t reason, sz =iov_from_buf (elem->in_sg, elem->in_num,0 , &fault,sizeof (fault)); -assert (sz ==sizeof (fault)); -trace_virtio_iommu_report_fault (reason, flags, endpoint, address);virtqueue_push (vq, elem, sz);virtio_notify (vdev, vq);Signature · 1 line
2.34.1