vhost: Check for valid vdev in vhost_backend_handle_iotlb_msg
PATCH 1/1 vhost: Check for valid vdev in vhost_backend_handle_iotlb_msg
Not checking this can lead to invalid dev->vdev member access in vhost_device_iotlb_miss if backend issue an iotlb message in a bad timing, either maliciously or by a bug.
Reproduced rebooting a guest with testpmd in txonly forward mode.
#0 0x0000559ffff94394 in vhost_device_iotlb_miss (
dev=dev@entry=0x55a0012f6680, iova=10245279744, write=1)
at ../hw/virtio/vhost.c:1013
#1 0x0000559ffff9ac31 in vhost_backend_handle_iotlb_msg (
imsg=0x7ffddcfd32c0, dev=0x55a0012f6680)
at ../hw/virtio/vhost-backend.c:411
#2 vhost_backend_handle_iotlb_msg (dev=dev@entry=0x55a0012f6680,
imsg=imsg@entry=0x7ffddcfd32c0)
at ../hw/virtio/vhost-backend.c:404
#3 0x0000559fffeded7b in slave_read (opaque=0x55a0012f6680)
at ../hw/virtio/vhost-user.c:1464
#4 0x000055a0000c541b in aio_dispatch_handler (
ctx=ctx@entry=0x55a0010a2120, node=0x55a0012d9e00)
at ../util/aio-posix.c:329--- hw/virtio/vhost-backend.c | 5 +++++ 1 file changed, 5 insertions(+)
hw/virtio/vhost-backend.c +5 -0
@@ -406,6 +406,11 @@ int vhost_backend_handle_iotlb_msg(struct vhost_dev *dev, {int ret =0 ; +if (unlikely (!dev->vdev)) { +error_report ("Unexpected IOTLB message when virtio device is stopped" ); +return -EINVAL ; + } +switch (imsg->type) {case VHOST_IOTLB_MISS : ret = vhost_device_iotlb_miss(dev, imsg->iova,
Signature · 1 line
2.27.0
Version 2 of ("vhost-user: Check for iotlb callback in iotlb_miss") [1].
Starting a new series, since the title does not reflect the changes anymore.
Thanks!
[1] https://patchew.org/QEMU/[email protected]/
Quoted 47 lines · Eugenio Pérez
Not checking this can lead to invalid
dev->vdevmember access invhost_device_iotlb_missif backend issue an iotlb message in a bad timing, either maliciously or by a bug.Reproduced rebooting a guest with testpmd in txonly forward mode.
#00x0000559ffff94394invhost_device_iotlb_miss(dev=dev@entry=0x55a0012f6680, iova=10245279744, write=1) at ../hw/virtio/vhost.c:1013 #1 0x0000559ffff9ac31 in vhost_backend_handle_iotlb_msg ( imsg=0x7ffddcfd32c0, dev=0x55a0012f6680) at ../hw/virtio/vhost-backend.c:411 #2 vhost_backend_handle_iotlb_msg (dev=dev@entry=0x55a0012f6680, imsg=imsg@entry=0x7ffddcfd32c0) at ../hw/virtio/vhost-backend.c:404 #3 0x0000559fffeded7b in slave_read (opaque=0x55a0012f6680) at ../hw/virtio/vhost-user.c:1464 #4 0x000055a0000c541b in aio_dispatch_handler ( ctx=ctx@entry=0x55a0010a2120, node=0x55a0012d9e00) at ../util/aio-posix.c:329Fixes 6dcdd06e3b ("spec/vhost-user spec: Add IOMMU support")Signed-off-by Eugenio Pérez <[email protected]>--- hw/virtio/vhost-backend.c | 5 +++++ 1 file changed, 5 insertions(+)hw/virtio/vhost-backend.c +5
-1@@ -406,6 +406,11 @@ int vhost_backend_handle_iotlb_msg(struct vhost_dev *dev, {int ret =0 ; +if (unlikely (!dev->vdev)) { +error_report ("Unexpected IOTLB message when virtio device is stopped" ); +return -EINVAL ; + } +switch (imsg->type) {case VHOST_IOTLB_MISS : ret = vhost_device_iotlb_miss(dev, imsg->iova, --2.27.0
Quoted 20 lines · Eugenio Pérez
Not checking this can lead to invalid
dev->vdevmember access invhost_device_iotlb_missif backend issue an iotlb message in a bad timing, either maliciously or by a bug.Reproduced rebooting a guest with testpmd in txonly forward mode.
#00x0000559ffff94394invhost_device_iotlb_miss(dev=dev@entry=0x55a0012f6680, iova=10245279744, write=1) at ../hw/virtio/vhost.c:1013 #1 0x0000559ffff9ac31 in vhost_backend_handle_iotlb_msg ( imsg=0x7ffddcfd32c0, dev=0x55a0012f6680) at ../hw/virtio/vhost-backend.c:411 #2 vhost_backend_handle_iotlb_msg (dev=dev@entry=0x55a0012f6680, imsg=imsg@entry=0x7ffddcfd32c0) at ../hw/virtio/vhost-backend.c:404 #3 0x0000559fffeded7b in slave_read (opaque=0x55a0012f6680) at ../hw/virtio/vhost-user.c:1464 #4 0x000055a0000c541b in aio_dispatch_handler ( ctx=ctx@entry=0x55a0010a2120, node=0x55a0012d9e00) at ../util/aio-posix.c:329
Quoted 2 lines
Fixes 6dcdd06e3b ("spec/vhost-user spec: Add IOMMU support")Signed-off-by Eugenio Pérez <[email protected]>
Quoted 20 lines
--- hw/virtio/vhost-backend.c | 5 +++++ 1 file changed, 5 insertions(+)hw/virtio/vhost-backend.c +5
-0@@ -406,6 +406,11 @@ int vhost_backend_handle_iotlb_msg(struct vhost_dev *dev, {int ret =0 ; +if (unlikely (!dev->vdev)) { +error_report ("Unexpected IOTLB message when virtio device is stopped" ); +return -EINVAL ; + } +switch (imsg->type) {case VHOST_IOTLB_MISS : ret = vhost_device_iotlb_miss(dev, imsg->iova,
Quoted 20 lines · Eugenio Pérez
Not checking this can lead to invalid
dev->vdevmember access invhost_device_iotlb_missif backend issue an iotlb message in a bad timing, either maliciously or by a bug.Reproduced rebooting a guest with testpmd in txonly forward mode. #0
0x0000559ffff94394invhost_device_iotlb_miss(dev=dev@entry=0x55a0012f6680, iova=10245279744, write=1) at ../hw/virtio/vhost.c:1013 #1 0x0000559ffff9ac31 in vhost_backend_handle_iotlb_msg ( imsg=0x7ffddcfd32c0, dev=0x55a0012f6680) at ../hw/virtio/vhost-backend.c:411 #2 vhost_backend_handle_iotlb_msg (dev=dev@entry=0x55a0012f6680, imsg=imsg@entry=0x7ffddcfd32c0) at ../hw/virtio/vhost-backend.c:404 #3 0x0000559fffeded7b in slave_read (opaque=0x55a0012f6680) at ../hw/virtio/vhost-user.c:1464 #4 0x000055a0000c541b in aio_dispatch_handler ( ctx=ctx@entry=0x55a0010a2120, node=0x55a0012d9e00) at ../util/aio-posix.c:329
Quoted 1 line
Fixes 6dcdd06e3b ("spec/vhost-user spec: Add IOMMU support")
I'm not sure but IIUC vhost_backend_handle_iotlb_msg() was introduced by commit 020e571b8b, so maybe is better this 'Fixes' line:
Quoted 25 lines
Signed-off-by Eugenio Pérez <[email protected]>---
hw/virtio/vhost-backend.c| 5 +++++1 file changed, 5 insertions(+)hw/virtio/vhost-backend.c +5
-0@@ -406,6 +406,11 @@ int vhost_backend_handle_iotlb_msg(struct vhost_dev *dev, {int ret =0 ; +if (unlikely (!dev->vdev)) { +error_report ("Unexpected IOTLB message when virtio device is stopped" ); +return -EINVAL ; + } +switch (imsg->type) {case VHOST_IOTLB_MISS : ret = vhost_device_iotlb_miss(dev, imsg->iova,Signature · 1 line
2.27.0
The patch LGTM:
Quoted 22 lines · Stefano Garzarella
Quoted 20 lines · Eugenio Pérez
Not checking this can lead to invalid
dev->vdevmember access invhost_device_iotlb_missif backend issue an iotlb message in a bad timing, either maliciously or by a bug.Reproduced rebooting a guest with testpmd in txonly forward mode. #0
0x0000559ffff94394invhost_device_iotlb_miss(dev=dev@entry=0x55a0012f6680, iova=10245279744, write=1) at ../hw/virtio/vhost.c:1013 #1 0x0000559ffff9ac31 in vhost_backend_handle_iotlb_msg ( imsg=0x7ffddcfd32c0, dev=0x55a0012f6680) at ../hw/virtio/vhost-backend.c:411 #2 vhost_backend_handle_iotlb_msg (dev=dev@entry=0x55a0012f6680, imsg=imsg@entry=0x7ffddcfd32c0) at ../hw/virtio/vhost-backend.c:404 #3 0x0000559fffeded7b in slave_read (opaque=0x55a0012f6680) at ../hw/virtio/vhost-user.c:1464 #4 0x000055a0000c541b in aio_dispatch_handler ( ctx=ctx@entry=0x55a0010a2120, node=0x55a0012d9e00) at ../util/aio-posix.c:329
Quoted 7 lines
Quoted 1 line
Fixes 6dcdd06e3b ("spec/vhost-user spec: Add IOMMU support")I'm not sure but IIUC
vhost_backend_handle_iotlb_msg()was introduced by commit020e571b8b, so maybe is better this 'Fixes' line:Fixes 020e571b8b ("vhost: rework IOTLB messaging")
Hi Stefano.
Thanks for reviewing it :). Actually yes, you are right, I carried the previous Fixes line by mistake.
Should I send a new patch?
Thanks!
Quoted 30 lines
Quoted 22 lines
Signed-off-by Eugenio Pérez <[email protected]>---
hw/virtio/vhost-backend.c| 5 +++++1 file changed, 5 insertions(+)hw/virtio/vhost-backend.c +5
-1@@ -406,6 +406,11 @@ int vhost_backend_handle_iotlb_msg(struct vhost_dev *dev, {int ret =0 ; +if (unlikely (!dev->vdev)) { +error_report ("Unexpected IOTLB message when virtio device is stopped" ); +return -EINVAL ; + } +switch (imsg->type) {case VHOST_IOTLB_MISS : ret = vhost_device_iotlb_miss(dev, imsg->iova, --Quoted 3 lines
2.27.0
The patch LGTM:
Reviewed-by Stefano Garzarella <[email protected]>
Quoted 31 lines · Eugenio Perez Martin
Quoted 22 lines · Stefano Garzarella
Quoted 20 lines · Eugenio Pérez
Not checking this can lead to invalid
dev->vdevmember access invhost_device_iotlb_missif backend issue an iotlb message in a bad timing, either maliciously or by a bug.Reproduced rebooting a guest with testpmd in txonly forward mode. #0
0x0000559ffff94394invhost_device_iotlb_miss(dev=dev@entry=0x55a0012f6680, iova=10245279744, write=1) at ../hw/virtio/vhost.c:1013 #1 0x0000559ffff9ac31 in vhost_backend_handle_iotlb_msg ( imsg=0x7ffddcfd32c0, dev=0x55a0012f6680) at ../hw/virtio/vhost-backend.c:411 #2 vhost_backend_handle_iotlb_msg (dev=dev@entry=0x55a0012f6680, imsg=imsg@entry=0x7ffddcfd32c0) at ../hw/virtio/vhost-backend.c:404 #3 0x0000559fffeded7b in slave_read (opaque=0x55a0012f6680) at ../hw/virtio/vhost-user.c:1464 #4 0x000055a0000c541b in aio_dispatch_handler ( ctx=ctx@entry=0x55a0010a2120, node=0x55a0012d9e00) at ../util/aio-posix.c:329Quoted 7 lines
Quoted 1 line
Fixes 6dcdd06e3b ("spec/vhost-user spec: Add IOMMU support")I'm not sure but IIUC
vhost_backend_handle_iotlb_msg()was introduced by commit020e571b8b, so maybe is better this 'Fixes' line:Fixes 020e571b8b ("vhost: rework IOTLB messaging")
Quoted 6 lines
Hi Stefano.
Thanks for reviewing it :). Actually yes, you are right, I carried the previous Fixes line by mistake.
Should I send a new patch?
Maybe Michael can fix it while applying, but I'm not sure, let's see what he says :-)
Stefano
Quoted 35 lines
Thanks!
Quoted 30 lines
Quoted 22 lines
Signed-off-by Eugenio Pérez <[email protected]>---
hw/virtio/vhost-backend.c| 5 +++++1 file changed, 5 insertions(+)hw/virtio/vhost-backend.c +5
-1@@ -406,6 +406,11 @@ int vhost_backend_handle_iotlb_msg(struct vhost_dev *dev, {int ret =0 ; +if (unlikely (!dev->vdev)) { +error_report ("Unexpected IOTLB message when virtio device is stopped" ); +return -EINVAL ; + } +switch (imsg->type) {case VHOST_IOTLB_MISS : ret = vhost_device_iotlb_miss(dev, imsg->iova, --Quoted 3 lines
2.27.0
The patch LGTM:
Reviewed-by Stefano Garzarella <[email protected]>