Skip to content

Commit

Permalink
vhost: release memory_listener object in error path
Browse files Browse the repository at this point in the history
vhost_dev_start function does not release memory_listener object
in case of an error. This may crash the guest when vhost is unable
to set memory table:

  stack trace of thread 125653:
  Program terminated with signal SIGSEGV, Segmentation fault
  #0  memory_listener_register (qemu-kvm + 0x6cda0f)
  #1  vhost_dev_start (qemu-kvm + 0x699301)
  #2  vhost_net_start (qemu-kvm + 0x45b03f)
  #3  virtio_net_set_status (qemu-kvm + 0x665672)
  #4  qmp_set_link (qemu-kvm + 0x548fd5)
  qemu#5  net_vhost_user_event (qemu-kvm + 0x552c45)
  qemu#6  tcp_chr_connect (qemu-kvm + 0x88d473)
  qemu#7  tcp_chr_new_client (qemu-kvm + 0x88cf83)
  qemu#8  tcp_chr_accept (qemu-kvm + 0x88b429)
  qemu#9  qio_net_listener_channel_func (qemu-kvm + 0x7ac07c)
  qemu#10 g_main_context_dispatch (libglib-2.0.so.0 + 0x54e2f)

Release memory_listener objects in the error path.

Signed-off-by: Prasad Pandit <pjp@fedoraproject.org>
Message-Id: <20230529114333.31686-2-ppandit@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Fixes: c471ad0 ("vhost_net: device IOTLB support")
Cc: qemu-stable@nongnu.org
Acked-by: Jason Wang <jasowang@redhat.com>
  • Loading branch information
Prasad Pandit authored and mstsirkin committed Jun 23, 2023
1 parent 7a0903f commit 1e3ffb3
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions hw/virtio/vhost.c
Expand Up @@ -2003,6 +2003,9 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings)
}

fail_mem:
if (vhost_dev_has_iommu(hdev)) {
memory_listener_unregister(&hdev->iommu_listener);
}
fail_features:
vdev->vhost_started = false;
hdev->started = false;
Expand Down

0 comments on commit 1e3ffb3

Please sign in to comment.