9c6c51
From 6832d9d8dd0963f4865801a29e848ff3256b3282 Mon Sep 17 00:00:00 2001
9c6c51
Message-Id: <6832d9d8dd0963f4865801a29e848ff3256b3282@dist-git>
9c6c51
From: Jiri Denemark <jdenemar@redhat.com>
9c6c51
Date: Fri, 12 Apr 2019 21:21:05 +0200
9c6c51
Subject: [PATCH] qemu: Don't cache microcode version
9c6c51
MIME-Version: 1.0
9c6c51
Content-Type: text/plain; charset=UTF-8
9c6c51
Content-Transfer-Encoding: 8bit
9c6c51
9c6c51
My earlier commit be46f61326 was incomplete. It removed caching of
9c6c51
microcode version in the CPU driver, which means the capabilities XML
9c6c51
will see the correct microcode version. But it is also cached in the
9c6c51
QEMU capabilities cache where it is used to detect whether we need to
9c6c51
reprobe QEMU. By missing the second place, the original commit
9c6c51
be46f61326 made the situation even worse since libvirt would report
9c6c51
correct microcode version while still using the old host CPU model
9c6c51
(visible in domain capabilities XML).
9c6c51
9c6c51
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9c6c51
Reviewed-by: Ján Tomko <jtomko@redhat.com>
9c6c51
(cherry picked from commit 673c62a3b7855a0685d8f116e227c402720b9ee9)
9c6c51
9c6c51
CVE-2018-12126, CVE-2018-12127, CVE-2018-12130, CVE-2019-11091
9c6c51
9c6c51
Conflicts:
9c6c51
	src/qemu/qemu_capabilities.c
9c6c51
            - virQEMUCapsCacheLookupByArch refactoring (commits
9c6c51
              7948ad4129a and 1a3de67001c) are missing
9c6c51
9c6c51
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9c6c51
---
9c6c51
 src/qemu/qemu_capabilities.c | 12 ++++++++----
9c6c51
 src/qemu/qemu_capabilities.h |  3 +--
9c6c51
 src/qemu/qemu_driver.c       |  9 +--------
9c6c51
 tests/testutilsqemu.c        |  2 +-
9c6c51
 4 files changed, 11 insertions(+), 15 deletions(-)
9c6c51
9c6c51
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
9c6c51
index 912f758bcd..0d6fa02560 100644
9c6c51
--- a/src/qemu/qemu_capabilities.c
9c6c51
+++ b/src/qemu/qemu_capabilities.c
9c6c51
@@ -4684,7 +4684,7 @@ virQEMUCapsNewData(const char *binary,
9c6c51
                                            priv->libDir,
9c6c51
                                            priv->runUid,
9c6c51
                                            priv->runGid,
9c6c51
-                                           priv->microcodeVersion,
9c6c51
+                                           virHostCPUGetMicrocodeVersion(),
9c6c51
                                            priv->kernelVersion);
9c6c51
 }
9c6c51
 
9c6c51
@@ -4767,8 +4767,7 @@ virFileCachePtr
9c6c51
 virQEMUCapsCacheNew(const char *libDir,
9c6c51
                     const char *cacheDir,
9c6c51
                     uid_t runUid,
9c6c51
-                    gid_t runGid,
9c6c51
-                    unsigned int microcodeVersion)
9c6c51
+                    gid_t runGid)
9c6c51
 {
9c6c51
     char *capsCacheDir = NULL;
9c6c51
     virFileCachePtr cache = NULL;
9c6c51
@@ -4792,7 +4791,6 @@ virQEMUCapsCacheNew(const char *libDir,
9c6c51
 
9c6c51
     priv->runUid = runUid;
9c6c51
     priv->runGid = runGid;
9c6c51
-    priv->microcodeVersion = microcodeVersion;
9c6c51
 
9c6c51
     if (uname(&uts) == 0 &&
9c6c51
         virAsprintf(&priv->kernelVersion, "%s %s", uts.release, uts.version) < 0)
9c6c51
@@ -4813,8 +4811,11 @@ virQEMUCapsPtr
9c6c51
 virQEMUCapsCacheLookup(virFileCachePtr cache,
9c6c51
                        const char *binary)
9c6c51
 {
9c6c51
+    virQEMUCapsCachePrivPtr priv = virFileCacheGetPriv(cache);
9c6c51
     virQEMUCapsPtr ret = NULL;
9c6c51
 
9c6c51
+    priv->microcodeVersion = virHostCPUGetMicrocodeVersion();
9c6c51
+
9c6c51
     ret = virFileCacheLookup(cache, binary);
9c6c51
 
9c6c51
     VIR_DEBUG("Returning caps %p for %s", ret, binary);
9c6c51
@@ -4860,10 +4861,13 @@ virQEMUCapsPtr
9c6c51
 virQEMUCapsCacheLookupByArch(virFileCachePtr cache,
9c6c51
                              virArch arch)
9c6c51
 {
9c6c51
+    virQEMUCapsCachePrivPtr priv = virFileCacheGetPriv(cache);
9c6c51
     virQEMUCapsPtr ret = NULL;
9c6c51
     virArch target;
9c6c51
     struct virQEMUCapsSearchData data = { .arch = arch };
9c6c51
 
9c6c51
+    priv->microcodeVersion = virHostCPUGetMicrocodeVersion();
9c6c51
+
9c6c51
     ret = virFileCacheLookupByFunc(cache, virQEMUCapsCompareArch, &data);
9c6c51
     if (!ret) {
9c6c51
         /* If the first attempt at finding capabilities has failed, try
9c6c51
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
9c6c51
index 0c06081107..9550df2cd5 100644
9c6c51
--- a/src/qemu/qemu_capabilities.h
9c6c51
+++ b/src/qemu/qemu_capabilities.h
9c6c51
@@ -574,8 +574,7 @@ void virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps,
9c6c51
 virFileCachePtr virQEMUCapsCacheNew(const char *libDir,
9c6c51
                                     const char *cacheDir,
9c6c51
                                     uid_t uid,
9c6c51
-                                    gid_t gid,
9c6c51
-                                    unsigned int microcodeVersion);
9c6c51
+                                    gid_t gid);
9c6c51
 virQEMUCapsPtr virQEMUCapsCacheLookup(virFileCachePtr cache,
9c6c51
                                       const char *binary);
9c6c51
 virQEMUCapsPtr virQEMUCapsCacheLookupCopy(virFileCachePtr cache,
9c6c51
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
9c6c51
index bafef1e3b5..88c08f88ee 100644
9c6c51
--- a/src/qemu/qemu_driver.c
9c6c51
+++ b/src/qemu/qemu_driver.c
9c6c51
@@ -592,8 +592,6 @@ qemuStateInitialize(bool privileged,
9c6c51
     char *hugepagePath = NULL;
9c6c51
     char *memoryBackingPath = NULL;
9c6c51
     size_t i;
9c6c51
-    virCPUDefPtr hostCPU = NULL;
9c6c51
-    unsigned int microcodeVersion = 0;
9c6c51
 
9c6c51
     if (VIR_ALLOC(qemu_driver) < 0)
9c6c51
         return -1;
9c6c51
@@ -813,15 +811,10 @@ qemuStateInitialize(bool privileged,
9c6c51
         run_gid = cfg->group;
9c6c51
     }
9c6c51
 
9c6c51
-    if ((hostCPU = virCPUProbeHost(virArchFromHost())))
9c6c51
-        microcodeVersion = hostCPU->microcodeVersion;
9c6c51
-    virCPUDefFree(hostCPU);
9c6c51
-
9c6c51
     qemu_driver->qemuCapsCache = virQEMUCapsCacheNew(cfg->libDir,
9c6c51
                                                      cfg->cacheDir,
9c6c51
                                                      run_uid,
9c6c51
-                                                     run_gid,
9c6c51
-                                                     microcodeVersion);
9c6c51
+                                                     run_gid);
9c6c51
     if (!qemu_driver->qemuCapsCache)
9c6c51
         goto error;
9c6c51
 
9c6c51
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
9c6c51
index dc7e90b952..3e0b753549 100644
9c6c51
--- a/tests/testutilsqemu.c
9c6c51
+++ b/tests/testutilsqemu.c
9c6c51
@@ -617,7 +617,7 @@ int qemuTestDriverInit(virQEMUDriver *driver)
9c6c51
 
9c6c51
     /* Using /dev/null for libDir and cacheDir automatically produces errors
9c6c51
      * upon attempt to use any of them */
9c6c51
-    driver->qemuCapsCache = virQEMUCapsCacheNew("/dev/null", "/dev/null", 0, 0, 0);
9c6c51
+    driver->qemuCapsCache = virQEMUCapsCacheNew("/dev/null", "/dev/null", 0, 0);
9c6c51
     if (!driver->qemuCapsCache)
9c6c51
         goto error;
9c6c51
 
9c6c51
-- 
9c6c51
2.21.0
9c6c51