edecca
From 14898a26978613278b0a2508c077179144d54b39 Mon Sep 17 00:00:00 2001
edecca
Message-Id: <14898a26978613278b0a2508c077179144d54b39@dist-git>
edecca
From: Jiri Denemark <jdenemar@redhat.com>
edecca
Date: Thu, 2 Aug 2018 16:56:02 +0200
edecca
Subject: [PATCH] qemu_migration: Avoid writing to freed memory
edecca
MIME-Version: 1.0
edecca
Content-Type: text/plain; charset=UTF-8
edecca
Content-Transfer-Encoding: 8bit
edecca
edecca
When a domain is killed on the source host while it is being migrated
edecca
and libvirtd is waiting for the migration to finish (waiting for the
edecca
domain condition in qemuMigrationSrcWaitForCompletion), the run-time
edecca
state including priv->job.current may already be freed once
edecca
virDomainObjWait returns with -1. Thus the priv->job.current pointer
edecca
cached in jobInfo is no longer valid and setting jobInfo->status may
edecca
crash the daemon.
edecca
edecca
https://bugzilla.redhat.com/show_bug.cgi?id=1593137
edecca
edecca
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
edecca
Reviewed-by: Ján Tomko <jtomko@redhat.com>
edecca
(cherry picked from commit dddcb601ebf97ef222a03bb27b2357e831e8a0cc)
edecca
edecca
https://bugzilla.redhat.com/show_bug.cgi?id=1615854
edecca
edecca
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
edecca
Reviewed-by: Erik Skultety <eskultet@redhat.com>
edecca
---
edecca
 src/qemu/qemu_migration.c | 3 ++-
edecca
 1 file changed, 2 insertions(+), 1 deletion(-)
edecca
edecca
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
edecca
index 435cd174af..825a9d399b 100644
edecca
--- a/src/qemu/qemu_migration.c
edecca
+++ b/src/qemu/qemu_migration.c
edecca
@@ -1584,7 +1584,8 @@ qemuMigrationSrcWaitForCompletion(virQEMUDriverPtr driver,
edecca
 
edecca
         if (events) {
edecca
             if (virDomainObjWait(vm) < 0) {
edecca
-                jobInfo->status = QEMU_DOMAIN_JOB_STATUS_FAILED;
edecca
+                if (virDomainObjIsActive(vm))
edecca
+                    jobInfo->status = QEMU_DOMAIN_JOB_STATUS_FAILED;
edecca
                 return -2;
edecca
             }
edecca
         } else {
edecca
-- 
edecca
2.18.0
edecca