All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé via" <qemu-devel@nongnu.org>
To: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>, qemu-devel@nongnu.org
Cc: yc-core@yandex-team.ru
Subject: Re: [PATCH] vhost: fix repeated memory unmap in error paths
Date: Thu, 10 Feb 2022 13:06:05 +0100	[thread overview]
Message-ID: <e8d5554f-d78d-7711-355b-8795559e6075@amsat.org> (raw)
In-Reply-To: <164449358353.2210343.10106072767435805975.stgit@dynamic-vpn.dhcp.yndx.net>

On 10/2/22 12:46, Konstantin Khlebnikov wrote:
> Fuzzing found that on some error paths vhost_memory_unmap() is called twice or
> for NULL address. Let's reset pointers after unmap and ingnore unmap for NULL.
> 
> Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
> ---
>   hw/virtio/vhost.c |    4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> index 7b03efccec..4e5d5f2ea4 100644
> --- a/hw/virtio/vhost.c
> +++ b/hw/virtio/vhost.c
> @@ -335,7 +335,7 @@ static void vhost_memory_unmap(struct vhost_dev *dev, void *buffer,
>                                  hwaddr len, int is_write,
>                                  hwaddr access_len)
>   {
> -    if (!vhost_dev_has_iommu(dev)) {
> +    if (buffer && !vhost_dev_has_iommu(dev)) {

Shouldn't we simply add an "assert(buffer);" check here instead?

>           cpu_physical_memory_unmap(buffer, len, is_write, access_len);
>       }
>   }
> @@ -1191,6 +1191,7 @@ fail_alloc_avail:
>       vhost_memory_unmap(dev, vq->desc, virtio_queue_get_desc_size(vdev, idx),
>                          0, 0);
>   fail_alloc_desc:
> +    vq->used = vq->avail = vq->desc = NULL;
>       return r;
>   }
>   
> @@ -1238,6 +1239,7 @@ static void vhost_virtqueue_stop(struct vhost_dev *dev,
>                          0, virtio_queue_get_avail_size(vdev, idx));
>       vhost_memory_unmap(dev, vq->desc, virtio_queue_get_desc_size(vdev, idx),
>                          0, virtio_queue_get_desc_size(vdev, idx));
> +    vq->used = vq->avail = vq->desc = NULL;
>   }

This part is OK.


  reply	other threads:[~2022-02-10 12:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-10 11:46 [PATCH] vhost: fix repeated memory unmap in error paths Konstantin Khlebnikov
2022-02-10 12:06 ` Philippe Mathieu-Daudé via [this message]
2022-02-10 12:20   ` Konstantin Khlebnikov

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=e8d5554f-d78d-7711-355b-8795559e6075@amsat.org \
    --to=qemu-devel@nongnu.org \
    --cc=f4bug@amsat.org \
    --cc=khlebnikov@yandex-team.ru \
    --cc=yc-core@yandex-team.ru \
    /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.