qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Evgeny Yakovlev <wrfsh@yandex-team.ru>
Cc: qemu-devel@nongnu.org, yc-core@yandex-team.ru
Subject: Re: [PATCH] hw/vfio/pci: fix double free in vfio_msi_disable
Date: Thu, 26 Sep 2019 11:16:22 -0600	[thread overview]
Message-ID: <20190926111622.5cd9f856@x1.home> (raw)
In-Reply-To: <1569497375-24633-1-git-send-email-wrfsh@yandex-team.ru>

On Thu, 26 Sep 2019 14:29:35 +0300
Evgeny Yakovlev <wrfsh@yandex-team.ru> wrote:

> The following guest behaviour patter leads to double free in VFIO PCI:
> 
> 1. Guest enables MSI interrupts
> vfio_msi_enable is called, but fails in vfio_enable_vectors.
> In our case this was because VFIO GPU device was in D3 state.
> Unhappy path in vfio_msi_enable will g_free(vdev->msi_vectors) but not
> set this pointer to NULL
> 
> 2. Guest still sees MSI an enabled after that because emulated config
> write is done in vfio_pci_write_config unconditionally before calling
> vfio_msi_enable
> 
> 3. Guest disables MSI interrupts
> vfio_msi_disable is called and tries to g_free(vdev->msi_vectors)
> in vfio_msi_disable_common => double free
> 
> Signed-off-by: Evgeny Yakovlev <wrfsh@yandex-team.ru>
> ---
>  hw/vfio/pci.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> index c5e6fe6..12fac39 100644
> --- a/hw/vfio/pci.c
> +++ b/hw/vfio/pci.c
> @@ -651,6 +651,7 @@ retry:
>          }
>  
>          g_free(vdev->msi_vectors);
> +        vdev->msi_vectors = NULL;
>  
>          if (ret > 0 && ret != vdev->nr_vectors) {
>              vdev->nr_vectors = ret;

Looks correct to me, I'll queue it.  Thanks,

Alex


      reply	other threads:[~2019-09-26 17:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-26 11:29 [PATCH] hw/vfio/pci: fix double free in vfio_msi_disable Evgeny Yakovlev
2019-09-26 17:16 ` Alex Williamson [this message]

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=20190926111622.5cd9f856@x1.home \
    --to=alex.williamson@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=wrfsh@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).