All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Albert Esteve <aesteve@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH] hw/virtio/vhost: check nvqs at dev_start
Date: Mon, 2 Oct 2023 05:27:04 -0400	[thread overview]
Message-ID: <20231002052550-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20230901122323.66183-1-aesteve@redhat.com>

On Fri, Sep 01, 2023 at 02:23:23PM +0200, Albert Esteve wrote:
> While this is not expected to happen, it could still
> be that a vhost_dev did not set its nvqs member.
> 
> Since `vhost_dev_start` access the device's vqs array
> later without checking its size, it would cause a
> Segmentation fault when nvqs is 0.
> 
> To avoid this `rare` case and made the code safer,
> add a clause that ensures nvqs has been set, and
> warn the user if it has not.
> 
> Signed-off-by: Albert Esteve <aesteve@redhat.com>
> ---
>  hw/virtio/vhost.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> index e2f6ffb446..78805fe5b7 100644
> --- a/hw/virtio/vhost.c
> +++ b/hw/virtio/vhost.c
> @@ -1935,6 +1935,11 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings)
>      hdev->started = true;
>      hdev->vdev = vdev;
>  
> +    if (!hdev->nvqs) {
> +        error_report("device nvqs not set");
> +        goto fail_nvqs;
> +    }
> +
>      r = vhost_dev_set_features(hdev, hdev->log_enabled);
>      if (r < 0) {
>          goto fail_features;
> @@ -2028,6 +2033,7 @@ fail_mem:
>      if (vhost_dev_has_iommu(hdev)) {
>          memory_listener_unregister(&hdev->iommu_listener);
>      }
> +fail_nvqs:
>  fail_features:
>      vdev->vhost_started = false;
>      hdev->started = false;

What do we want to return in this case?
ATM the value we return (r) will be uninitialized.

> -- 
> 2.41.0



  reply	other threads:[~2023-10-02  9:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-01 12:23 [PATCH] hw/virtio/vhost: check nvqs at dev_start Albert Esteve
2023-10-02  9:27 ` Michael S. Tsirkin [this message]
2023-10-02 10:49   ` Albert Esteve

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231002052550-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=aesteve@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.