Blame SOURCES/libvirt-qemu-driver-Fix-qemuDomainHelperGetVcpus-for-sparse-vcpu-topologies.patch

6ae9ed
From 71279f41cc04f3c350d25f87243e3184d71c88c9 Mon Sep 17 00:00:00 2001
6ae9ed
Message-Id: <71279f41cc04f3c350d25f87243e3184d71c88c9@dist-git>
6ae9ed
From: Peter Krempa <pkrempa@redhat.com>
6ae9ed
Date: Fri, 26 Aug 2016 15:45:24 -0400
6ae9ed
Subject: [PATCH] qemu: driver: Fix qemuDomainHelperGetVcpus for sparse vcpu
6ae9ed
 topologies
6ae9ed
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1097930
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1224341
6ae9ed
6ae9ed
ce43cca0e refactored the helper to prepare it for sparse topologies but
6ae9ed
forgot to fix the iterator used to fill the structures. This would
6ae9ed
result into a weirdly sparse populated array and possible out of bounds
6ae9ed
access and crash once sparse vcpu topologies were allowed.
6ae9ed
6ae9ed
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1369988
6ae9ed
(cherry picked from commit 9b6e947b015026bc7bca9acc4283808459c4efd2)
6ae9ed
---
6ae9ed
 src/qemu/qemu_driver.c | 12 +++++++-----
6ae9ed
 1 file changed, 7 insertions(+), 5 deletions(-)
6ae9ed
6ae9ed
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
6ae9ed
index 1ef8bc4..c8c7aee 100644
6ae9ed
--- a/src/qemu/qemu_driver.c
6ae9ed
+++ b/src/qemu/qemu_driver.c
6ae9ed
@@ -1477,15 +1477,17 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm,
6ae9ed
     for (i = 0; i < virDomainDefGetVcpusMax(vm->def) && ncpuinfo < maxinfo; i++) {
6ae9ed
         virDomainVcpuDefPtr vcpu = virDomainDefGetVcpu(vm->def, i);
6ae9ed
         pid_t vcpupid = qemuDomainGetVcpuPid(vm, i);
6ae9ed
+        virVcpuInfoPtr vcpuinfo = info + ncpuinfo;
6ae9ed
 
6ae9ed
         if (!vcpu->online)
6ae9ed
             continue;
6ae9ed
 
6ae9ed
         if (info) {
6ae9ed
-            info[i].number = i;
6ae9ed
-            info[i].state = VIR_VCPU_RUNNING;
6ae9ed
+            vcpuinfo->number = i;
6ae9ed
+            vcpuinfo->state = VIR_VCPU_RUNNING;
6ae9ed
 
6ae9ed
-            if (qemuGetProcessInfo(&(info[i].cpuTime), &(info[i].cpu), NULL,
6ae9ed
+            if (qemuGetProcessInfo(&vcpuinfo->cpuTime,
6ae9ed
+                                   &vcpuinfo->cpu, NULL,
6ae9ed
                                    vm->pid, vcpupid) < 0) {
6ae9ed
                 virReportSystemError(errno, "%s",
6ae9ed
                                      _("cannot get vCPU placement & pCPU time"));
6ae9ed
@@ -1494,7 +1496,7 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm,
6ae9ed
         }
6ae9ed
 
6ae9ed
         if (cpumaps) {
6ae9ed
-            unsigned char *cpumap = VIR_GET_CPUMAP(cpumaps, maplen, i);
6ae9ed
+            unsigned char *cpumap = VIR_GET_CPUMAP(cpumaps, maplen, ncpuinfo);
6ae9ed
             virBitmapPtr map = NULL;
6ae9ed
 
6ae9ed
             if (!(map = virProcessGetAffinity(vcpupid)))
6ae9ed
@@ -1505,7 +1507,7 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm,
6ae9ed
         }
6ae9ed
 
6ae9ed
         if (cpuwait) {
6ae9ed
-            if (qemuGetSchedInfo(&(cpuwait[i]), vm->pid, vcpupid) < 0)
6ae9ed
+            if (qemuGetSchedInfo(&(cpuwait[ncpuinfo]), vm->pid, vcpupid) < 0)
6ae9ed
                 return -1;
6ae9ed
         }
6ae9ed
 
6ae9ed
-- 
6ae9ed
2.10.0
6ae9ed