vfio-helpers: Fix qemu_vfio_open_pci() crash
PATCH 1/1 vfio-helpers: Fix qemu_vfio_open_pci() crash
qemu_vfio_open_common() initializes s->lock only after passing s to qemu_vfio_dma_map() via qemu_vfio_init_ramblock(). qemu_vfio_dma_map() tries to lock the uninitialized lock and crashes.
Fix by initializing s->lock first.
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1645840
---
Compile-tested only, as I lack suitable hardware. Cong Li (cc'ed) is going to test it for real. It looks obvious enough to me to put it into -rc3 without waiting for the test results. We can also wait and put it into -rc4.
util/vfio-helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
util/vfio-helpers.c +1 -1
@@ -411,13 +411,13 @@ static int qemu_vfio_init_ramblock(const char *block_name, void *host_addr,static void qemu_vfio_open_common (QEMUVFIOState *s) { +qemu_mutex_init (&s->lock); s->ram_notifier.ram_block_added = qemu_vfio_ram_block_added; s->ram_notifier.ram_block_removed = qemu_vfio_ram_block_removed;ram_block_notifier_add (&s->ram_notifier); s->low_water_mark =QEMU_VFIO_IOVA_MIN ; s->high_water_mark =QEMU_VFIO_IOVA_MAX ;qemu_ram_foreach_block (qemu_vfio_init_ramblock, s); -qemu_mutex_init (&s->lock); }/**
Signature · 1 line
2.17.2
Quoted 7 lines · On Tue, 27 Nov 2018 09:41:43 +0100 Markus Armbruster <[email protected]> wrote:
qemu_vfio_open_common()initializess->lockonly after passing s toqemu_vfio_dma_map()viaqemu_vfio_init_ramblock().qemu_vfio_dma_map()tries to lock the uninitialized lock and crashes.Fix by initializing
s->lockfirst.
Quoted 8 lines
Fixes 418026ca43bc2626db092d7558258f9594366f28Signed-off-by Markus Armbruster <[email protected]>---
Compile-tested only, as I lack suitable hardware. Cong Li (cc'ed) is going to test it for real. It looks obvious enough to me to put it into -rc3 without waiting for the test results. We can also wait and put it into -rc4.
This looks obvious to me as well.
Quoted 13 lines
util/vfio-helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)util/vfio-helpers.c +1
-0@@ -411,13 +411,13 @@ static int qemu_vfio_init_ramblock(const char *block_name, void *host_addr,static void qemu_vfio_open_common (QEMUVFIOState *s) { +qemu_mutex_init (&s->lock);
util/vfio-helpers.c static int qemu_vfio_init_ramblock(const char *block_name, void *host_addr, · line 423
Quoted 10 lines
util/vfio-helpers.c +0
-1s->ram_notifier.ram_block_added = qemu_vfio_ram_block_added; s->ram_notifier.ram_block_removed = qemu_vfio_ram_block_removed;ram_block_notifier_add (&s->ram_notifier); s->low_water_mark =QEMU_VFIO_IOVA_MIN ; s->high_water_mark =QEMU_VFIO_IOVA_MAX ;qemu_ram_foreach_block (qemu_vfio_init_ramblock, s); -qemu_mutex_init (&s->lock); }/**
Quoted 10 lines · Markus Armbruster
qemu_vfio_open_common()initializess->lockonly after passing s toqemu_vfio_dma_map()viaqemu_vfio_init_ramblock().qemu_vfio_dma_map()tries to lock the uninitialized lock and crashes.Fix by initializing
s->lockfirst.RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1645840
Fixes 418026ca43bc2626db092d7558258f9594366f28Signed-off-by Markus Armbruster <[email protected]>
Quoted 8 lines
---
Compile-tested only, as I lack suitable hardware. Cong Li (cc'ed) is going to test it for real. It looks obvious enough to me to put it into -rc3 without waiting for the test results. We can also wait and put it into -rc4.util/vfio-helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Peter Maydell
AppliedQuoted 11 lines · Markus Armbruster
qemu_vfio_open_common()initializess->lockonly after passing s toqemu_vfio_dma_map()viaqemu_vfio_init_ramblock().qemu_vfio_dma_map()tries to lock the uninitialized lock and crashes.Fix by initializing
s->lockfirst.RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1645840
Fixes 418026ca43bc2626db092d7558258f9594366f28Signed-off-by Markus Armbruster <[email protected]>
Quoted 8 lines
---
Compile-tested only, as I lack suitable hardware. Cong Li (cc'ed) is going to test it for real. It looks obvious enough to me to put it into -rc3 without waiting for the test results. We can also wait and put it into -rc4.util/vfio-helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied, thanks (for rc3).
-- PMM
----- Original Message -----
Quoted 13 lines
From: "Markus Armbruster" <[email protected]>
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Sent: Tuesday, November 27, 2018 4:41:43 PM
Subject: [PATCH for-3.1] vfio-helpers: Fixqemu_vfio_open_pci()crash
qemu_vfio_open_common()initializess->lockonly after passing s toqemu_vfio_dma_map()viaqemu_vfio_init_ramblock().qemu_vfio_dma_map()tries to lock the uninitialized lock and crashes.Fix by initializing
s->lockfirst.
Quoted 8 lines
Fixes 418026ca43bc2626db092d7558258f9594366f28Signed-off-by Markus Armbruster <[email protected]>---
Compile-tested only, as I lack suitable hardware. Cong Li (cc'ed) is going to test it for real. It looks obvious enough to me to put it into -rc3 without waiting for the test results. We can also wait and put it into -rc4.
Smoke test of nvme:// pass with this patch.
Ack.
Quoted 28 lines
util/vfio-helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)util/vfio-helpers.c +1
-1@@ -411,13 +411,13 @@ static int qemu_vfio_init_ramblock(const char *block_name, void *host_addr, static void qemu_vfio_open_common(QEMUVFIOState *s) { +qemu_mutex_init (&s->lock); s->ram_notifier.ram_block_added = qemu_vfio_ram_block_added; s->ram_notifier.ram_block_removed = qemu_vfio_ram_block_removed;ram_block_notifier_add (&s->ram_notifier); s->low_water_mark =QEMU_VFIO_IOVA_MIN ; s->high_water_mark =QEMU_VFIO_IOVA_MAX ;qemu_ram_foreach_block (qemu_vfio_init_ramblock, s); -qemu_mutex_init (&s->lock); }/**
--
2.17.2