Blame SOURCES/libvirt-qemu_conf-Avoid-dereferencing-NULL-in-virQEMUDriverGetHost-NUMACaps-CPU.patch

a41c76
From f06f903d5cb3c14853a7213b6a70c078380b7a62 Mon Sep 17 00:00:00 2001
a41c76
Message-Id: <f06f903d5cb3c14853a7213b6a70c078380b7a62@dist-git>
a41c76
From: Michal Privoznik <mprivozn@redhat.com>
a41c76
Date: Fri, 24 Jan 2020 15:05:50 +0100
a41c76
Subject: [PATCH] qemu_conf: Avoid dereferencing NULL in
a41c76
 virQEMUDriverGetHost{NUMACaps, CPU}
a41c76
a41c76
When fixing [1] I've ran attached reproducer and had it spawn
a41c76
1024 threads and query capabilities XML in each one of them. This
a41c76
lead libvirtd to hit the RLIMIT_NOFILE limit which was kind of
a41c76
expected. What wasn't expected was a subsequent segfault. It
a41c76
happened because virCPUProbeHost failed and returned NULL. We've
a41c76
taken the NULL and passed it to virCapabilitiesHostNUMARef()
a41c76
which dereferenced it. Code inspection showed the same flas in
a41c76
virQEMUDriverGetHostNUMACaps(), so I'm fixing both places.
a41c76
a41c76
1: https://bugzilla.redhat.com/show_bug.cgi?id=1791790
a41c76
a41c76
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
a41c76
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
a41c76
(cherry picked from commit cc361a34c53210d682dbc5f2d506b4a23b71e399)
a41c76
a41c76
https://bugzilla.redhat.com/show_bug.cgi?id=1794691
a41c76
a41c76
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
a41c76
Message-Id: <5de22b27463cd2803b3910d7ef45a0e4bc08ad47.1579874719.git.mprivozn@redhat.com>
a41c76
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
a41c76
---
a41c76
 src/qemu/qemu_conf.c | 18 ++++++++++++++----
a41c76
 1 file changed, 14 insertions(+), 4 deletions(-)
a41c76
a41c76
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
a41c76
index 3d2f0e7bbb..e33ef4895e 100644
a41c76
--- a/src/qemu/qemu_conf.c
a41c76
+++ b/src/qemu/qemu_conf.c
a41c76
@@ -1201,32 +1201,42 @@ virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver,
a41c76
 virCapsHostNUMAPtr
a41c76
 virQEMUDriverGetHostNUMACaps(virQEMUDriverPtr driver)
a41c76
 {
a41c76
+    virCapsHostNUMAPtr hostnuma;
a41c76
+
a41c76
     qemuDriverLock(driver);
a41c76
 
a41c76
     if (!driver->hostnuma)
a41c76
         driver->hostnuma = virCapabilitiesHostNUMANewHost();
a41c76
 
a41c76
+    hostnuma = driver->hostnuma;
a41c76
+
a41c76
     qemuDriverUnlock(driver);
a41c76
 
a41c76
-    virCapabilitiesHostNUMARef(driver->hostnuma);
a41c76
+    if (hostnuma)
a41c76
+        virCapabilitiesHostNUMARef(hostnuma);
a41c76
 
a41c76
-    return driver->hostnuma;
a41c76
+    return hostnuma;
a41c76
 }
a41c76
 
a41c76
 
a41c76
 virCPUDefPtr
a41c76
 virQEMUDriverGetHostCPU(virQEMUDriverPtr driver)
a41c76
 {
a41c76
+    virCPUDefPtr hostcpu;
a41c76
+
a41c76
     qemuDriverLock(driver);
a41c76
 
a41c76
     if (!driver->hostcpu)
a41c76
         driver->hostcpu = virCPUProbeHost(virArchFromHost());
a41c76
 
a41c76
+    hostcpu = driver->hostcpu;
a41c76
+
a41c76
     qemuDriverUnlock(driver);
a41c76
 
a41c76
-    virCPUDefRef(driver->hostcpu);
a41c76
+    if (hostcpu)
a41c76
+        virCPUDefRef(hostcpu);
a41c76
 
a41c76
-    return driver->hostcpu;
a41c76
+    return hostcpu;
a41c76
 }
a41c76
 
a41c76
 
a41c76
-- 
a41c76
2.25.0
a41c76