From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Avihai Horon <avihaih@nvidia.com>, qemu-devel@nongnu.org
Cc: "Alex Williamson" <alex.williamson@redhat.com>,
"Cédric Le Goater" <clg@redhat.com>
Subject: Re: [PATCH v2] vfio: Fix null pointer dereference bug in vfio_bars_finalize()
Date: Tue, 4 Jul 2023 16:07:35 +0200 [thread overview]
Message-ID: <a359bb8c-9643-3dd6-66d4-ab32e2506d79@linaro.org> (raw)
In-Reply-To: <20230704133927.24677-1-avihaih@nvidia.com>
On 4/7/23 15:39, Avihai Horon wrote:
> vfio_realize() has the following flow:
> 1. vfio_bars_prepare() -- sets VFIOBAR->size.
> 2. msix_early_setup().
> 3. vfio_bars_register() -- allocates VFIOBAR->mr.
>
> After vfio_bars_prepare() is called msix_early_setup() can fail. If it
> does fail, vfio_bars_register() is never called and VFIOBAR->mr is not
> allocated.
>
> In this case, vfio_bars_finalize() is called as part of the error flow
> to free the bars' resources. However, vfio_bars_finalize() calls
> object_unparent() for VFIOBAR->mr after checking only VFIOBAR->size, and
> thus we get a null pointer dereference.
>
> Fix it by checking VFIOBAR->mr in vfio_bars_finalize().
>
> Fixes: 89d5202edc50 ("vfio/pci: Allow relocating MSI-X MMIO")
> Signed-off-by: Avihai Horon <avihaih@nvidia.com>
> ---
>
> Changes from v1:
> * Assert VFIOBAR->size and set VFIOBAR->mr to NULL to make the code
> more accurate. (Philippe)
> * Small reword in the last paragraph of the commit message.
>
> hw/vfio/pci.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
next prev parent reply other threads:[~2023-07-04 14:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-04 13:39 [PATCH v2] vfio: Fix null pointer dereference bug in vfio_bars_finalize() Avihai Horon
2023-07-04 14:07 ` Philippe Mathieu-Daudé [this message]
2023-07-04 15:54 ` Cédric Le Goater
2023-07-05 6:16 ` Avihai Horon
2023-07-06 20:31 ` Alex Williamson
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=a359bb8c-9643-3dd6-66d4-ab32e2506d79@linaro.org \
--to=philmd@linaro.org \
--cc=alex.williamson@redhat.com \
--cc=avihaih@nvidia.com \
--cc=clg@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 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).