提交 9b6e947b 编写于 作者: P Peter Krempa

qemu: driver: Fix qemuDomainHelperGetVcpus for sparse vcpu topologies

ce43cca0 refactored the helper to prepare it for sparse topologies but
forgot to fix the iterator used to fill the structures. This would
result into a weirdly sparse populated array and possible out of bounds
access and crash once sparse vcpu topologies were allowed.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1369988
上级 64f26276
...@@ -1477,15 +1477,17 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm, ...@@ -1477,15 +1477,17 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm,
for (i = 0; i < virDomainDefGetVcpusMax(vm->def) && ncpuinfo < maxinfo; i++) { for (i = 0; i < virDomainDefGetVcpusMax(vm->def) && ncpuinfo < maxinfo; i++) {
virDomainVcpuDefPtr vcpu = virDomainDefGetVcpu(vm->def, i); virDomainVcpuDefPtr vcpu = virDomainDefGetVcpu(vm->def, i);
pid_t vcpupid = qemuDomainGetVcpuPid(vm, i); pid_t vcpupid = qemuDomainGetVcpuPid(vm, i);
virVcpuInfoPtr vcpuinfo = info + ncpuinfo;
if (!vcpu->online) if (!vcpu->online)
continue; continue;
if (info) { if (info) {
info[i].number = i; vcpuinfo->number = i;
info[i].state = VIR_VCPU_RUNNING; vcpuinfo->state = VIR_VCPU_RUNNING;
if (qemuGetProcessInfo(&(info[i].cpuTime), &(info[i].cpu), NULL, if (qemuGetProcessInfo(&vcpuinfo->cpuTime,
&vcpuinfo->cpu, NULL,
vm->pid, vcpupid) < 0) { vm->pid, vcpupid) < 0) {
virReportSystemError(errno, "%s", virReportSystemError(errno, "%s",
_("cannot get vCPU placement & pCPU time")); _("cannot get vCPU placement & pCPU time"));
...@@ -1494,7 +1496,7 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm, ...@@ -1494,7 +1496,7 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm,
} }
if (cpumaps) { if (cpumaps) {
unsigned char *cpumap = VIR_GET_CPUMAP(cpumaps, maplen, i); unsigned char *cpumap = VIR_GET_CPUMAP(cpumaps, maplen, ncpuinfo);
virBitmapPtr map = NULL; virBitmapPtr map = NULL;
if (!(map = virProcessGetAffinity(vcpupid))) if (!(map = virProcessGetAffinity(vcpupid)))
...@@ -1505,7 +1507,7 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm, ...@@ -1505,7 +1507,7 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm,
} }
if (cpuwait) { if (cpuwait) {
if (qemuGetSchedInfo(&(cpuwait[i]), vm->pid, vcpupid) < 0) if (qemuGetSchedInfo(&(cpuwait[ncpuinfo]), vm->pid, vcpupid) < 0)
return -1; return -1;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册