[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 04/14] vfio/migration: Fix NULL pointer dereference bug
From: |
Avihai Horon |
Subject: |
[PATCH v5 04/14] vfio/migration: Fix NULL pointer dereference bug |
Date: |
Thu, 29 Dec 2022 13:03:35 +0200 |
As part of its error flow, vfio_vmstate_change() accesses
MigrationState->to_dst_file without any checks. This can cause a NULL
pointer dereference if the error flow is taken and
MigrationState->to_dst_file is not set.
For example, this can happen if VM is started or stopped not during
migration and vfio_vmstate_change() error flow is taken, as
MigrationState->to_dst_file is not set at that time.
Fix it by checking that MigrationState->to_dst_file is set before using
it.
Fixes: 02a7e71b1e5b ("vfio: Add VM state change handler to know state of VM")
Signed-off-by: Avihai Horon <avihaih@nvidia.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
hw/vfio/migration.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
index e1413ac90c..09fe7c1de2 100644
--- a/hw/vfio/migration.c
+++ b/hw/vfio/migration.c
@@ -743,7 +743,9 @@ static void vfio_vmstate_change(void *opaque, bool running,
RunState state)
*/
error_report("%s: Failed to set device state 0x%x", vbasedev->name,
(migration->device_state & mask) | value);
- qemu_file_set_error(migrate_get_current()->to_dst_file, ret);
+ if (migrate_get_current()->to_dst_file) {
+ qemu_file_set_error(migrate_get_current()->to_dst_file, ret);
+ }
}
vbasedev->migration->vm_running = running;
trace_vfio_vmstate_change(vbasedev->name, running, RunState_str(state),
--
2.26.3
- [PATCH v5 00/14] vfio/migration: Implement VFIO migration protocol v2, Avihai Horon, 2022/12/29
- [PATCH v5 01/14] linux-headers: Update to v6.2-rc1, Avihai Horon, 2022/12/29
- [PATCH v5 02/14] migration: No save_live_pending() method uses the QEMUFile parameter, Avihai Horon, 2022/12/29
- [PATCH v5 03/14] migration: Simplify migration_iteration_run(), Avihai Horon, 2022/12/29
- [PATCH v5 04/14] vfio/migration: Fix NULL pointer dereference bug,
Avihai Horon <=
- [PATCH v5 05/14] vfio/migration: Allow migration without VFIO IOMMU dirty tracking support, Avihai Horon, 2022/12/29
- [PATCH v5 07/14] vfio/common: Change vfio_devices_all_running_and_saving() logic to equivalent one, Avihai Horon, 2022/12/29
- [PATCH v5 06/14] migration/qemu-file: Add qemu_file_get_to_fd(), Avihai Horon, 2022/12/29
- [PATCH v5 08/14] vfio/migration: Move migration v1 logic to vfio_migration_init(), Avihai Horon, 2022/12/29
- [PATCH v5 09/14] vfio/migration: Rename functions/structs related to v1 protocol, Avihai Horon, 2022/12/29
- [PATCH v5 10/14] vfio/migration: Implement VFIO migration protocol v2, Avihai Horon, 2022/12/29
- [PATCH v5 13/14] vfio: Alphabetize migration section of VFIO trace-events file, Avihai Horon, 2022/12/29
- [PATCH v5 12/14] vfio/migration: Remove VFIO migration protocol v1, Avihai Horon, 2022/12/29
- [PATCH v5 14/14] docs/devel: Align VFIO migration docs to v2 protocol, Avihai Horon, 2022/12/29
- [PATCH v5 11/14] vfio/migration: Optimize vfio_save_pending(), Avihai Horon, 2022/12/29