qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: qemu-devel@nongnu.org
Cc: alex.williamson@redhat.com, avihaih@nvidia.com, clg@redhat.com
Subject: [PULL 02/12] vfio/migration: Fix NULL pointer dereference bug
Date: Thu, 16 Feb 2023 16:02:00 -0700	[thread overview]
Message-ID: <167658852016.932837.13243210499133474787.stgit@omen> (raw)
In-Reply-To: <167658846945.932837.1420176491103357684.stgit@omen>

From: Avihai Horon <avihaih@nvidia.com>

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>
Link: https://lore.kernel.org/r/20230216143630.25610-3-avihaih@nvidia.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
 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 83d2d44080a6..65f3f3bef795 100644
--- a/hw/vfio/migration.c
+++ b/hw/vfio/migration.c
@@ -741,7 +741,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),




  parent reply	other threads:[~2023-02-16 23:02 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-16 23:01 [PULL 00/12] VFIO updates 2023-02-16 Alex Williamson
2023-02-16 23:01 ` [PULL 01/12] linux-headers: Update to v6.2-rc8 Alex Williamson
2023-02-16 23:02 ` Alex Williamson [this message]
2023-02-16 23:02 ` [PULL 03/12] vfio/migration: Allow migration without VFIO IOMMU dirty tracking support Alex Williamson
2023-02-16 23:02 ` [PULL 04/12] vfio/common: Change vfio_devices_all_running_and_saving() logic to equivalent one Alex Williamson
2023-02-16 23:02 ` [PULL 05/12] vfio/migration: Block multiple devices migration Alex Williamson
2023-02-16 23:02 ` [PULL 06/12] vfio/migration: Move migration v1 logic to vfio_migration_init() Alex Williamson
2023-02-16 23:02 ` [PULL 07/12] vfio/migration: Rename functions/structs related to v1 protocol Alex Williamson
2023-02-16 23:02 ` [PULL 08/12] vfio/migration: Implement VFIO migration protocol v2 Alex Williamson
2023-02-16 23:02 ` [PULL 09/12] vfio/migration: Remove VFIO migration protocol v1 Alex Williamson
2023-02-16 23:02 ` [PULL 10/12] vfio: Alphabetize migration section of VFIO trace-events file Alex Williamson
2023-02-16 23:02 ` [PULL 11/12] docs/devel: Align VFIO migration docs to v2 protocol Alex Williamson
2023-02-16 23:02 ` [PULL 12/12] MAINTAINERS: Add myself as VFIO reviewer Alex Williamson
2023-02-21 11:27 ` [PULL 00/12] VFIO updates 2023-02-16 Peter Maydell

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=167658852016.932837.13243210499133474787.stgit@omen \
    --to=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).