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