From: Cornelia Huck <cohuck@redhat.com>
To: Michal Privoznik <mprivozn@redhat.com>
Cc: alex.williamson@redhat.com, qemu-devel@nongnu.org
Subject: Re: [PATCH 1/2] hw/vfio/pci: Fix double free of migration_blocker
Date: Mon, 11 Nov 2019 11:52:30 +0100 [thread overview]
Message-ID: <20191111115230.4cc1bd6b.cohuck@redhat.com> (raw)
In-Reply-To: <c96b132607f4314ce1efc1af995be300f21ecc04.1573468531.git.mprivozn@redhat.com>
On Mon, 11 Nov 2019 11:37:41 +0100
Michal Privoznik <mprivozn@redhat.com> wrote:
> When user tries to hotplug a VFIO device, but the operation fails
> somewhere in the middle (in my testing it failed because of
> RLIMIT_MEMLOCK forbidding more memory allocation), then a double
> free occurs. In vfio_realize() the vdev->migration_blocker is
> allocated, then something goes wrong which causes control to jump
> onto 'error' label where the error is freed. But the pointer is
> left pointing to invalid memory. Later, when
> vfio_instance_finalize() is called, the memory is freed again.
>
> In my testing the second hunk was sufficient to fix the bug, but
> I figured the first hunk doesn't hurt either.
Better safe than sorry, I guess.
>
> ==169952== Invalid read of size 8
> ==169952== at 0xA47DCD: error_free (error.c:266)
> ==169952== by 0x4E0A18: vfio_instance_finalize (pci.c:3040)
> ==169952== by 0x8DF74C: object_deinit (object.c:606)
> ==169952== by 0x8DF7BE: object_finalize (object.c:620)
> ==169952== by 0x8E0757: object_unref (object.c:1074)
> ==169952== by 0x45079C: memory_region_unref (memory.c:1779)
> ==169952== by 0x45376B: do_address_space_destroy (memory.c:2793)
> ==169952== by 0xA5C600: call_rcu_thread (rcu.c:283)
> ==169952== by 0xA427CB: qemu_thread_start (qemu-thread-posix.c:519)
> ==169952== by 0x80A8457: start_thread (in /lib64/libpthread-2.29.so)
> ==169952== by 0x81C96EE: clone (in /lib64/libc-2.29.so)
> ==169952== Address 0x143137e0 is 0 bytes inside a block of size 48 free'd
> ==169952== at 0x4A342BB: free (vg_replace_malloc.c:530)
> ==169952== by 0xA47E05: error_free (error.c:270)
> ==169952== by 0x4E0945: vfio_realize (pci.c:3025)
> ==169952== by 0x76A4FF: pci_qdev_realize (pci.c:2099)
> ==169952== by 0x689B9A: device_set_realized (qdev.c:876)
> ==169952== by 0x8E2C80: property_set_bool (object.c:2080)
> ==169952== by 0x8E0EF6: object_property_set (object.c:1272)
> ==169952== by 0x8E3FC8: object_property_set_qobject (qom-qobject.c:26)
> ==169952== by 0x8E11DB: object_property_set_bool (object.c:1338)
> ==169952== by 0x5E7BDD: qdev_device_add (qdev-monitor.c:673)
> ==169952== by 0x5E81E5: qmp_device_add (qdev-monitor.c:798)
> ==169952== by 0x9E18A8: do_qmp_dispatch (qmp-dispatch.c:132)
> ==169952== Block was alloc'd at
> ==169952== at 0x4A35476: calloc (vg_replace_malloc.c:752)
> ==169952== by 0x51B1158: g_malloc0 (in /usr/lib64/libglib-2.0.so.0.6000.6)
> ==169952== by 0xA47357: error_setv (error.c:61)
> ==169952== by 0xA475D9: error_setg_internal (error.c:97)
> ==169952== by 0x4DF8C2: vfio_realize (pci.c:2737)
> ==169952== by 0x76A4FF: pci_qdev_realize (pci.c:2099)
> ==169952== by 0x689B9A: device_set_realized (qdev.c:876)
> ==169952== by 0x8E2C80: property_set_bool (object.c:2080)
> ==169952== by 0x8E0EF6: object_property_set (object.c:1272)
> ==169952== by 0x8E3FC8: object_property_set_qobject (qom-qobject.c:26)
> ==169952== by 0x8E11DB: object_property_set_bool (object.c:1338)
> ==169952== by 0x5E7BDD: qdev_device_add (qdev-monitor.c:673)
>
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Fixes: f045a0104c8c ("vfio: unplug failover primary device before migration")
> ---
> hw/vfio/pci.c | 2 ++
> 1 file changed, 2 insertions(+)
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
next prev parent reply other threads:[~2019-11-11 10:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-11 10:37 [PATCH 0/2] A pair of memory access problems Michal Privoznik
2019-11-11 10:37 ` [PATCH 1/2] hw/vfio/pci: Fix double free of migration_blocker Michal Privoznik
2019-11-11 10:52 ` Cornelia Huck [this message]
2019-11-11 10:37 ` [PATCH 2/2] vfio-helpers: Free QEMUVFIOState in qemu_vfio_close() Michal Privoznik
2019-11-11 11:15 ` Cornelia Huck
2019-11-12 15:25 ` Michal Privoznik
2019-11-11 14:13 ` [PATCH 0/2] A pair of memory access problems no-reply
2019-11-15 16: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=20191111115230.4cc1bd6b.cohuck@redhat.com \
--to=cohuck@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=mprivozn@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.